Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Main.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
9#pragma comment (lib, "Crypt32")
10#include <openssl/crypto.h>
11#include <openssl/opensslv.h>
12
13#include "Common.h"
16
17#include "Log.h"
18#include "Master.h"
19#include "OpenSSLProviders.h"
20#include "World.h"
21
22#ifndef _SKYFIRE_CORE_CONFIG
23# define _SKYFIRE_CORE_CONFIG "worldserver.conf"
24#endif
25
26#ifdef _WIN32
27#include "ServiceWin32.h"
28char serviceName[] = "worldserver";
29char serviceLongName[] = "SkyFire world service";
30char serviceDescription[] = "SkyFire World of Warcraft emulator world service";
31/*
32 * -1 - not in service mode
33 * 0 - stopped
34 * 1 - running
35 * 2 - paused
36 */
37int m_ServiceStatus = -1;
38#endif
39
43
44#ifndef _SKYFIRE_WORLD_DATABASE_HOST
45# define _SKYFIRE_WORLD_DATABASE_HOST ""
46#endif
47
48#ifndef _SKYFIRE_WORLD_DATABASE_PORT
49# define _SKYFIRE_WORLD_DATABASE_PORT ""
50#endif
51
52#ifndef _SKYFIRE_WORLD_DATABASE_USER
53# define _SKYFIRE_WORLD_DATABASE_USER ""
54#endif
55
56#ifndef _SKYFIRE_WORLD_DATABASE_PASS
57# define _SKYFIRE_WORLD_DATABASE_PASS ""
58#endif
59
60#ifndef _SKYFIRE_DATABASE_AUTH
61# define _SKYFIRE_DATABASE_AUTH ""
62#endif
63
64#ifndef _SKYFIRE_DATABASE_CHARACTERS
65# define _SKYFIRE_DATABASE_CHARACTERS ""
66#endif
67
68#ifndef _SKYFIRE_DATABASE_WORLD
69# define _SKYFIRE_DATABASE_WORLD ""
70#endif
71
74
76void usage(const char* prog)
77{
78 printf("Usage:\n");
79 printf(" %s [<options>]\n", prog);
80 printf(" -c config_file use config_file as configuration file\n");
81 printf(" --no_use_config_database_info dont use database login info from config file\n");
82 printf(" --db_host sets the database host, requires: --no_use_config_database_info\n");
83 printf(" --db_port sets the database port, requires: --no_use_config_database_info\n");
84 printf(" --db_user sets the database user, requires: --no_use_config_database_info\n");
85 printf(" --db_password sets the database password, requires: --no_use_config_database_info\n");
86 printf(" --db_auth sets the auth database, requires: --no_use_config_database_info\n");
87 printf(" --db_chars sets the characters database, requires: --no_use_config_database_info\n");
88 printf(" --db_world sets the world database, requires: --no_use_config_database_info\n");
89#ifdef _WIN32
90 printf(" Running as service functions:\n");
91 printf(" --service run as service\n");
92 printf(" -s install install service\n");
93 printf(" -s uninstall uninstall service\n");
94#endif
95}
96
98extern int main(int argc, char** argv)
99{
100
101 bool noUseConfigDatabaseInfo = 0;
102 const char* db_Host = _SKYFIRE_WORLD_DATABASE_HOST;
103 const char* db_Port = _SKYFIRE_WORLD_DATABASE_PORT;
104 const char* db_User = _SKYFIRE_WORLD_DATABASE_USER;
105 const char* db_Password = _SKYFIRE_WORLD_DATABASE_PASS;
106 const char* authDB = _SKYFIRE_DATABASE_AUTH;
107 const char* charactersDB = _SKYFIRE_DATABASE_CHARACTERS;
108 const char* worldDB = _SKYFIRE_DATABASE_WORLD;
109
111 char const* cfg_file = _SKYFIRE_CORE_CONFIG;
112 int c = 1;
113 while (c < argc)
114 {
115 if (strcmp(argv[c], "--help") == 0)
116 {
117 usage(argv[0]);
118 return 1;
119 }
120
121 if (strcmp(argv[c], "--no_use_config_database_info") == 0)
122 {
123 noUseConfigDatabaseInfo = argv[c];
124 }
125
126 if (noUseConfigDatabaseInfo == 1)
127 {
128 if (strcmp(argv[c], "--db_host") == 0)
129 {
130 if (++c >= argc)
131 {
132 printf("Runtime-Error: --db_host option requires an input argument\n");
133 usage(argv[0]);
134 return 1;
135 }
136 else
137 {
138
139 db_Host = argv[c];
140 }
141 }
142
143 if (strcmp(argv[c], "--db_port") == 0)
144 {
145 if (++c >= argc)
146 {
147 printf("Runtime-Error: --db_port option requires an input argument\n");
148 usage(argv[0]);
149 return 1;
150 }
151 else
152 db_Port = argv[c];
153 }
154
155 if (strcmp(argv[c], "--db_user") == 0)
156 {
157 if (++c >= argc)
158 {
159 printf("Runtime-Error: --db_user option requires an input argument\n");
160 usage(argv[0]);
161 return 1;
162 }
163 else
164 db_User = argv[c];
165 }
166
167 if (strcmp(argv[c], "--db_password") == 0)
168 {
169 if (++c >= argc)
170 {
171 printf("Runtime-Error: --db_password option requires an input argument\n");
172 usage(argv[0]);
173 return 1;
174 }
175 else
176 db_Password = argv[c];
177 }
178
179 if (strcmp(argv[c], "--db_auth") == 0)
180 {
181 if (++c >= argc)
182 {
183 printf("Runtime-Error: --db_auth option requires an input argument\n");
184 usage(argv[0]);
185 return 1;
186 }
187 else
188 authDB = argv[c];
189 }
190
191 if (strcmp(argv[c], "--db_chars") == 0)
192 {
193 if (++c >= argc)
194 {
195 printf("Runtime-Error: --db_chars option requires an input argument\n");
196 usage(argv[0]);
197 return 1;
198 }
199 else
200 charactersDB = argv[c];
201 }
202
203 if (strcmp(argv[c], "--db_world") == 0)
204 {
205 if (++c >= argc)
206 {
207 printf("Runtime-Error: --db_world option requires an input argument\n");
208 usage(argv[0]);
209 return 1;
210 }
211 else
212 worldDB = argv[c];
213 }
214 }
215
216 if (!strcmp(argv[c], "-c"))
217 {
218 if (++c >= argc)
219 {
220 printf("Runtime-Error: -c option requires an input argument");
221 usage(argv[0]);
222 return 1;
223 }
224 else
225 cfg_file = argv[c];
226 }
227
228#ifdef _WIN32
229 if (strcmp(argv[c], "-s") == 0) // Services
230 {
231 if (++c >= argc)
232 {
233 printf("Runtime-Error: -s option requires an input argument");
234 usage(argv[0]);
235 return 1;
236 }
237
238 if (strcmp(argv[c], "install") == 0)
239 {
240 if (WinServiceInstall())
241 printf("Installing service\n");
242 return 1;
243 }
244 else if (strcmp(argv[c], "uninstall") == 0)
245 {
246 if (WinServiceUninstall())
247 printf("Uninstalling service\n");
248 return 1;
249 }
250 else
251 {
252 printf("Runtime-Error: unsupported option %s", argv[c]);
253 usage(argv[0]);
254 return 1;
255 }
256 }
257
258 if (strcmp(argv[c], "--service") == 0)
259 WinServiceRun();
260#endif
261 ++c;
262 }
263
264 if (!sConfigMgr->LoadInitial(cfg_file))
265 {
266 printf("Invalid or missing configuration file : %s\n", cfg_file);
267 printf("Verify that the file exists and has \'[worldserver]' written in the top of the file!\n");
268 return 1;
269 }
270
271 SF_LOG_INFO("server.worldserver", "Using configuration file %s.", cfg_file);
272
273 SF_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
274
275 if (!Skyfire::LoadOpenSSLProviders("server.worldserver"))
276 return 1;
277
278 if (noUseConfigDatabaseInfo == true)
279 {
280 sMaster->SetNoUseConfigDatabaseInfo(noUseConfigDatabaseInfo);
281 sMaster->SetDatabaseHost(db_Host);
282 sMaster->SetDatabasePort(db_Port);
283 sMaster->SetDatabaseUser(db_User);
284 sMaster->SetDatabasePassword(db_Password);
285 sMaster->SetDatabaseAuth(authDB);
286 sMaster->SetDatabaseChars(charactersDB);
287 sMaster->SetDatabaseWorld(worldDB);
288 }
289
292 int ret = sMaster->Run();
293
294 // at sMaster return function exist with codes
295 // 0 - normal shutdown
296 // 1 - shutdown at error
297 // 2 - restart command used, this code can be used by restarter for restart Skyfired
298
299 return ret;
300}
301
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabaseWorkerPool
#define sConfigMgr
Definition Config.h:64
std::uint32_t uint32
Definition Define.h:77
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabaseWorkerPool
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabaseWorkerPool
#define _SKYFIRE_WORLD_DATABASE_PASS
Definition Main.cpp:57
#define _SKYFIRE_DATABASE_CHARACTERS
Definition Main.cpp:65
#define _SKYFIRE_DATABASE_AUTH
Definition Main.cpp:61
#define _SKYFIRE_DATABASE_WORLD
Definition Main.cpp:69
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
#define _SKYFIRE_WORLD_DATABASE_USER
Definition Main.cpp:53
#define _SKYFIRE_CORE_CONFIG
Definition Main.cpp:23
#define sMaster
Definition Master.h:47
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
#define _SKYFIRE_WORLD_DATABASE_PORT
Definition Main.cpp:49
#define _SKYFIRE_WORLD_DATABASE_HOST
Definition Main.cpp:45
RealmNameMap realmNameStore
Definition Main.cpp:72
std::map< uint32, std::string > RealmNameMap
Definition World.h:905
uint32 realmID
Id of the realm.
Definition Main.cpp:73
bool LoadOpenSSLProviders(char const *logFilter)
void usage(const char *prog)
Print out the usage string for this program on the console.
Definition Main.cpp:192
int main(int argc, char **argv)
Launch the auth server.
Definition Main.cpp:207
LoginDatabaseWorkerPool LoginDatabase
Definition Main.cpp:54