-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
199 lines (170 loc) · 8.58 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
#include <windows.h>
#include "text.h"
#include "operation.h"
#include "console.h"
#include "network-addresses.h"
#include "encryption.h"
#include "netconfig.h"
#include "updates.h"
#include "player.h"
#include "quest.h"
#include "battleparamentry.h"
#include "itemraretable.h"
#include "levels.h"
#include "map.h"
#include "license.h"
#include "client.h"
#include "listenthread.h"
#include "lobby.h"
#include "items.h"
#include "server.h"
#include "dns-server.h"
#include "commonservers.h"
#include "patchserver.h"
#include "blockserver.h"
#include "loginserver.h"
#include "lobbyserver.h"
#include "newserv.h"
CFGFile* config;
UPDATE_LIST* updatelist;
QUESTLIST* quests;
LICENSE_LIST* licenses;
LEVEL_TABLE* leveltable;
BATTLE_PARAM battleParamTable[2][3][4][0x60]; // online/offline, episode, diff, monster
in_addr local_addresses[24];
in_addr external_connect;
in_addr local_connect;
int main(int argc,char* argv[])
{
ConsolePrintColor("$0F> Fuzziqer Software NewServ beta 5\n\n");
// load config file (die if it's not found)
ConsolePrintColor("$0E> Loading configuration file: ");
config = CFGLoadFile("system\\config.ini");
if (!config)
{
ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0C> > Configuration file must be present for server to work.\n");
return (-1);
} else ConsolePrintColor("$0Aok\n");
// load update list
ConsolePrintColor("$0E> Loading update list: ");
updatelist = LoadUpdateList("system\\update.ini");
if (!updatelist) ConsolePrintColor("$0Cfailed!\n");
else ConsolePrintColor("$0A%d files\n",updatelist->numFiles);
// load license list (die if it's not found)
ConsolePrintColor("$0E> Loading license list: ");
licenses = LoadLicenseList("system\\licenses.nsi");
if (!licenses)
{
ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0C> > License list must be present for server to work.\n");
return (-1);
} else ConsolePrintColor("$0A%d licenses\n",licenses->numLicenses);
// load monster information (battleparamentry files)
DWORD numFailures = 0;
ConsolePrintColor("$0E> Loading battle parameters: ");
if (!LoadBattleParamEntriesEpisode(&battleParamTable[0][0][0][0],"system\\blueburst\\BattleParamEntry_on.dat")) numFailures++;
if (!LoadBattleParamEntriesEpisode(&battleParamTable[0][1][0][0],"system\\blueburst\\BattleParamEntry_lab_on.dat")) numFailures++;
if (!LoadBattleParamEntriesEpisode(&battleParamTable[0][2][0][0],"system\\blueburst\\BattleParamEntry_ep4_on.dat")) numFailures++;
if (!LoadBattleParamEntriesEpisode(&battleParamTable[1][0][0][0],"system\\blueburst\\BattleParamEntry.dat")) numFailures++;
if (!LoadBattleParamEntriesEpisode(&battleParamTable[1][1][0][0],"system\\blueburst\\BattleParamEntry_lab.dat")) numFailures++;
if (!LoadBattleParamEntriesEpisode(&battleParamTable[1][2][0][0],"system\\blueburst\\BattleParamEntry_ep4.dat")) numFailures++;
if (numFailures) ConsolePrintColor("$0Cfailed!\n");
else ConsolePrintColor("$0Aok\n");
// load non-rare item info
ConsolePrintColor("$0E> Loading non-rare item information: ");
if (SetupNonRareSystem()) ConsolePrintColor("$0Cfailed!\n");
else ConsolePrintColor("$0Aok\n");
// load level info
ConsolePrintColor("$0E> Loading player level information: ");
leveltable = LoadLevelTable("system\\blueburst\\PlyLevelTbl.prs",true);
if (!leveltable) ConsolePrintColor("$0Cfailed!\n");
else ConsolePrintColor("$0Aok\n");
// build quest lists
ConsolePrintColor("$0E> Loading quest list: ");
if (CreateQuestList("system\\quests\\index.ini","system\\quests\\",&quests)) ConsolePrintColor("$0Cfailed!\n");
else ConsolePrintColor("$0A%d quests\n",quests->numQuests);
// start Winsock
ConsolePrintColor("$0E> Starting network subsystem: ");
WSADATA wsadata;
if (WSAStartup(MAKEWORD(2,2),&wsadata))
{
ConsolePrintColor("$0Cfailed!\n");
return (-1);
} else ConsolePrintColor("$0Aok\n");
ConsolePrintColor("\n");
// find our network addresses and set the default local and external connect addresses
long x = WSGetLocalAddressList(local_addresses);
local_connect.s_addr = WSResolveAddress(CFGGetStringSafeA(config,"Local_Address"));
external_connect.s_addr = WSResolveAddress(CFGGetStringSafeA(config,"External_Address"));
if (!WSAddLocalAddress(local_addresses,&local_connect)) ConsolePrintColor("$0C> Error: could not add local address to address list\n");
if (!WSAddLocalAddress(local_addresses,&external_connect)) ConsolePrintColor("$0C> Error: could not add external address to address list\n");
ConsolePrintColor("$0E> IP addresses found:\n>");
for (x = 0; local_addresses[x].s_addr; x++)
{
if (local_addresses[x].s_addr == external_connect.s_addr) ConsolePrintColor("$0F %s",inet_ntoa(local_addresses[x]));
else if (local_addresses[x].s_addr == local_connect.s_addr) ConsolePrintColor("$0B %s",inet_ntoa(local_addresses[x]));
else ConsolePrintColor("$0E %s",inet_ntoa(local_addresses[x]));
}
ConsolePrintColor("\n\n");
// start all our servers!
SERVER *blockserver = NULL;
SERVER *loginserver = NULL;
SERVER *lobbyserver = NULL;
SERVER *patchserver = NULL;
ConsolePrintColor("$0E> Starting DNS server: ");
if (DNSStartServer()) ConsolePrintColor("$0Aok\n");
else ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0E> Starting patch server: ");
patchserver = StartServer("Patch Server",(LPTHREAD_START_ROUTINE)HandlePatchClient,(LISTEN_THREAD_CALLBACK)HandleConnection,CFGGetNumber(config,"Patch_Server_Port_PC"),CFGGetNumber(config,"Patch_Server_Port_BB"),0);
if (patchserver) ConsolePrintColor("$0Aok\n");
else ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0E> Starting block server: ");
blockserver = StartServer("Block Server",(LPTHREAD_START_ROUTINE)HandleBlockClient,(LISTEN_THREAD_CALLBACK)HandleConnection,CFGGetNumber(config,"Block_Server_Port_BB"),CFGGetNumber(config,"Block_Server_Port_1_BB"),CFGGetNumber(config,"Block_Server_Port_2_BB"),0);
if (blockserver) ConsolePrintColor("$0Aok\n");
else ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0E> Starting login server: ");
loginserver = StartServer("Login Server",(LPTHREAD_START_ROUTINE)HandleLoginClient,(LISTEN_THREAD_CALLBACK)HandleConnection,CFGGetNumber(config,"Japanese_1.0_Port_GC"),CFGGetNumber(config,"Japanese_1.1_Port_GC"),CFGGetNumber(config,"Japanese_Ep3_Port_GC"),CFGGetNumber(config,"American_1.0/1.1_Port_GC"),CFGGetNumber(config,"American_Ep3_Port_GC"),CFGGetNumber(config,"European_1.0_Port_GC"),CFGGetNumber(config,"European_1.1_Port_GC"),CFGGetNumber(config,"European_Ep3_Port_GC"),CFGGetNumber(config,"Login_Server_Port_PC"),CFGGetNumber(config,"Login_Server_Port_BB"),0);
if (loginserver)
{
if (SetupLoginServer(loginserver))
{
StopServer(loginserver);
ConsolePrintColor("$0Cfailed!\n");
} else ConsolePrintColor("$0Aok\n");
} else ConsolePrintColor("$0Cfailed!\n");
ConsolePrintColor("$0E> Starting lobby server: ");
lobbyserver = StartServer("Lobby Server",(LPTHREAD_START_ROUTINE)HandleLobbyClient,(LISTEN_THREAD_CALLBACK)HandleConnection,CFGGetNumber(config,"Lobby_Server_Port_PC"),CFGGetNumber(config,"Lobby_Server_Port_GC"),CFGGetNumber(config,"Lobby_Server_Port_BB"),0);
if (lobbyserver)
{
if (SetupLobbyServer(lobbyserver))
{
StopServer(lobbyserver);
ConsolePrintColor("$0Cfailed!\n");
} else ConsolePrintColor("$0Aok\n");
} else ConsolePrintColor("$0Cfailed!\n");
// and now, we wait. there should be some kind of termination condition here
// (like user presses CTRL+SHIFT+ESCAPE or something). I haven't put this
// in because I always just close it by clicking the close box on the console.
ConsolePrintColor("\n");
WaitForSingleObject(GetCurrentThread(),INFINITE);
// stop servers and free everything
ConsolePrintColor("$0E> Stopping lobby server\n");
StopServer(lobbyserver);
ConsolePrintColor("$0E> Stopping login server\n");
StopServer(loginserver);
ConsolePrintColor("$0E> Stopping block server\n");
StopServer(blockserver);
ConsolePrintColor("$0E> Stopping patch server\n");
StopServer(patchserver);
ConsolePrintColor("$0E> Stopping DNS server\n");
DNSStopServer();
ConsolePrintColor("$0E> Releasing data from memory\n");
DestroyLicenseList(licenses);
DestroyQuestList(quests);
DestroyUpdateList(updatelist);
CFGCloseFile(config);
ConsolePrintColor("$0E> Stopping network system\n");
WSACleanup();
return 0;
}