Skip to content

Commit 23ba42b

Browse files
authored
Merge pull request #241 from FreeZoneMods/xd_dev
Fix crash after GameSpy client query
2 parents 94acc9a + aa8207b commit 23ba42b

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

src/xrGame/gamespy/GameSpy_QR2_callbacks.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void __cdecl callback_serverkey(int keyid, qr2_buffer_t outbuf, void* userdata)
3131
{
3232
if (!userdata)
3333
return;
34-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
34+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
3535
if (!pServer)
3636
return;
3737
CGameSpy_QR2* pQR2 = pServer->QR2();
@@ -195,7 +195,7 @@ void __cdecl callback_serverkey(int keyid, qr2_buffer_t outbuf, void* userdata)
195195

196196
void __cdecl callback_playerkey(int keyid, int index, qr2_buffer_t outbuf, void* userdata)
197197
{
198-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
198+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
199199
if (!pServer)
200200
return;
201201
if (u32(index) >= pServer->GetClientsCount())
@@ -262,7 +262,7 @@ void __cdecl callback_playerkey(int keyid, int index, qr2_buffer_t outbuf, void*
262262

263263
void __cdecl callback_teamkey(int keyid, int index, qr2_buffer_t outbuf, void* userdata)
264264
{
265-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
265+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
266266
if (!pServer)
267267
return;
268268

@@ -290,7 +290,7 @@ void __cdecl callback_keylist(qr2_key_type keytype, qr2_keybuffer_t keybuffer, v
290290
{
291291
if (!userdata)
292292
return;
293-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
293+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
294294
CGameSpy_QR2* pQR2 = pServer->QR2();
295295
if (!pQR2)
296296
return;
@@ -375,7 +375,7 @@ int __cdecl callback_count(qr2_key_type keytype, void* userdata)
375375
{
376376
if (!userdata)
377377
return 0;
378-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
378+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
379379
switch (keytype)
380380
{
381381
case key_player: { return pServer->GetPlayersCount();
@@ -405,7 +405,7 @@ int __cdecl callback_count(qr2_key_type keytype, void* userdata)
405405
void __cdecl callback_adderror(qr2_error_t error, gsi_char* errmsg, void* userdata)
406406
{
407407
Msg("! Error while adding this server to master list ->%s.", errmsg);
408-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
408+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
409409
if (pServer)
410410
pServer->OnError_Add(error);
411411
};
@@ -416,7 +416,7 @@ void __cdecl callback_cm(char* data, int len, void* userdata){};
416416
void __cdecl callback_deny_ip(void* userdata, unsigned int sender_ip, int* result)
417417
{
418418
*result = 0;
419-
IPureServer* pServer = static_cast<CGameSpy_QR2::Context*>(userdata)->GSServer;
419+
IPureServer* pServer = static_cast<xrGameSpyServer*>(userdata);
420420
if (pServer && pServer->IsPlayerIPDenied(static_cast<u32>(sender_ip)))
421421
{
422422
*result = 1;
@@ -425,7 +425,7 @@ void __cdecl callback_deny_ip(void* userdata, unsigned int sender_ip, int* resul
425425
/*
426426
void __cdecl callback_public(unsigned int ip, unsigned short port, void* userdata)
427427
{
428-
xrGameSpyServer* pServer = static_cast<CGameSpy_QR2::Context *>(userdata)->GSServer;
428+
xrGameSpyServer* pServer = static_cast<xrGameSpyServer*>(userdata);
429429
if (!pServer)
430430
{
431431
VERIFY2(pServer, "xrGameSpyServer is NULL");

src/xrGame/xrGameSpy_GameSpyFuncs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// void xrGameSpyServer::QR2_Init (u32 PortID)
88
void xrGameSpyServer::QR2_Init(int PortID)
99
{
10-
CGameSpy_QR2::Context ctx;
10+
CGameSpy_QR2::SInitConfig ctx;
1111
ctx.OnServerKey = callback_serverkey;
1212
ctx.OnPlayerKey = callback_playerkey;
1313
ctx.OnTeamKey = callback_teamkey;

src/xrGameSpy/GameSpy_QR2.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,27 @@ void CGameSpy_QR2::RegisterAdditionalKeys()
8585
qr2_register_keyA(SERVER_UP_TIME_KEY, ("server_up_time"));
8686
};
8787

88-
bool CGameSpy_QR2::Init(int PortID, int Public, Context& ctx)
89-
{
90-
//--------- QR2 Init -------------------------/
91-
// call qr_init with the query port number and gamename, default IP address, and no user data
92-
93-
// if (qr2_initA(NULL,NULL,PortID, GAMESPY_GAMENAME, m_SecretKey, Public, 0,
94-
qr2_error_t err = xrGS_qr2_initA(NULL, NULL, PortID, Public, 0, ctx.OnServerKey, ctx.OnPlayerKey, ctx.OnTeamKey,
95-
ctx.OnKeyList, ctx.OnCount, ctx.OnError, &ctx);
88+
bool CGameSpy_QR2::Init(int PortID, int Public, SInitConfig& ctx)
89+
{
90+
qr2_error_t err = xrGS_qr2_initA(nullptr,
91+
nullptr,
92+
PortID,
93+
Public,
94+
0,
95+
ctx.OnServerKey,
96+
ctx.OnPlayerKey,
97+
ctx.OnTeamKey,
98+
ctx.OnKeyList,
99+
ctx.OnCount,
100+
ctx.OnError,
101+
ctx.GSServer);
102+
96103
#ifndef MASTER_GOLD
97104
Msg("xrGS::xrGS_qr2_initA returned code is [%d]", err);
98105
#endif // #ifndef MASTER_GOLD
99106

100107
if (err != e_qrnoerror)
101108
{
102-
// _tprintf(_T("Error starting query sockets\n"));
103109
Msg("xrGS::QR2 : Failes to Initialize!");
104110
return false;
105111
}
@@ -112,8 +118,7 @@ bool CGameSpy_QR2::Init(int PortID, int Public, Context& ctx)
112118
// Set a function to be called when we receive a nat negotiation request
113119
qr2_register_natneg_callback(NULL, ctx.OnNatNeg);
114120

115-
// Set a function to be called when gamespy responds my IP and port number
116-
// qr2_register_publicaddress_callback(NULL, callback_public);
121+
// Set a function to be called when gamespy responds my IP and port number
117122
qr2_register_denyresponsetoip_callback(NULL, ctx.OnDenyIP);
118123

119124
#ifndef MASTER_GOLD

src/xrGameSpy/GameSpy_QR2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class xrGameSpyServer;
66
class XRGAMESPY_API CGameSpy_QR2
77
{
88
public:
9-
class Context
9+
struct SInitConfig
1010
{
1111
public:
1212
void(__cdecl* OnServerKey)(int keyid, qr2_buffer_t outbuf, void* userdata);
@@ -25,7 +25,7 @@ class XRGAMESPY_API CGameSpy_QR2
2525
// string16 m_SecretKey;
2626

2727
public:
28-
bool Init(int PortID, int Public, Context& ctx);
28+
bool Init(int PortID, int Public, SInitConfig& ctx);
2929
void Think(void* qrec);
3030
void ShutDown(void* qrec);
3131
void RegisterAdditionalKeys();

0 commit comments

Comments
 (0)