-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·53 lines (45 loc) · 1.27 KB
/
main.cpp
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
#include "base/command_line.h"
#include "base/logger.h"
#include "server_core/server.h"
void PrintUsage() {
printf("-serverIp=<IP> -- IP that server will be listening on.\n");
printf("-pluginsFolder=<path> -- (optional) where server should look for plugins.\n");
printf("-logToFile -- (optional) log all output to a file.\n");
}
int main(int argc, const char** argv) {
if (argc <= 1) {
PrintUsage();
return 1;
}
if (!CommandLine::Init(argc, argv)) {
perror("Command line was not initialized.");
return 1;
}
CommandLine& cl = *CommandLine::ForCurrentProcess();
if (!Logger::InitLog(cl.HasSwitch("logToFile"))) {
perror("Log file wasn't opened");
return 1;
}
Path::StringType pluginsPath = PATH_LITERAL(".");
if (cl.HasSwitch("pluginsFolder")) {
pluginsPath = cl.SwitchValue("pluginsFolder");
}
if (!cl.HasSwitch("serverIp")) {
Log(ERR) << "Please specify server IP\n";
return 1;
}
int sockInit = Socket::InitSockets();
if (sockInit == 0) {
Server server;
if (server.LoadPlugins(pluginsPath)) {
server.Run();
} else {
Log(ERR) << "No plugins were loaded, exiting.";
}
} else {
Log(ERR) << "Sockets were not initialized.";
}
Socket::UninitSockets();
Logger::UninitLog();
return 0;
}