-
Notifications
You must be signed in to change notification settings - Fork 2
/
framework.cpp
114 lines (89 loc) · 3.7 KB
/
framework.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "framework.h"
Framework::Framework() : m_Running(true), m_Options(), m_LoginServer(), m_Clock()
{
}
int Framework::Run(int argc, char **argv)
{
printf(">> GW2SEX - Guild Wars 2 Server Emulator for XNIX\n");
printf(">> Some ideas taken from http://poke152.blogspot.com.au/2012_12_01_archive.html\n");
printf(">> Developed by Nomelx\n\n");
System::IgnoreSigPipe(); // For debugging with GDB
System::CheckRoot(); // Servers should have a unique user to run the application
if (!Configure(argc, argv)) {
printf("!) Server attempting to start with incorrect configuration.\n");
return 1;
}
if (strcmp(m_Options.m_ServerMode, "gateway") == 0) {
return RunGateway();
}
return 0;
}
int Framework::RunGateway()
{
int gatewayPort = GetSettingInteger("networking.login_server.port");
const char* gatewayCertificate = GetSettingString("networking.login_server.certFile");
const char* gatewayPrivateKey = GetSettingString("networking.login_server.keyFile");
printf("Starting %s\n", m_Options.m_ServerName);
printf("Starting login gateway server on port %d\n", gatewayPort);
// Establish a connection to mysql db
if (!Database::Get().Initalize(
GetSettingString("networking.database.db_name"),
GetSettingString("networking.database.db_address"),
GetSettingString("networking.database.db_username"),
GetSettingString("networking.database.db_password"),
GetSettingInteger("networking.database.db_port")
)) {
printf("!) Unable to connect to database server (listner).\n");
return -1;
} else {
printf("Connected to database %s on %s\n", GetSettingString("networking.database.db_name"), GetSettingString("networking.database.db_address"));
}
// This will spawn off the login / server socket thread
if (!m_LoginServer.Startup(gatewayPort,
gatewayCertificate,
gatewayPrivateKey,
m_Options.m_MITMMode)) {
m_LoginServer.Shutdown();
printf("!) Unable to create login server (listner).\n");
return 1;
}
// Populates the blacklist file
if (!GW2BlackList::Initalize(GetSettingString("networking.login_server.blacklist"))) {
m_LoginServer.Shutdown();
printf("!) Unable to read ban list (listner).\n");
return 1;
}
// Start the server clock for regulation, this does not regulate the listning socket.
// We would idealy use this to make sure we are not spending too much time doing expensive operations.
m_Clock.Start();
// Main thread loop, do any non blocking functions here.
while (m_Running) {
// Poll the users, this is where all player managment is done.
m_LoginServer.Update();
// Update the clock.
m_Clock.Frame();
}
m_LoginServer.Shutdown();
return 0;
}
bool Framework::Configure(int argc, char **argv)
{
// Check argc agains the required argument count, we subtract one because the OS includes the running path.
if ((argc-1)!=REQ_ARGUMENTS_C) {
ShowUsage();
return false;
}
// Assume arg 1 is the config file.
if (!Import(argv[1])) {
return false;
}
// Load any missions critical options here.
sprintf(m_Options.m_ServerName, "%s", GetSettingString("networking.server.name"));
sprintf(m_Options.m_ServerMode, "%s", GetSettingString("networking.server.mode"));
m_Options.m_MITMMode = GetSettingBool("networking.server.mitmMode");
return true;
}
void Framework::ShowUsage() {
printf("Usage: gw2sex config-file[.cofg]\n");
printf("\n");
}