-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathserverconsole.h
More file actions
60 lines (50 loc) · 1.09 KB
/
Copy pathserverconsole.h
File metadata and controls
60 lines (50 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <thread>
#include <string>
using namespace std;
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
typedef void* HANDLE;
enum PrefixType {
NoPrefix = 0,
Info = 1,
Warn = 2,
Error = 3,
Fatal = 4,
Debug = 5
};
constexpr auto INFO_PREFIX = "[ Info ]";
constexpr auto WARN_PREFIX = "[ Warn ]";
constexpr auto ERROR_PREFIX = "[ Error ]";
constexpr auto FATAL_PREFIX = "[ Fatal ]";
constexpr auto DEBUG_PREFIX = "[ Debug ]";
class ServerConsole {
public:
ServerConsole();
~ServerConsole();
bool Init();
void Start();
void Stop();
void Log(PrefixType prefixType, const string& text);
void Print(PrefixType prefixType, const string& text, bool logToFile = true);
void StartRead();
unsigned long long GetCurrentTime() const noexcept {
return _currentTime;
}
private:
int run();
int shutdown();
void onSecondTick();
void onMinuteTick();
void log(const string& text);
private:
thread _serverConsoleThread;
bool _running;
time_t _currentTime;
string _currentTimeStr;
char _secondCount;
HANDLE _consoleOutput;
string _logFile;
};
extern ServerConsole serverConsole;