-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.cpp
271 lines (244 loc) · 10.4 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2017 MaNGOS project <https://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/// \addtogroup mangosd Mangos Daemon
/// @{
/// \file
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "Config/Config.h"
#include "ProgressBar.h"
#include "Log.h"
#include "Master.h"
#include "SystemConfig.h"
#include "AuctionHouseBot.h"
#include "revision.h"
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <ace/Version.h>
#include <ace/Get_Opt.h>
#ifdef WIN32
#include "ServiceWin32.h"
char serviceName[] = "mangosd";
char serviceLongName[] = "MaNGOS world service";
char serviceDescription[] = "Massive Network Game Object Server";
#if defined(CLASSIC)
const char RAW_VMAP_MAGIC[] = "VMAPz06"; /**< used in extracted vmap files with raw data */
#elseif defined(TBC)
const char RAW_VMAP_MAGIC[] = "VMAPs06"; /**< used in extracted vmap files with raw data */
#elseif defined(WOTLK)
const char RAW_VMAP_MAGIC[] = "VMAPt06"; /**< used in extracted vmap files with raw data */
#elseif defined(CATA)
const char RAW_VMAP_MAGIC[] = "VMAPc06"; /**< used in extracted vmap files with raw data */
#endif
/*
* -1 - not in service mode
* 0 - stopped
* 1 - running
* 2 - paused
*/
int m_ServiceStatus = -1;
#else
#include "PosixDaemon.h"
#endif
DatabaseType WorldDatabase; ///< Accessor to the world database
DatabaseType CharacterDatabase; ///< Accessor to the character database
DatabaseType LoginDatabase; ///< Accessor to the realm/login database
uint32 realmID; ///< Id of the realm
/// Print out the usage string for this program on the console.
void usage(const char* prog)
{
sLog.outString("Usage: \n %s [<options>]\n"
" -v, --version print version and exist\n\r"
" -c config_file use config_file as configuration file\n\r"
" -a, --ahbot config_file use config_file as ahbot configuration file\n\r"
#ifdef WIN32
" Running as service functions:\n\r"
" -s run run as service\n\r"
" -s install install service\n\r"
" -s uninstall uninstall service\n\r"
#else
" Running as daemon functions:\n\r"
" -s run run as daemon\n\r"
" -s stop stop daemon\n\r"
#endif
, prog);
}
/// Launch the mangos server
extern int main(int argc, char** argv)
{
///- Command line parsing
char const* cfg_file = MANGOSD_CONFIG_LOCATION;
char const* options = ":a:c:s:";
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v', ACE_Get_Opt::NO_ARG);
cmd_opts.long_option("ahbot", 'a', ACE_Get_Opt::ARG_REQUIRED);
char serviceDaemonMode = '\0';
int option;
while ((option = cmd_opts()) != EOF)
{
switch (option)
{
case 'a':
sAuctionBotConfig.SetConfigFileName(cmd_opts.opt_arg());
break;
case 'c':
cfg_file = cmd_opts.opt_arg();
break;
case 'v':
printf("%s\n", REVISION_NR);
return 0;
case 's':
{
const char* mode = cmd_opts.opt_arg();
if (!strcmp(mode, "run"))
{ serviceDaemonMode = 'r'; }
#ifdef WIN32
else if (!strcmp(mode, "install"))
{ serviceDaemonMode = 'i'; }
else if (!strcmp(mode, "uninstall"))
{ serviceDaemonMode = 'u'; }
#else
else if (!strcmp(mode, "stop"))
{ serviceDaemonMode = 's'; }
#endif
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
break;
}
case ':':
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
default:
sLog.outError("Runtime-Error: bad format of commandline arguments");
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
}
#ifdef WIN32 // windows service command need execute before config read
switch (serviceDaemonMode)
{
case 'i':
if (WinServiceInstall())
{ sLog.outString("Installing service"); }
return 1;
case 'u':
if (WinServiceUninstall())
{ sLog.outString("Uninstalling service"); }
return 1;
case 'r':
WinServiceRun();
break;
}
#endif
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#ifndef WIN32 // posix daemon commands need apply after config read
switch (serviceDaemonMode)
{
case 'r':
startDaemon();
break;
case 's':
stopDaemon();
break;
}
#endif
sLog.outString("%s [world-daemon]", REVISION_NR);
sLog.outString("<Ctrl-C> to stop.\n"
#if defined(CLASSIC)
" __ __ _ _ ___ ___ ___ \n"
" | \\/ |__ _| \\| |/ __|/ _ \\/ __| We Love \n"
" | |\\/| / _` | .` | (_ | (_) \\__ \\ Vanilla Wow \n"
" |_| |_\\__,_|_|\\_|\\___|\\___/|___/ \n"
" ____ \n"
" For help and support please visit: /_ /___ _ _ ___ \n"
" Website: https://getmangos.eu / // -_) '_/ _ \\ \n"
" Forum / Wiki: https://getmangos.eu /___\\___|_| \\___/\n"
);
#elseif defined(TBC)
" __ __ _ _ ___ ___ ___ \n"
" | \\/ |__ _| \\| |/ __|/ _ \\/ __| We Love the \n"
" | |\\/| / _` | .` | (_ | (_) \\__ \\ Burning Crusade \n"
" |_| |_\\__,_|_|\\_|\\___|\\___/|___/ \n"
" ___ \n"
" For help and support please visit: / _ \\ _ _ ___ \n"
" Website: https://getmangos.eu | (_) | ' \\/ -_) \n"
" Forum / Wiki: https://getmangos.eu \\___/|_||_\\___|\n"
);
#elseif defined(WOTLK)
" __ __ _ _ ___ ___ ___ \n"
" | \\/ |__ _| \\| |/ __|/ _ \\/ __| Wrath of the \n"
" | |\\/| / _` | .` | (_ | (_) \\__ \\ Lich King \n"
" |_| |_\\__,_|_|\\_|\\___|\\___/|___/ \n"
" _____ \n"
" For help and support please visit: |_ _|_ __ _____\n"
" Website: https://getmangos.eu | | \\ V V / _ \\\n"
" Forum / Wiki: https://getmangos.eu |_| \\_/\\_/\\___/ \n"
);
#elseif defined(CATA)
" __ __ _ _ ___ ___ ___ \n"
" | \\/ |__ _| \\| |/ __|/ _ \\/ __| \n"
" | |\\/| / _` | .` | (_ | (_) \\__ \\ \n"
" |_| |_\\__,_|_|\\_|\\___|\\___/|___/ \n"
" _____ _ \n"
" For help and support please visit: |_ _| |_ _ _ ___ ___ \n"
" Website: https://getmangos.eu | | | ' \\| '_/ -_) -_) \n"
" Forum / Wiki: https://getmangos.eu |_| |_||_|_| \\___\\___| \n"
);
#endif
sLog.outString("Using configuration file %s.", cfg_file);
DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
if (SSLeay() < 0x009080bfL)
{
DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!");
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]");
}
DETAIL_LOG("Using ACE: %s", ACE_VERSION);
///- Set progress bars show mode
BarGoLink::SetOutputState(sConfig.GetBoolDefault("ShowProgressBars", true));
///- and run the 'Master'
/// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
int code = sMaster.Run();
#ifdef WIN32
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
return code;
// at sMaster return function exist with codes
// 0 - normal shutdown
// 1 - shutdown at error
// 2 - restart command used, this code can be used by restarter for restart mangosd
}
/// @}