-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlobbyserver.cpp
More file actions
162 lines (142 loc) · 5.58 KB
/
Copy pathlobbyserver.cpp
File metadata and controls
162 lines (142 loc) · 5.58 KB
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
#include <windows.h>
#include <stdio.h>
#include "text.h"
#include "operation.h"
#include "console.h"
#include "netconfig.h"
#include "quest.h"
#include "encryption.h"
#include "license.h"
#include "version.h"
#include "battleparamentry.h"
#include "itemraretable.h"
#include "player.h"
#include "map.h"
#include "client.h"
#include "listenthread.h"
#include "lobby.h"
#include "server.h"
#include "commonservers.h"
#include "loginserver.h"
#include "command-functions.h"
extern CFGFile* config;
// creates the lobbies used by players on the lobby server
int SetupLobbyServer(SERVER* s)
{
int x,y;
LOBBY* l;
for (x = 0; x < 20; x++)
{
l = (LOBBY*)malloc(sizeof(LOBBY));
if (!l) break;
memset(l,0,sizeof(LOBBY));
l->block = x + 1;
l->maxlevel = 0xFFFFFFFF;
swprintf(l->name,L"LOBBY%d",x + 1);
l->flags = LOBBY_FLAG_HACKPROTECT | LOBBY_FLAG_PUBLIC | LOBBY_FLAG_DEFAULT | ((x > 14) ? LOBBY_FLAG_EP3 : 0);
l->maxClients = 12;
l->type = x;
if (!AddLobby(s,l))
{
free(l);
break;
}
}
if (x < 20)
{
for (y = 0; y < x; y++) free(s->lobbies[x]);
free(s->lobbies);
return 1;
}
return 0;
}
// thie function is called when a player connects to the lobby server
DWORD HandleLobbyClient(NEW_CLIENT_THREAD_DATA* nctd)
{
SERVER* s = nctd->s;
CLIENT* c = nctd->c;
nctd->release = true;
nctd = NULL;
srand(GetTickCount());
char filename[MAX_PATH],filename2[MAX_PATH],bankname[MAX_PATH];
int result;
// add the client to the server
ConsolePrintColor("$0E> Lobby server: new client\n");
AddClient(s,c);
// send an init command and get username/password
CommandServerInit(c,true);
ProcessCommands(s,c,0x9D,0x9E,0x0093,0);
int errors = 0;
if (c->version == VERSION_BLUEBURST)
{
// if the client is BB, then get its player and account data and send it to them
//errors = GetPlayerInfoFromShipgate(...);
//if (errors)
//{
sprintf(filename,"system\\players\\account_%s.nsa",c->license.username);
sprintf(filename2,"system\\players\\%s.act",c->license.username);
result = PlayerLoadAccountData(&c->playerInfo,filename);
if (!result) result = PlayerLoadAccountDataOldFormat(&c->playerInfo,filename2);
if (!result) result = PlayerLoadAccountData(&c->playerInfo,"system\\blueburst\\default.nsa");
if (!result) result = PlayerLoadAccountDataOldFormat(&c->playerInfo,"system\\blueburst\\default.act");
if (!result)
{
CommandMessageBox(c,L"$C6Your account data could not be found.");
errors = 4534632;
} else {
sprintf(c->playerInfo.bankname,"player%d",c->cfg.bbplayernum + 1);
sprintf(filename,"system\\players\\player_%s_%d.nsc",c->license.username,c->cfg.bbplayernum + 1);
sprintf(filename2,"system\\players\\%s-player-%d.pbb",c->license.username,c->cfg.bbplayernum);
sprintf(bankname,"system\\players\\bank_%s_%s.nsb",c->license.username,c->playerInfo.bankname);
errors = !PlayerLoadPlayerData(&c->playerInfo,filename);
if (errors) errors = !PlayerLoadPlayerDataOldFormat(&c->playerInfo,filename2);
if (errors) CommandMessageBox(c,L"$C6Your player data could not be found.");
else {
errors = !PlayerLoadBankData(&c->playerInfo.bank,bankname);
if (errors) errors = !PlayerLoadBankData(&c->playerInfo.bank,"system\\blueburst\\default.nsb");
if (errors) CommandMessageBox(c,L"$C6Warning: Your bank data could not be loaded.");
}
}
//}
}
c->playTimeBegin = GetTickCount();
// send the lobby list and add them to an open lobby, if possible
LOBBY* l;
if (!errors)
{
CommandSendLobbyList(s,c);
if (c->version == VERSION_BLUEBURST) CommandBBSendPlayerInfo(c);
CommandSimple(c,0x0095,0x00000000); // this is GetCharacterInfo(), in effect
ProcessCommands(s,c,0x0061,0);
ConsolePrintColor("$0E> Lobby server: client joining lobby\n");
if (ProcedureChangeLobby(s,NULL,NULL,c))
{
ConsolePrintColor("$0E> Lobby server error: lobbies full\n");
CommandMessageBox(c,L"$C6All lobbies are currently full.");
} else {
ConsolePrintColor("$0E> Lobby server: client leaving lobby with error code %d\n",ProcessCommands(s,c,0));
l = FindLobby(s,c->lobbyID);
if (l) ProcedureChangeLobby(s,l,NULL,c);
}
}
c->playerInfo.disp.playTime += ((GetTickCount() - c->playTimeBegin) / 1000);
// if the client is BB, save the player and account data
if (c->version == VERSION_BLUEBURST)
{
//errors = SendPlayerInfoToShipgate(...);
//if (errors)
//{
sprintf(filename,"system\\players\\account_%s.nsa",c->license.username);
PlayerSaveAccountData(&c->playerInfo,filename);
sprintf(filename,"system\\players\\player_%s_%d.nsc",c->license.username,c->cfg.bbplayernum + 1);
PlayerSavePlayerData(&c->playerInfo,filename);
sprintf(filename,"system\\players\\bank_%s_%s.nsb",c->license.username,c->playerInfo.bankname);
PlayerSaveBankData(&c->playerInfo.bank,filename);
//}
}
// remove and delete the client
RemoveClient(s,c);
DeleteClient(c);
ConsolePrintColor("$0E> Lobby server: disconnecting client\n");
return 0;
}