From 6cf79729db2fa6847c41904d30d812c177092cc9 Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 15 Jan 2017 10:34:04 +0100 Subject: [PATCH] Reformat: xrGameSpy --- src/xrGameSpy/GameSpy_ATLAS.cpp | 194 ++++------- src/xrGameSpy/GameSpy_ATLAS.h | 99 ++---- src/xrGameSpy/GameSpy_Available.cpp | 51 ++- src/xrGameSpy/GameSpy_Available.h | 2 +- src/xrGameSpy/GameSpy_Browser.cpp | 485 +++++++++++++-------------- src/xrGameSpy/GameSpy_Browser.h | 158 ++++----- src/xrGameSpy/GameSpy_Full.cpp | 85 ++--- src/xrGameSpy/GameSpy_Full.h | 36 +- src/xrGameSpy/GameSpy_GCD_Client.cpp | 8 +- src/xrGameSpy/GameSpy_GCD_Client.h | 2 +- src/xrGameSpy/GameSpy_GCD_Server.cpp | 77 ++--- src/xrGameSpy/GameSpy_GCD_Server.h | 24 +- src/xrGameSpy/GameSpy_GP.cpp | 292 ++++++---------- src/xrGameSpy/GameSpy_GP.h | 79 ++--- src/xrGameSpy/GameSpy_HTTP.cpp | 130 ++++--- src/xrGameSpy/GameSpy_HTTP.h | 18 +- src/xrGameSpy/GameSpy_Keys.h | 139 ++++---- src/xrGameSpy/GameSpy_Patching.cpp | 124 ++++--- src/xrGameSpy/GameSpy_Patching.h | 8 +- src/xrGameSpy/GameSpy_QR2.cpp | 264 +++++++-------- src/xrGameSpy/GameSpy_QR2.h | 40 +-- src/xrGameSpy/GameSpy_SAKE.cpp | 103 ++---- src/xrGameSpy/GameSpy_SAKE.h | 42 +-- src/xrGameSpy/stdafx.h | 10 +- src/xrGameSpy/xrGameSpy.cpp | 135 ++++---- src/xrGameSpy/xrGameSpy.h | 18 +- src/xrGameSpy/xrGameSpy_MainDefs.h | 70 ++-- 27 files changed, 1191 insertions(+), 1502 deletions(-) diff --git a/src/xrGameSpy/GameSpy_ATLAS.cpp b/src/xrGameSpy/GameSpy_ATLAS.cpp index 89f0ba80603..f74d5592e8f 100644 --- a/src/xrGameSpy/GameSpy_ATLAS.cpp +++ b/src/xrGameSpy/GameSpy_ATLAS.cpp @@ -1,188 +1,124 @@ -#include "stdafx.h" #include "GameSpy_ATLAS.h" +#include "stdafx.h" -CGameSpy_ATLAS::CGameSpy_ATLAS () +CGameSpy_ATLAS::CGameSpy_ATLAS() { - m_interface = NULL; - Init (); + m_interface = NULL; + Init(); } -CGameSpy_ATLAS::~CGameSpy_ATLAS () +CGameSpy_ATLAS::~CGameSpy_ATLAS() { - if (m_interface) - { - scShutdown(m_interface); - } + if (m_interface) { + scShutdown(m_interface); + } } void CGameSpy_ATLAS::Init() { - SCResult init_res = scInitialize(GAMESPY_GAMEID, &m_interface); - VERIFY(init_res == SCResult_NO_ERROR); - if (init_res != SCResult_NO_ERROR) - { - Msg("! GameSpy ATLAS: failed to initialize, error code: %d", init_res); - } + SCResult init_res = scInitialize(GAMESPY_GAMEID, &m_interface); + VERIFY(init_res == SCResult_NO_ERROR); + if (init_res != SCResult_NO_ERROR) { + Msg("! GameSpy ATLAS: failed to initialize, error code: %d", init_res); + } } void CGameSpy_ATLAS::Think() { - scThink(m_interface); + scThink(m_interface); } shared_str const CGameSpy_ATLAS::TryToTranslate(GHTTPResult httpResult) { - return "mp_gamespy_http_error"; + return "mp_gamespy_http_error"; } shared_str const CGameSpy_ATLAS::TryToTranslate(WSLoginValue loginValue) { - return "mp_gamespy_ws_login_error"; + return "mp_gamespy_ws_login_error"; } shared_str const CGameSpy_ATLAS::TryToTranslate(SCResult result) { - return "mp_gamespy_atlas_error"; + return "mp_gamespy_atlas_error"; } -u32 CGameSpy_ATLAS::WSLoginProfile(shared_str const & email, - shared_str const & nick, - shared_str const & password, - WSLoginCallback callback, - void * userData) +u32 CGameSpy_ATLAS::WSLoginProfile(shared_str const& email, shared_str const& nick, shared_str const& password, + WSLoginCallback callback, void* userData) { - return static_cast(wsLoginProfile(GP_PARTNERID_GAMESPY, GAMESPY_GP_NAMESPACE_ID, - nick.c_str(), email.c_str(), password.c_str(), NULL, callback, userData)); + return static_cast(wsLoginProfile(GP_PARTNERID_GAMESPY, GAMESPY_GP_NAMESPACE_ID, nick.c_str(), email.c_str(), + password.c_str(), NULL, callback, userData)); } -SCResult CGameSpy_ATLAS::CreateSession(const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCCreateSessionCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData) +SCResult CGameSpy_ATLAS::CreateSession(const GSLoginCertificate* theCertificate, + const GSLoginPrivateData* thePrivateData, SCCreateSessionCallback theCallback, gsi_time theTimeoutMs, + void* theUserData) { - return scCreateSession( - m_interface, - theCertificate, - thePrivateData, - theCallback, - theTimeoutMs, - theUserData - ); + return scCreateSession(m_interface, theCertificate, thePrivateData, theCallback, theTimeoutMs, theUserData); } SCResult CGameSpy_ATLAS::SetReportIntention(const gsi_u8 theConnectionId[SC_CONNECTION_GUID_SIZE], - gsi_bool isAuthoritative, - const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCSetReportIntentionCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData) -{ - return scSetReportIntention( - m_interface, - theConnectionId, - isAuthoritative, - theCertificate, - thePrivateData, - theCallback, - theTimeoutMs, - theUserData - ); -} - -char const* CGameSpy_ATLAS::GetConnectionId() -{ - return scGetConnectionId(m_interface); -} - -SCResult CGameSpy_ATLAS::SubmitReport(const SCReportPtr theReport, - gsi_bool isAuthoritative, - const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCSubmitReportCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData) -{ - return scSubmitReport( - m_interface, - theReport, - isAuthoritative, - theCertificate, - thePrivateData, - theCallback, - theTimeoutMs, - theUserData - ); -} - -SCResult CGameSpy_ATLAS::CreateReport(gsi_u32 theHeaderVersion, - gsi_u32 thePlayerCount, - gsi_u32 theTeamCount, - SCReportPtr * theReportOut) -{ - return scCreateReport( - m_interface, - theHeaderVersion, - thePlayerCount, - theTeamCount, - theReportOut - ); + gsi_bool isAuthoritative, const GSLoginCertificate* theCertificate, const GSLoginPrivateData* thePrivateData, + SCSetReportIntentionCallback theCallback, gsi_time theTimeoutMs, void* theUserData) +{ + return scSetReportIntention(m_interface, theConnectionId, isAuthoritative, theCertificate, thePrivateData, + theCallback, theTimeoutMs, theUserData); +} + +char const* CGameSpy_ATLAS::GetConnectionId() +{ + return scGetConnectionId(m_interface); +} + +SCResult CGameSpy_ATLAS::SubmitReport(const SCReportPtr theReport, gsi_bool isAuthoritative, + const GSLoginCertificate* theCertificate, const GSLoginPrivateData* thePrivateData, + SCSubmitReportCallback theCallback, gsi_time theTimeoutMs, void* theUserData) +{ + return scSubmitReport(m_interface, theReport, isAuthoritative, theCertificate, thePrivateData, theCallback, + theTimeoutMs, theUserData); +} + +SCResult CGameSpy_ATLAS::CreateReport( + gsi_u32 theHeaderVersion, gsi_u32 thePlayerCount, gsi_u32 theTeamCount, SCReportPtr* theReportOut) +{ + return scCreateReport(m_interface, theHeaderVersion, thePlayerCount, theTeamCount, theReportOut); } SCResult CGameSpy_ATLAS::ReportBeginGlobalData(SCReportPtr theReportData) { - return scReportBeginGlobalData(theReportData); + return scReportBeginGlobalData(theReportData); } SCResult CGameSpy_ATLAS::ReportBeginPlayerData(SCReportPtr theReportData) { - return scReportBeginPlayerData(theReportData); + return scReportBeginPlayerData(theReportData); } SCResult CGameSpy_ATLAS::ReportBeginNewPlayer(SCReportPtr theReportData) { - return scReportBeginNewPlayer(theReportData); + return scReportBeginNewPlayer(theReportData); } -SCResult CGameSpy_ATLAS::ReportSetPlayerData(SCReportPtr theReport, - gsi_u32 thePlayerIndex, - const gsi_u8 thePlayerConnectionId[SC_CONNECTION_GUID_SIZE], - gsi_u32 thePlayerTeamIndex, - SCGameResult theResult, - gsi_u32 theProfileId, - const GSLoginCertificate * theCertificate) +SCResult CGameSpy_ATLAS::ReportSetPlayerData(SCReportPtr theReport, gsi_u32 thePlayerIndex, + const gsi_u8 thePlayerConnectionId[SC_CONNECTION_GUID_SIZE], gsi_u32 thePlayerTeamIndex, SCGameResult theResult, + gsi_u32 theProfileId, const GSLoginCertificate* theCertificate) { - gsi_u8 zero_auth_data[16]; - ZeroMemory(zero_auth_data, sizeof(zero_auth_data)); - return scReportSetPlayerData( - theReport, - thePlayerIndex, - thePlayerConnectionId, - thePlayerTeamIndex, - theResult, - theProfileId, - theCertificate, - zero_auth_data - ); + gsi_u8 zero_auth_data[16]; + ZeroMemory(zero_auth_data, sizeof(zero_auth_data)); + return scReportSetPlayerData(theReport, thePlayerIndex, thePlayerConnectionId, thePlayerTeamIndex, theResult, + theProfileId, theCertificate, zero_auth_data); } -SCResult CGameSpy_ATLAS::ReportAddIntValue(SCReportPtr theReportData, - gsi_u16 theKeyId, - gsi_i32 theValue) +SCResult CGameSpy_ATLAS::ReportAddIntValue(SCReportPtr theReportData, gsi_u16 theKeyId, gsi_i32 theValue) { - return scReportAddIntValue(theReportData, theKeyId, theValue); + return scReportAddIntValue(theReportData, theKeyId, theValue); } -SCResult CGameSpy_ATLAS::ReportAddStringValue(SCReportPtr theReportData, - gsi_u16 theKeyId, - const gsi_char * theValue) +SCResult CGameSpy_ATLAS::ReportAddStringValue(SCReportPtr theReportData, gsi_u16 theKeyId, const gsi_char* theValue) { - return scReportAddStringValue(theReportData, theKeyId, theValue); + return scReportAddStringValue(theReportData, theKeyId, theValue); } -SCResult CGameSpy_ATLAS::ReportEnd(SCReportPtr theReport, - gsi_bool isAuth, - SCGameStatus theStatus) +SCResult CGameSpy_ATLAS::ReportEnd(SCReportPtr theReport, gsi_bool isAuth, SCGameStatus theStatus) { - return scReportEnd(theReport, isAuth, theStatus); + return scReportEnd(theReport, isAuth, theStatus); } diff --git a/src/xrGameSpy/GameSpy_ATLAS.h b/src/xrGameSpy/GameSpy_ATLAS.h index 52d24117991..3eb16a0e25c 100644 --- a/src/xrGameSpy/GameSpy_ATLAS.h +++ b/src/xrGameSpy/GameSpy_ATLAS.h @@ -7,69 +7,44 @@ class XRGAMESPY_API CGameSpy_ATLAS { public: - CGameSpy_ATLAS (); - ~CGameSpy_ATLAS (); + CGameSpy_ATLAS(); + ~CGameSpy_ATLAS(); + + void Think(); + u32 WSLoginProfile(shared_str const& email, shared_str const& nick, shared_str const& password, + WSLoginCallback callback, void* userData); + + SCResult CreateSession(const GSLoginCertificate* theCertificate, const GSLoginPrivateData* thePrivateData, + SCCreateSessionCallback theCallback, gsi_time theTimeoutMs, void* theUserData); + + SCResult SetReportIntention(const gsi_u8 theConnectionId[SC_CONNECTION_GUID_SIZE], gsi_bool isAuthoritative, + const GSLoginCertificate* theCertificate, const GSLoginPrivateData* thePrivateData, + SCSetReportIntentionCallback theCallback, gsi_time theTimeoutMs, void* theUserData); + char const* GetConnectionId(); + SCResult SubmitReport(const SCReportPtr theReport, gsi_bool isAuthoritative, + const GSLoginCertificate* theCertificate, const GSLoginPrivateData* thePrivateData, + SCSubmitReportCallback theCallback, gsi_time theTimeoutMs, void* theUserData); + + SCResult CreateReport( + gsi_u32 theHeaderVersion, gsi_u32 thePlayerCount, gsi_u32 theTeamCount, SCReportPtr* theReportOut); + SCResult ReportBeginGlobalData(SCReportPtr theReportData); + SCResult ReportBeginPlayerData(SCReportPtr theReportData); + SCResult ReportBeginNewPlayer(SCReportPtr theReportData); + SCResult ReportSetPlayerData(SCReportPtr theReport, gsi_u32 thePlayerIndex, + const gsi_u8 thePlayerConnectionId[SC_CONNECTION_GUID_SIZE], gsi_u32 thePlayerTeamIndex, SCGameResult theResult, + gsi_u32 theProfileId, const GSLoginCertificate* theCertificate); + SCResult ReportAddIntValue(SCReportPtr theReportData, gsi_u16 theKeyId, gsi_i32 theValue); + SCResult ReportAddStringValue(SCReportPtr theReportData, gsi_u16 theKeyId, const gsi_char* theValue); + SCResult ReportEnd(SCReportPtr theReport, gsi_bool isAuth, SCGameStatus theStatus); + + static shared_str const TryToTranslate(GHTTPResult httpResult); + static shared_str const TryToTranslate(WSLoginValue loginValue); + static shared_str const TryToTranslate(SCResult result); - void Think (); - u32 WSLoginProfile (shared_str const & email, - shared_str const & nick, - shared_str const & password, - WSLoginCallback callback, - void * userData); - - SCResult CreateSession (const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCCreateSessionCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData); - - SCResult SetReportIntention (const gsi_u8 theConnectionId[SC_CONNECTION_GUID_SIZE], - gsi_bool isAuthoritative, - const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCSetReportIntentionCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData); - char const* GetConnectionId (); - SCResult SubmitReport (const SCReportPtr theReport, - gsi_bool isAuthoritative, - const GSLoginCertificate * theCertificate, - const GSLoginPrivateData * thePrivateData, - SCSubmitReportCallback theCallback, - gsi_time theTimeoutMs, - void * theUserData); - - SCResult CreateReport (gsi_u32 theHeaderVersion, - gsi_u32 thePlayerCount, - gsi_u32 theTeamCount, - SCReportPtr * theReportOut); - SCResult ReportBeginGlobalData (SCReportPtr theReportData); - SCResult ReportBeginPlayerData (SCReportPtr theReportData); - SCResult ReportBeginNewPlayer (SCReportPtr theReportData); - SCResult ReportSetPlayerData (SCReportPtr theReport, - gsi_u32 thePlayerIndex, - const gsi_u8 thePlayerConnectionId[SC_CONNECTION_GUID_SIZE], - gsi_u32 thePlayerTeamIndex, - SCGameResult theResult, - gsi_u32 theProfileId, - const GSLoginCertificate * theCertificate); - SCResult ReportAddIntValue (SCReportPtr theReportData, - gsi_u16 theKeyId, - gsi_i32 theValue); - SCResult ReportAddStringValue (SCReportPtr theReportData, - gsi_u16 theKeyId, - const gsi_char * theValue); - SCResult ReportEnd (SCReportPtr theReport, - gsi_bool isAuth, - SCGameStatus theStatus); - - static shared_str const TryToTranslate(GHTTPResult httpResult); - static shared_str const TryToTranslate(WSLoginValue loginValue); - static shared_str const TryToTranslate(SCResult result); private: - SCInterfacePtr m_interface; + SCInterfacePtr m_interface; - void Init (); -}; //class CGameSpy_ATLAS + void Init(); +}; // class CGameSpy_ATLAS -#endif //#ifndef GAMESPY_ATLAS_INCLUDED +#endif //#ifndef GAMESPY_ATLAS_INCLUDED diff --git a/src/xrGameSpy/GameSpy_Available.cpp b/src/xrGameSpy/GameSpy_Available.cpp index 227406a4cbf..ec918bb30f5 100644 --- a/src/xrGameSpy/GameSpy_Available.cpp +++ b/src/xrGameSpy/GameSpy_Available.cpp @@ -1,32 +1,31 @@ -#include "StdAfx.h" #include "GameSpy_Available.h" +#include "StdAfx.h" -bool CGameSpy_Available::CheckAvailableServices (shared_str& resultstr) +bool CGameSpy_Available::CheckAvailableServices(shared_str& resultstr) { - GSIACResult result; - GSIStartAvailableCheckA(GAMESPY_GAMENAME); + GSIACResult result; + GSIStartAvailableCheckA(GAMESPY_GAMENAME); - while((result = GSIAvailableCheckThink()) == GSIACWaiting) - msleep(5); + while ((result = GSIAvailableCheckThink()) == GSIACWaiting) + msleep(5); - if(result != GSIACAvailable) - { - switch (result) - { - case GSIACUnavailable: - { - resultstr = "! Online Services for STALKER are no longer available."; - }break; - case GSIACTemporarilyUnavailable: - { - resultstr = "! Online Services for STALKER are temporarily down for maintenance."; - }break; - } - return false; - } - else - { - resultstr = "Success"; - }; - return true; + if (result != GSIACAvailable) { + switch (result) + { + case GSIACUnavailable: { resultstr = "! Online Services for STALKER are no longer available."; + } + break; + case GSIACTemporarilyUnavailable: + { + resultstr = "! Online Services for STALKER are temporarily down for maintenance."; + } + break; + } + return false; + } + else + { + resultstr = "Success"; + }; + return true; }; diff --git a/src/xrGameSpy/GameSpy_Available.h b/src/xrGameSpy/GameSpy_Available.h index ea22ac134d0..17fce28bd6e 100644 --- a/src/xrGameSpy/GameSpy_Available.h +++ b/src/xrGameSpy/GameSpy_Available.h @@ -6,5 +6,5 @@ class XRGAMESPY_API CGameSpy_Available { public: - bool CheckAvailableServices (shared_str& resultstr); + bool CheckAvailableServices(shared_str& resultstr); }; diff --git a/src/xrGameSpy/GameSpy_Browser.cpp b/src/xrGameSpy/GameSpy_Browser.cpp index 388b8bff284..85312dceb13 100644 --- a/src/xrGameSpy/GameSpy_Browser.cpp +++ b/src/xrGameSpy/GameSpy_Browser.cpp @@ -1,89 +1,96 @@ -#include "StdAfx.h" #include "GameSpy_Browser.h" -#include "xrServerEntities/gametype_chooser.h" -#include "GameSpy_Keys.h" #include "Common/object_broker.h" +#include "GameSpy_Keys.h" +#include "StdAfx.h" +#include "xrServerEntities/gametype_chooser.h" -#define GAMETYPE_NAME_KEY 100 -#define DEDICATED_KEY 101 -#define G_USER_PASSWORD_KEY 135 +#define GAMETYPE_NAME_KEY 100 +#define DEDICATED_KEY 101 +#define G_USER_PASSWORD_KEY 135 namespace { -void __cdecl SBCallback(ServerBrowser sb, SBCallbackReason reason, SBServer server, void *instance) +void __cdecl SBCallback(ServerBrowser sb, SBCallbackReason reason, SBServer server, void* instance) { - CGameSpy_Browser* pGSBrowser = (CGameSpy_Browser*) instance; - if (!pGSBrowser) return; - switch (reason) - { - case sbc_serveradded : //a server was added to the list, may just have an IP & port at this point - { + CGameSpy_Browser* pGSBrowser = (CGameSpy_Browser*)instance; + if (!pGSBrowser) return; + switch (reason) + { + case sbc_serveradded: // a server was added to the list, may just have an IP & port at this point + { #ifdef _DEBUG //. Msg("sbc_serveradded"); #endif -// pGSBrowser->SortBrowserByPing(); -// pGSBrowser->UpdateServerList(); - }break; - case sbc_serverupdated : //server information has been updated - either basic or full information is now available about this server - { + // pGSBrowser->SortBrowserByPing(); + // pGSBrowser->UpdateServerList(); + } + break; + case sbc_serverupdated: // server information has been updated - either basic or full information is now available + // about this server + { #ifdef _DEBUG //. Msg("sbc_serverupdated"); #endif -// pGSBrowser->SortBrowserByPing(); - pGSBrowser->UpdateServerList(); - }break; - case sbc_serverupdatefailed : //an attempt to retrieve information about this server, either directly or from the master, failed - { + // pGSBrowser->SortBrowserByPing(); + pGSBrowser->UpdateServerList(); + } + break; + case sbc_serverupdatefailed: // an attempt to retrieve information about this server, either directly or from the + // master, failed + { #ifdef _DEBUG //. Msg("sbc_serverupdatefailed"); #endif -// pGSBrowser->OnUpdateFailed(server); -// pGSBrowser->SortBrowserByPing(); - pGSBrowser->UpdateServerList(); - }break; - case sbc_serverdeleted : //a server was removed from the list - { + // pGSBrowser->OnUpdateFailed(server); + // pGSBrowser->SortBrowserByPing(); + pGSBrowser->UpdateServerList(); + } + break; + case sbc_serverdeleted: // a server was removed from the list + { #ifdef _DEBUG - Msg("sbc_serverdeleted"); + Msg("sbc_serverdeleted"); #endif -// pGSBrowser->SortBrowserByPing(); - pGSBrowser->UpdateServerList(); - }break; - case sbc_updatecomplete : //the server query engine is now idle - { + // pGSBrowser->SortBrowserByPing(); + pGSBrowser->UpdateServerList(); + } + break; + case sbc_updatecomplete: // the server query engine is now idle + { #ifdef _DEBUG //. Msg("sbc_updatecomplete"); #endif -// pGSBrowser->SortBrowserByPing(); - pGSBrowser->UpdateServerList(); - }break; - case sbc_queryerror ://the master returned an error string for the provided query - { + // pGSBrowser->SortBrowserByPing(); + pGSBrowser->UpdateServerList(); + } + break; + case sbc_queryerror: // the master returned an error string for the provided query + { #ifdef _DEBUG - Msg("sbc_queryerror"); + Msg("sbc_queryerror"); #endif - }break; - case sbc_serverchallengereceived: - { + } + break; + case sbc_serverchallengereceived: { #ifdef _DEBUG //. Msg("sbc_serverchallengereceived"); #endif - }break; - default: - { - R_ASSERT2(0, "Unknown Callback Reason"); - }break; - }; + } + break; + default: { R_ASSERT2(0, "Unknown Callback Reason"); + } + break; + }; } } CGameSpy_Browser::CGameSpy_Browser() #ifdef CONFIG_PROFILE_LOCKS - :m_refresh_lock(MUTEX_PROFILE_ID(CGameSpy_Browser::m_refresh_lock)) -#endif // CONFIG_PROFILE_LOCKS + : m_refresh_lock(MUTEX_PROFILE_ID(CGameSpy_Browser::m_refresh_lock)) +#endif // CONFIG_PROFILE_LOCKS { - m_pQR2 = NULL; - m_pGSBrowser = NULL; + m_pQR2 = NULL; + m_pGSBrowser = NULL; m_pQR2 = new CGameSpy_QR2(); m_pQR2->RegisterAdditionalKeys(); m_bAbleToConnectToMasterServer = true; @@ -91,10 +98,9 @@ CGameSpy_Browser::CGameSpy_Browser() m_bShowCMSErr = false; char secretKey[16]; FillSecretKey(secretKey); - m_pGSBrowser = ServerBrowserNewA(GAMESPY_GAMENAME, GAMESPY_GAMENAME, secretKey, - 0, GAMESPY_BROWSER_MAX_UPDATES, QVERSION_QR2, SBFalse, SBCallback, this); - if (!m_pGSBrowser) - { + m_pGSBrowser = ServerBrowserNewA(GAMESPY_GAMENAME, GAMESPY_GAMENAME, secretKey, 0, GAMESPY_BROWSER_MAX_UPDATES, + QVERSION_QR2, SBFalse, SBCallback, this); + if (!m_pGSBrowser) { Msg("! Unable to init Server Browser!"); } // else @@ -103,31 +109,28 @@ CGameSpy_Browser::CGameSpy_Browser() CGameSpy_Browser::~CGameSpy_Browser() { - if (onDestroy) - onDestroy(this); + if (onDestroy) onDestroy(this); - Clear(); + Clear(); - delete_data(m_pQR2); - if (m_pGSBrowser) - { - ServerBrowserFree(m_pGSBrowser); - m_pGSBrowser = NULL; - } + delete_data(m_pQR2); + if (m_pGSBrowser) { + ServerBrowserFree(m_pGSBrowser); + m_pGSBrowser = NULL; + } }; static bool services_checked = false; -bool CGameSpy_Browser::Init(UpdateCallback updateCb, DestroyCallback destroyCb) +bool CGameSpy_Browser::Init(UpdateCallback updateCb, DestroyCallback destroyCb) { - if (onDestroy) - onDestroy(this); + if (onDestroy) onDestroy(this); onUpdate = updateCb; onDestroy = destroyCb; - return true; + return true; }; -void CGameSpy_Browser::Clear() +void CGameSpy_Browser::Clear() { onUpdate.clear(); onDestroy.clear(); @@ -135,63 +138,47 @@ void CGameSpy_Browser::Clear() struct RefreshData { - CGameSpy_Browser* pGSBrowser; - string4096 FilterStr; + CGameSpy_Browser* pGSBrowser; + string4096 FilterStr; }; -void RefreshInternetList (void * inData) +void RefreshInternetList(void* inData) { - RefreshData* pRData = (RefreshData*) inData; - pRData->pGSBrowser->RefreshListInternet(pRData->FilterStr); - xr_delete(pRData); + RefreshData* pRData = (RefreshData*)inData; + pRData->pGSBrowser->RefreshListInternet(pRData->FilterStr); + xr_delete(pRData); }; -void CGameSpy_Browser::RefreshListInternet (const char* FilterStr) +void CGameSpy_Browser::RefreshListInternet(const char* FilterStr) { - m_refresh_lock.Enter(); - static const u8 targetFields[] = - { - HOSTNAME_KEY, - HOSTPORT_KEY, - NUMPLAYERS_KEY, - MAXPLAYERS_KEY, - MAPNAME_KEY, - GAMETYPE_KEY, - GAMEVER_KEY, - PASSWORD_KEY, - G_USER_PASSWORD_KEY, - DEDICATED_KEY, - GAMETYPE_NAME_KEY - }; - const int fieldCount = sizeof(targetFields)/sizeof(targetFields[0]); - SBError error = ServerBrowserUpdateA(m_pGSBrowser, onUpdate ? SBTrue : SBFalse, - SBFalse, targetFields, fieldCount, FilterStr); - m_bAbleToConnectToMasterServer = (error == sbe_noerror); - m_bShowCMSErr = (error != sbe_noerror); - m_bTryingToConnectToMasterServer = false; - - m_refresh_lock.Leave(); + m_refresh_lock.Enter(); + static const u8 targetFields[] = {HOSTNAME_KEY, HOSTPORT_KEY, NUMPLAYERS_KEY, MAXPLAYERS_KEY, MAPNAME_KEY, + GAMETYPE_KEY, GAMEVER_KEY, PASSWORD_KEY, G_USER_PASSWORD_KEY, DEDICATED_KEY, GAMETYPE_NAME_KEY}; + const int fieldCount = sizeof(targetFields) / sizeof(targetFields[0]); + SBError error = + ServerBrowserUpdateA(m_pGSBrowser, onUpdate ? SBTrue : SBFalse, SBFalse, targetFields, fieldCount, FilterStr); + m_bAbleToConnectToMasterServer = (error == sbe_noerror); + m_bShowCMSErr = (error != sbe_noerror); + m_bTryingToConnectToMasterServer = false; + + m_refresh_lock.Leave(); }; GSUpdateStatus CGameSpy_Browser::RefreshList_Full(bool Local, const char* FilterStr) { - if (!m_pGSBrowser) - return GSUpdateStatus::Success; - SBState state = ServerBrowserState(m_pGSBrowser); - if((state != sb_connected) && (state != sb_disconnected)) - { - ServerBrowserHalt(m_pGSBrowser); - Msg("xrGSB Refresh Stopped\n"); - }; - ServerBrowserClear(m_pGSBrowser); - - // do an update - if (!Local) - { + if (!m_pGSBrowser) return GSUpdateStatus::Success; + SBState state = ServerBrowserState(m_pGSBrowser); + if ((state != sb_connected) && (state != sb_disconnected)) { + ServerBrowserHalt(m_pGSBrowser); + Msg("xrGSB Refresh Stopped\n"); + }; + ServerBrowserClear(m_pGSBrowser); + + // do an update + if (!Local) { m_refresh_lock.Enter(); m_refresh_lock.Leave(); - if (!m_bAbleToConnectToMasterServer) - return GSUpdateStatus::MasterUnreachable; - RefreshData* pRData = new RefreshData(); + if (!m_bAbleToConnectToMasterServer) return GSUpdateStatus::MasterUnreachable; + RefreshData* pRData = new RefreshData(); xr_strcpy(pRData->FilterStr, FilterStr); pRData->pGSBrowser = this; m_bTryingToConnectToMasterServer = true; @@ -199,8 +186,7 @@ GSUpdateStatus CGameSpy_Browser::RefreshList_Full(bool Local, const char* Filter return GSUpdateStatus::ConnectingToMaster; } SBError error = ServerBrowserLANUpdate(m_pGSBrowser, onUpdate ? SBTrue : SBFalse, START_PORT_LAN, END_PORT_LAN); - if (error!=sbe_noerror) - { + if (error != sbe_noerror) { Msg("! xrGSB Error - %s", ServerBrowserErrorDescA(m_pGSBrowser, error)); return GSUpdateStatus::Unknown; } @@ -209,218 +195,205 @@ GSUpdateStatus CGameSpy_Browser::RefreshList_Full(bool Local, const char* Filter void CGameSpy_Browser::CallBack_OnUpdateCompleted() { - int NumServers = ServerBrowserCount(m_pGSBrowser); - - ServerInfo NewServerInfo; - for (int i=0; iIndex = idx; + void* pServer = GetServerByIndex(idx); + ReadServerInfo(pServerInfo, pServer); + pServerInfo->Index = idx; } -void *CGameSpy_Browser::GetServerByIndex(int index) -{ return ServerBrowserGetServer(m_pGSBrowser, index); } +void* CGameSpy_Browser::GetServerByIndex(int index) +{ + return ServerBrowserGetServer(m_pGSBrowser, index); +} -bool CGameSpy_Browser::GetBool(void *srv, int keyId, bool defaultValue) +bool CGameSpy_Browser::GetBool(void* srv, int keyId, bool defaultValue) { - const char *key = m_pQR2->RegisteredKey(keyId); - return SBServerGetBoolValueA(SBServer(srv), key, defaultValue ? SBTrue : SBFalse)==SBTrue; + const char* key = m_pQR2->RegisteredKey(keyId); + return SBServerGetBoolValueA(SBServer(srv), key, defaultValue ? SBTrue : SBFalse) == SBTrue; } -int CGameSpy_Browser::GetInt(void *srv, int keyId, int defaultValue) +int CGameSpy_Browser::GetInt(void* srv, int keyId, int defaultValue) { - const char *key = m_pQR2->RegisteredKey(keyId); + const char* key = m_pQR2->RegisteredKey(keyId); return SBServerGetIntValueA(SBServer(srv), key, defaultValue); } -float CGameSpy_Browser::GetFloat(void *srv, int keyId, float defaultValue) +float CGameSpy_Browser::GetFloat(void* srv, int keyId, float defaultValue) { - const char *key = m_pQR2->RegisteredKey(keyId); + const char* key = m_pQR2->RegisteredKey(keyId); return float(SBServerGetFloatValueA(SBServer(srv), key, defaultValue)); } -const char *CGameSpy_Browser::GetString(void *srv, int keyId, const char *defaultValue) +const char* CGameSpy_Browser::GetString(void* srv, int keyId, const char* defaultValue) { - const char *key = m_pQR2->RegisteredKey(keyId); + const char* key = m_pQR2->RegisteredKey(keyId); return SBServerGetStringValueA(SBServer(srv), key, defaultValue); } -void CGameSpy_Browser::ReadServerInfo (ServerInfo* pServerInfo, void* gsServer) +void CGameSpy_Browser::ReadServerInfo(ServerInfo* pServerInfo, void* gsServer) { auto pServer = static_cast(gsServer); - if (!pServer || !pServerInfo) return; - xr_sprintf(pServerInfo->m_Address, "%s:%d", SBServerGetPublicAddress(pServer), SBServerGetPublicQueryPort(pServer)); - xr_sprintf(pServerInfo->m_HostName, "%s", SBServerGetPublicAddress(pServer)); - xr_sprintf(pServerInfo->m_ServerName, "%s", GetString(pServer, HOSTNAME_KEY, pServerInfo->m_HostName)); - xr_sprintf(pServerInfo->m_SessionName, "%s", GetString(pServer, MAPNAME_KEY, "Unknown")); - xr_sprintf(pServerInfo->m_ServerGameType, "%s", GetString(pServer, GAMETYPE_KEY, "Unknown")); - pServerInfo->m_bPassword = GetBool(pServer, PASSWORD_KEY); - pServerInfo->m_bUserPass = GetBool(pServer, G_USER_PASSWORD_KEY); - pServerInfo->m_Ping = (s16)(SBServerGetPing(pServer) & 0xffff); - pServerInfo->m_ServerNumPlayers = (s16)GetInt(pServer, NUMPLAYERS_KEY, 0); - pServerInfo->m_ServerMaxPlayers = (s16)GetInt(pServer, MAXPLAYERS_KEY, 32); - xr_sprintf(pServerInfo->m_ServerUpTime, "%s", GetString(pServer, SERVER_UP_TIME_KEY, "Unknown")); - pServerInfo->m_ServerNumTeams = (s16)GetInt(pServer, NUMTEAMS_KEY, 0); - pServerInfo->m_Port = (s16)GetInt(pServer, HOSTPORT_KEY, 0); - pServerInfo->m_HPort = (s16)SBServerGetPublicQueryPort(pServer); - pServerInfo->m_bDedicated = GetBool(pServer, DEDICATED_KEY); - pServerInfo->m_GameType = (u8)GetInt(pServer, GAMETYPE_NAME_KEY, 0); - if (pServerInfo->m_GameType == 0) - { - pServerInfo->m_GameType = ParseStringToGameType(pServerInfo->m_ServerGameType); - } - xr_sprintf(pServerInfo->m_ServerVersion, "%s", GetString(pServer, GAMEVER_KEY, "--")); - - //--------- Read Game Infos ---------------------------// - pServerInfo->m_aPlayers.clear(); - pServerInfo->m_aTeams.clear(); - //-------------------------------------------------------// - if (SBServerHasFullKeys(pServer) == SBFalse) return; - + if (!pServer || !pServerInfo) return; + xr_sprintf(pServerInfo->m_Address, "%s:%d", SBServerGetPublicAddress(pServer), SBServerGetPublicQueryPort(pServer)); + xr_sprintf(pServerInfo->m_HostName, "%s", SBServerGetPublicAddress(pServer)); + xr_sprintf(pServerInfo->m_ServerName, "%s", GetString(pServer, HOSTNAME_KEY, pServerInfo->m_HostName)); + xr_sprintf(pServerInfo->m_SessionName, "%s", GetString(pServer, MAPNAME_KEY, "Unknown")); + xr_sprintf(pServerInfo->m_ServerGameType, "%s", GetString(pServer, GAMETYPE_KEY, "Unknown")); + pServerInfo->m_bPassword = GetBool(pServer, PASSWORD_KEY); + pServerInfo->m_bUserPass = GetBool(pServer, G_USER_PASSWORD_KEY); + pServerInfo->m_Ping = (s16)(SBServerGetPing(pServer) & 0xffff); + pServerInfo->m_ServerNumPlayers = (s16)GetInt(pServer, NUMPLAYERS_KEY, 0); + pServerInfo->m_ServerMaxPlayers = (s16)GetInt(pServer, MAXPLAYERS_KEY, 32); + xr_sprintf(pServerInfo->m_ServerUpTime, "%s", GetString(pServer, SERVER_UP_TIME_KEY, "Unknown")); + pServerInfo->m_ServerNumTeams = (s16)GetInt(pServer, NUMTEAMS_KEY, 0); + pServerInfo->m_Port = (s16)GetInt(pServer, HOSTPORT_KEY, 0); + pServerInfo->m_HPort = (s16)SBServerGetPublicQueryPort(pServer); + pServerInfo->m_bDedicated = GetBool(pServer, DEDICATED_KEY); + pServerInfo->m_GameType = (u8)GetInt(pServer, GAMETYPE_NAME_KEY, 0); + if (pServerInfo->m_GameType == 0) { + pServerInfo->m_GameType = ParseStringToGameType(pServerInfo->m_ServerGameType); + } + xr_sprintf(pServerInfo->m_ServerVersion, "%s", GetString(pServer, GAMEVER_KEY, "--")); + + //--------- Read Game Infos ---------------------------// + pServerInfo->m_aPlayers.clear(); + pServerInfo->m_aTeams.clear(); + //-------------------------------------------------------// + if (SBServerHasFullKeys(pServer) == SBFalse) return; + pServerInfo->MaxPing = GetInt(pServer, G_MAX_PING_KEY); pServerInfo->MapRotation = GetBool(pServer, G_MAP_ROTATION_KEY); pServerInfo->VotingEnabled = GetBool(pServer, G_VOTING_ENABLED_KEY); - pServerInfo->SpectratorModes = GetInt(pServer, G_SPECTATOR_MODES_KEY); + pServerInfo->SpectratorModes = GetInt(pServer, G_SPECTATOR_MODES_KEY); if (pServerInfo->m_GameType == eGameIDDeathmatch || pServerInfo->m_GameType == eGameIDTeamDeathmatch) pServerInfo->FragLimit = GetInt(pServer, G_FRAG_LIMIT_KEY); pServerInfo->TimeLimit = GetFloat(pServer, G_TIME_LIMIT_KEY); pServerInfo->DamageBlockTime = GetFloat(pServer, G_DAMAGE_BLOCK_TIME_KEY); - if (pServerInfo->DamageBlockTime!=0) + if (pServerInfo->DamageBlockTime != 0) pServerInfo->DamageBlockIndicators = GetBool(pServer, G_DAMAGE_BLOCK_INDICATOR_KEY); pServerInfo->AnomaliesEnabled = GetBool(pServer, G_ANOMALIES_ENABLED_KEY); - if (pServerInfo->AnomaliesEnabled) - pServerInfo->AnomaliesTime = GetFloat(pServer, G_ANOMALIES_TIME_KEY); + if (pServerInfo->AnomaliesEnabled) pServerInfo->AnomaliesTime = GetFloat(pServer, G_ANOMALIES_TIME_KEY); pServerInfo->ForceRespawn = GetFloat(pServer, G_FORCE_RESPAWN_KEY); pServerInfo->WarmUp = GetFloat(pServer, G_WARM_UP_TIME_KEY); - if ( pServerInfo->m_GameType == eGameIDTeamDeathmatch - || pServerInfo->m_GameType == eGameIDArtefactHunt - || pServerInfo->m_GameType == eGameIDCaptureTheArtefact) - { + if (pServerInfo->m_GameType == eGameIDTeamDeathmatch || pServerInfo->m_GameType == eGameIDArtefactHunt || + pServerInfo->m_GameType == eGameIDCaptureTheArtefact) + { pServerInfo->AutoTeamBalance = GetBool(pServer, G_AUTO_TEAM_BALANCE_KEY); pServerInfo->AutoTeamSwap = GetBool(pServer, G_AUTO_TEAM_SWAP_KEY); pServerInfo->FriendlyIndicators = GetBool(pServer, G_FRIENDLY_INDICATORS_KEY); pServerInfo->FriendlyNames = GetBool(pServer, G_FRIENDLY_NAMES_KEY); pServerInfo->FriendlyFire = GetFloat(pServer, G_FRIENDLY_FIRE_KEY); - }; + }; - if (pServerInfo->m_GameType == eGameIDArtefactHunt || - pServerInfo->m_GameType == eGameIDCaptureTheArtefact) - { + if (pServerInfo->m_GameType == eGameIDArtefactHunt || pServerInfo->m_GameType == eGameIDCaptureTheArtefact) { pServerInfo->ArtefactCount = GetInt(pServer, G_ARTEFACTS_COUNT_KEY); pServerInfo->ArtefactStayTime = GetFloat(pServer, G_ARTEFACT_STAY_TIME_KEY); pServerInfo->ArtefactRespawnTime = GetFloat(pServer, G_ARTEFACT_RESPAWN_TIME_KEY); int reinf = atoi(GetString(pServer, G_REINFORCEMENT_KEY, "0")); - switch (reinf) - { - case -1: - pServerInfo->Reinforcement = -1; - break; - case 0: - pServerInfo->Reinforcement = 0; - break; - default: - pServerInfo->Reinforcement = GetFloat(pServer, G_REINFORCEMENT_KEY); - break; - } + switch (reinf) + { + case -1: pServerInfo->Reinforcement = -1; break; + case 0: pServerInfo->Reinforcement = 0; break; + default: pServerInfo->Reinforcement = GetFloat(pServer, G_REINFORCEMENT_KEY); break; + } pServerInfo->ShieldedBases = GetBool(pServer, G_SHIELDED_BASES_KEY); pServerInfo->ReturnPlayers = GetBool(pServer, G_RETURN_PLAYERS_KEY); pServerInfo->BearerCantSprint = GetBool(pServer, G_BEARER_CANT_SPRINT_KEY); - } - //--------- Read Players Info -------------------------// - for (int i=0; im_ServerNumPlayers; i++) - { - PlayerInfo PInfo; - _snprintf_s(PInfo.Name, sizeof(PInfo.Name)-1, "%s", SBServerGetPlayerStringValueA(pServer, i, "player", "Unknown")); - PInfo.Name[sizeof(PInfo.Name)-1] = 0; - PInfo.Frags = s16(SBServerGetPlayerIntValueA(pServer, i, "score", 0)); - PInfo.Deaths = u16(SBServerGetPlayerIntValueA(pServer, i, "deaths", 0)); - PInfo.Rank = u8(SBServerGetPlayerIntValueA(pServer, i, "skill", 0)); - PInfo.Team = u8(SBServerGetPlayerIntValueA(pServer, i, "team", 0)); - PInfo.Spectator = (SBServerGetPlayerIntValueA(pServer, i, "spectator", 1)) != 0; - PInfo.Artefacts = u8(SBServerGetPlayerIntValueA(pServer, i, "artefacts", 0)); - - pServerInfo->m_aPlayers.push_back(PInfo); - }; - //----------- Read Team Info ---------------------------// - if ( pServerInfo->m_GameType == eGameIDTeamDeathmatch - || pServerInfo->m_GameType == eGameIDArtefactHunt - || pServerInfo->m_GameType == eGameIDCaptureTheArtefact - ) - { - for (int i=0; im_ServerNumTeams; i++) - { - TeamInfo TI; - TI.Score = u8(SBServerGetTeamIntValueA(pServer, i, "t_score", 0)); - pServerInfo->m_aTeams.push_back(TI); - } - } + } + //--------- Read Players Info -------------------------// + for (int i = 0; i < pServerInfo->m_ServerNumPlayers; i++) + { + PlayerInfo PInfo; + _snprintf_s( + PInfo.Name, sizeof(PInfo.Name) - 1, "%s", SBServerGetPlayerStringValueA(pServer, i, "player", "Unknown")); + PInfo.Name[sizeof(PInfo.Name) - 1] = 0; + PInfo.Frags = s16(SBServerGetPlayerIntValueA(pServer, i, "score", 0)); + PInfo.Deaths = u16(SBServerGetPlayerIntValueA(pServer, i, "deaths", 0)); + PInfo.Rank = u8(SBServerGetPlayerIntValueA(pServer, i, "skill", 0)); + PInfo.Team = u8(SBServerGetPlayerIntValueA(pServer, i, "team", 0)); + PInfo.Spectator = (SBServerGetPlayerIntValueA(pServer, i, "spectator", 1)) != 0; + PInfo.Artefacts = u8(SBServerGetPlayerIntValueA(pServer, i, "artefacts", 0)); + + pServerInfo->m_aPlayers.push_back(PInfo); + }; + //----------- Read Team Info ---------------------------// + if (pServerInfo->m_GameType == eGameIDTeamDeathmatch || pServerInfo->m_GameType == eGameIDArtefactHunt || + pServerInfo->m_GameType == eGameIDCaptureTheArtefact) + { + for (int i = 0; i < pServerInfo->m_ServerNumTeams; i++) + { + TeamInfo TI; + TI.Score = u8(SBServerGetTeamIntValueA(pServer, i, "t_score", 0)); + pServerInfo->m_aTeams.push_back(TI); + } + } }; -void CGameSpy_Browser::RefreshQuick(int Index) +void CGameSpy_Browser::RefreshQuick(int Index) { SBServer pServer = ServerBrowserGetServer(m_pGSBrowser, Index); - if (!pServer) return; - ServerInfo xServerInfo; - ReadServerInfo(&xServerInfo, pServer); - ServerBrowserAuxUpdateServer(m_pGSBrowser, pServer, SBFalse, SBTrue); + if (!pServer) return; + ServerInfo xServerInfo; + ReadServerInfo(&xServerInfo, pServer); + ServerBrowserAuxUpdateServer(m_pGSBrowser, pServer, SBFalse, SBTrue); }; -bool CGameSpy_Browser::CheckDirectConnection(int Index) +bool CGameSpy_Browser::CheckDirectConnection(int Index) { SBServer pServer = ServerBrowserGetServer(m_pGSBrowser, Index); - if (!pServer) return false; - SBBool res = SBServerDirectConnect(pServer); - return res == SBTrue; + if (!pServer) return false; + SBBool res = SBServerDirectConnect(pServer); + return res == SBTrue; }; -void CGameSpy_Browser::OnUpdateFailed (void* server) +void CGameSpy_Browser::OnUpdateFailed(void* server) { - ServerBrowserRemoveServer(m_pGSBrowser, static_cast(server)); + ServerBrowserRemoveServer(m_pGSBrowser, static_cast(server)); } GSUpdateStatus CGameSpy_Browser::Update() { ServerBrowserThink(m_pGSBrowser); - if (m_bTryingToConnectToMasterServer) - return GSUpdateStatus::ConnectingToMaster; - if (m_bShowCMSErr) - { - m_bShowCMSErr = false; + if (m_bTryingToConnectToMasterServer) return GSUpdateStatus::ConnectingToMaster; + if (m_bShowCMSErr) { + m_bShowCMSErr = false; return GSUpdateStatus::MasterUnreachable; - } + } return GSUpdateStatus::Success; }; -void CGameSpy_Browser::UpdateServerList() +void CGameSpy_Browser::UpdateServerList() { - if (onUpdate) - onUpdate(); + if (onUpdate) onUpdate(); } -void CGameSpy_Browser::SortBrowserByPing () +void CGameSpy_Browser::SortBrowserByPing() { - ServerBrowserSortA(m_pGSBrowser, SBTrue, "ping", sbcm_int); + ServerBrowserSortA(m_pGSBrowser, SBTrue, "ping", sbcm_int); } -bool CGameSpy_Browser::HasAllKeys(int Index) +bool CGameSpy_Browser::HasAllKeys(int Index) { - SBServer pServer = ServerBrowserGetServer(m_pGSBrowser, Index); - if (!pServer) return true; - ServerInfo xServerInfo; - ReadServerInfo(&xServerInfo, pServer); -// xrGS_ServerBrowserAuxUpdateServer(m_pGSBrowser, pServer, SBFalse, SBTrue); - return (SBServerHasFullKeys(pServer) == SBTrue); + SBServer pServer = ServerBrowserGetServer(m_pGSBrowser, Index); + if (!pServer) return true; + ServerInfo xServerInfo; + ReadServerInfo(&xServerInfo, pServer); + // xrGS_ServerBrowserAuxUpdateServer(m_pGSBrowser, pServer, SBFalse, SBTrue); + return (SBServerHasFullKeys(pServer) == SBTrue); }; diff --git a/src/xrGameSpy/GameSpy_Browser.h b/src/xrGameSpy/GameSpy_Browser.h index d9c6e87e673..475501ad0da 100644 --- a/src/xrGameSpy/GameSpy_Browser.h +++ b/src/xrGameSpy/GameSpy_Browser.h @@ -6,48 +6,55 @@ class CServerList; class CGameSpy_QR2; -struct GameInfo { - shared_str InfoName; - shared_str InfoData; - GameInfo(LPCSTR Name, LPCSTR Data) { InfoName._set(Name); InfoData._set(Data); }; +struct GameInfo +{ + shared_str InfoName; + shared_str InfoData; + GameInfo(LPCSTR Name, LPCSTR Data) + { + InfoName._set(Name); + InfoData._set(Data); + }; }; -struct PlayerInfo { - string128 Name; - s16 Frags; - u16 Deaths; - u8 Rank; - u8 Team; - bool Spectator; - u8 Artefacts; +struct PlayerInfo +{ + string128 Name; + s16 Frags; + u16 Deaths; + u8 Rank; + u8 Team; + bool Spectator; + u8 Artefacts; }; struct TeamInfo { - u8 Score; + u8 Score; }; -struct ServerInfo{ -// SBServer pSBServer; - string128 m_Address; - string128 m_HostName; - string128 m_ServerName; - string128 m_SessionName; - string128 m_ServerGameType; - string128 m_ServerVersion; - u32 m_GameType; - - s16 m_ServerNumPlayers; - s16 m_ServerMaxPlayers; - string128 m_ServerUpTime; - s16 m_ServerNumTeams; - bool m_bDedicated; - bool m_bFFire; - s16 m_s16FFire; - bool m_bPassword; - bool m_bUserPass; - s16 m_Ping; - s16 m_Port, m_HPort; +struct ServerInfo +{ + // SBServer pSBServer; + string128 m_Address; + string128 m_HostName; + string128 m_ServerName; + string128 m_SessionName; + string128 m_ServerGameType; + string128 m_ServerVersion; + u32 m_GameType; + + s16 m_ServerNumPlayers; + s16 m_ServerMaxPlayers; + string128 m_ServerUpTime; + s16 m_ServerNumTeams; + bool m_bDedicated; + bool m_bFFire; + s16 m_s16FFire; + bool m_bPassword; + bool m_bUserPass; + s16 m_Ping; + s16 m_Port, m_HPort; int MaxPing; bool MapRotation; bool VotingEnabled; @@ -73,18 +80,18 @@ struct ServerInfo{ bool ReturnPlayers; bool BearerCantSprint; - xr_vector m_aPlayers; - xr_vector m_aTeams; - - int Index; + xr_vector m_aPlayers; + xr_vector m_aTeams; - ServerInfo () {}; - ServerInfo (string128 NewAddress) - { - xr_strcpy(m_Address, NewAddress); - }; + int Index; - bool operator == (LPCSTR Address){int res = xr_strcmp(m_Address, Address);return res == 0;}; + ServerInfo(){}; + ServerInfo(string128 NewAddress) { xr_strcpy(m_Address, NewAddress); }; + bool operator==(LPCSTR Address) + { + int res = xr_strcmp(m_Address, Address); + return res == 0; + }; }; enum class GSUpdateStatus @@ -102,51 +109,50 @@ class XRGAMESPY_API CGameSpy_Browser { public: using UpdateCallback = fastdelegate::FastDelegate; - using DestroyCallback = fastdelegate::FastDelegate; + using DestroyCallback = fastdelegate::FastDelegate; private: -// string16 m_SecretKey; - _ServerBrowser *m_pGSBrowser; - CGameSpy_QR2* m_pQR2; + // string16 m_SecretKey; + _ServerBrowser* m_pGSBrowser; + CGameSpy_QR2* m_pQR2; UpdateCallback onUpdate; DestroyCallback onDestroy; - - void ReadServerInfo (ServerInfo* pServerInfo, void* pServer); + void ReadServerInfo(ServerInfo* pServerInfo, void* pServer); - bool m_bAbleToConnectToMasterServer; - bool m_bTryingToConnectToMasterServer; - bool m_bShowCMSErr; + bool m_bAbleToConnectToMasterServer; + bool m_bTryingToConnectToMasterServer; + bool m_bShowCMSErr; - Lock m_refresh_lock ; + Lock m_refresh_lock; public: - CGameSpy_Browser(); - ~CGameSpy_Browser(); + CGameSpy_Browser(); + ~CGameSpy_Browser(); - bool Init(UpdateCallback updateCb, DestroyCallback destroyCb); - void Clear(); + bool Init(UpdateCallback updateCb, DestroyCallback destroyCb); + void Clear(); GSUpdateStatus RefreshList_Full(bool Local, const char* FilterStr = ""); - void RefreshQuick(int Index); - bool HasAllKeys (int Index); - bool CheckDirectConnection(int Index); - - void CallBack_OnUpdateCompleted (); - - int GetServersCount(); - void GetServerInfoByIndex(ServerInfo* pServerInfo, int idx); - void *GetServerByIndex(int id); - bool GetBool(void *srv, int keyId, bool defaultValue = false); - int GetInt(void *srv, int keyId, int defaultValue = 0); - float GetFloat(void *srv, int keyId, float defaultValue = 0.0f); - const char *GetString(void *srv, int keyId, const char *defaultValue = nullptr); - - void OnUpdateFailed (void* server); + void RefreshQuick(int Index); + bool HasAllKeys(int Index); + bool CheckDirectConnection(int Index); + + void CallBack_OnUpdateCompleted(); + + int GetServersCount(); + void GetServerInfoByIndex(ServerInfo* pServerInfo, int idx); + void* GetServerByIndex(int id); + bool GetBool(void* srv, int keyId, bool defaultValue = false); + int GetInt(void* srv, int keyId, int defaultValue = 0); + float GetFloat(void* srv, int keyId, float defaultValue = 0.0f); + const char* GetString(void* srv, int keyId, const char* defaultValue = nullptr); + + void OnUpdateFailed(void* server); GSUpdateStatus Update(); - void UpdateServerList (); - void SortBrowserByPing (); + void UpdateServerList(); + void SortBrowserByPing(); - void RefreshListInternet (const char* FilterStr); + void RefreshListInternet(const char* FilterStr); }; diff --git a/src/xrGameSpy/GameSpy_Full.cpp b/src/xrGameSpy/GameSpy_Full.cpp index d646f12c4fa..14bb79c1173 100644 --- a/src/xrGameSpy/GameSpy_Full.cpp +++ b/src/xrGameSpy/GameSpy_Full.cpp @@ -1,63 +1,64 @@ -#include "StdAfx.h" #include "GameSpy_Full.h" +#include "Common/object_broker.h" +#include "GameSpy_ATLAS.h" #include "GameSpy_Available.h" -#include "GameSpy_Patching.h" -#include "GameSpy_HTTP.h" #include "GameSpy_Browser.h" #include "GameSpy_GP.h" +#include "GameSpy_HTTP.h" +#include "GameSpy_Patching.h" #include "GameSpy_SAKE.h" -#include "GameSpy_ATLAS.h" -#include "Common/object_broker.h" +#include "StdAfx.h" -CGameSpy_Full::CGameSpy_Full() +CGameSpy_Full::CGameSpy_Full() { - m_pGSA = NULL; - m_pGS_Patching = NULL; - m_pGS_HTTP = NULL; - m_pGS_SB = NULL; - m_pGS_GP = NULL; - m_bServicesAlreadyChecked = false; - //--------------------------------------- - m_pGSA = new CGameSpy_Available(); - //----------------------------------------------------- - shared_str resultstr; - m_bServicesAlreadyChecked = m_pGSA->CheckAvailableServices(resultstr); - //----------------------------------------------------- - gsCoreInitialize(); - m_pGS_Patching = new CGameSpy_Patching(); - m_pGS_HTTP = new CGameSpy_HTTP(); - m_pGS_SB = new CGameSpy_Browser(); - m_pGS_GP = new CGameSpy_GP(); - m_pGS_SAKE = new CGameSpy_SAKE(); - m_pGS_ATLAS = new CGameSpy_ATLAS(); + m_pGSA = NULL; + m_pGS_Patching = NULL; + m_pGS_HTTP = NULL; + m_pGS_SB = NULL; + m_pGS_GP = NULL; + m_bServicesAlreadyChecked = false; + //--------------------------------------- + m_pGSA = new CGameSpy_Available(); + //----------------------------------------------------- + shared_str resultstr; + m_bServicesAlreadyChecked = m_pGSA->CheckAvailableServices(resultstr); + //----------------------------------------------------- + gsCoreInitialize(); + m_pGS_Patching = new CGameSpy_Patching(); + m_pGS_HTTP = new CGameSpy_HTTP(); + m_pGS_SB = new CGameSpy_Browser(); + m_pGS_GP = new CGameSpy_GP(); + m_pGS_SAKE = new CGameSpy_SAKE(); + m_pGS_ATLAS = new CGameSpy_ATLAS(); } CGameSpy_Full::~CGameSpy_Full() { - delete_data (m_pGSA); - delete_data (m_pGS_Patching); - delete_data (m_pGS_HTTP); - delete_data (m_pGS_SB); - delete_data (m_pGS_GP); - delete_data (m_pGS_SAKE); - delete_data (m_pGS_ATLAS); - gsCoreShutdown(); + delete_data(m_pGSA); + delete_data(m_pGS_Patching); + delete_data(m_pGS_HTTP); + delete_data(m_pGS_SB); + delete_data(m_pGS_GP); + delete_data(m_pGS_SAKE); + delete_data(m_pGS_ATLAS); + gsCoreShutdown(); } GSUpdateStatus CGameSpy_Full::Update() { - if (!m_bServicesAlreadyChecked) - { - m_bServicesAlreadyChecked = true; + if (!m_bServicesAlreadyChecked) { + m_bServicesAlreadyChecked = true; return GSUpdateStatus::OutOfService; - } - m_pGS_HTTP->Think (); + } + m_pGS_HTTP->Think(); GSUpdateStatus status = m_pGS_SB->Update(); - m_pGS_GP->Think (); - CoreThink (15); - m_pGS_ATLAS->Think (); + m_pGS_GP->Think(); + CoreThink(15); + m_pGS_ATLAS->Think(); return status; } void CGameSpy_Full::CoreThink(u32 millisecondsTimeout) -{ gsCoreThink(millisecondsTimeout); } +{ + gsCoreThink(millisecondsTimeout); +} diff --git a/src/xrGameSpy/GameSpy_Full.h b/src/xrGameSpy/GameSpy_Full.h index f95f01c796d..11b2282f9c2 100644 --- a/src/xrGameSpy/GameSpy_Full.h +++ b/src/xrGameSpy/GameSpy_Full.h @@ -14,28 +14,28 @@ class CGameSpy_ATLAS; class XRGAMESPY_API CGameSpy_Full { - bool m_bServicesAlreadyChecked; -public: - CGameSpy_Full (); - ~CGameSpy_Full (); + bool m_bServicesAlreadyChecked; - CGameSpy_Available* GetGameSpyAvailable () const { return m_pGSA; }; - CGameSpy_Patching* GetGameSpyPatching () const { return m_pGS_Patching; }; - CGameSpy_HTTP* GetGameSpyHTTP () const { return m_pGS_HTTP; }; - CGameSpy_Browser* GetGameSpyBrowser () const { return m_pGS_SB; }; - CGameSpy_GP* GetGameSpyGP () const { return m_pGS_GP; }; - CGameSpy_SAKE* GetGameSpySAKE () const { return m_pGS_SAKE; }; - CGameSpy_ATLAS* GetGameSpyATLAS () const { return m_pGS_ATLAS; }; +public: + CGameSpy_Full(); + ~CGameSpy_Full(); + CGameSpy_Available* GetGameSpyAvailable() const { return m_pGSA; }; + CGameSpy_Patching* GetGameSpyPatching() const { return m_pGS_Patching; }; + CGameSpy_HTTP* GetGameSpyHTTP() const { return m_pGS_HTTP; }; + CGameSpy_Browser* GetGameSpyBrowser() const { return m_pGS_SB; }; + CGameSpy_GP* GetGameSpyGP() const { return m_pGS_GP; }; + CGameSpy_SAKE* GetGameSpySAKE() const { return m_pGS_SAKE; }; + CGameSpy_ATLAS* GetGameSpyATLAS() const { return m_pGS_ATLAS; }; GSUpdateStatus Update(); void CoreThink(u32 millisecondsTimeout); private: - CGameSpy_Available* m_pGSA; - CGameSpy_Patching* m_pGS_Patching; - CGameSpy_HTTP* m_pGS_HTTP; - CGameSpy_Browser* m_pGS_SB; - CGameSpy_GP* m_pGS_GP; - CGameSpy_SAKE* m_pGS_SAKE; - CGameSpy_ATLAS* m_pGS_ATLAS; + CGameSpy_Available* m_pGSA; + CGameSpy_Patching* m_pGS_Patching; + CGameSpy_HTTP* m_pGS_HTTP; + CGameSpy_Browser* m_pGS_SB; + CGameSpy_GP* m_pGS_GP; + CGameSpy_SAKE* m_pGS_SAKE; + CGameSpy_ATLAS* m_pGS_ATLAS; }; diff --git a/src/xrGameSpy/GameSpy_GCD_Client.cpp b/src/xrGameSpy/GameSpy_GCD_Client.cpp index d74b817febf..6e06f3a1baf 100644 --- a/src/xrGameSpy/GameSpy_GCD_Client.cpp +++ b/src/xrGameSpy/GameSpy_GCD_Client.cpp @@ -1,8 +1,8 @@ -#include "StdAfx.h" #include "GameSpy_GCD_Client.h" +#include "StdAfx.h" -void CGameSpy_GCD_Client::CreateRespond(char *cdkey, char* RespondStr, char* ChallengeStr, u8 Reauth) +void CGameSpy_GCD_Client::CreateRespond(char* cdkey, char* RespondStr, char* ChallengeStr, u8 Reauth) { - gcd_compute_response(_strupr(cdkey), ChallengeStr, RespondStr, - Reauth==1 ? CDResponseMethod_REAUTH : CDResponseMethod_NEWAUTH); + gcd_compute_response( + _strupr(cdkey), ChallengeStr, RespondStr, Reauth == 1 ? CDResponseMethod_REAUTH : CDResponseMethod_NEWAUTH); } diff --git a/src/xrGameSpy/GameSpy_GCD_Client.h b/src/xrGameSpy/GameSpy_GCD_Client.h index 85a796042fa..aa9da658a6f 100644 --- a/src/xrGameSpy/GameSpy_GCD_Client.h +++ b/src/xrGameSpy/GameSpy_GCD_Client.h @@ -6,5 +6,5 @@ class XRGAMESPY_API CGameSpy_GCD_Client { public: - void CreateRespond(char *cdkey, char *RespondStr, char *ChallengeStr, u8 Reauth); + void CreateRespond(char* cdkey, char* RespondStr, char* ChallengeStr, u8 Reauth); }; diff --git a/src/xrGameSpy/GameSpy_GCD_Server.cpp b/src/xrGameSpy/GameSpy_GCD_Server.cpp index 22872b30289..41aef323586 100644 --- a/src/xrGameSpy/GameSpy_GCD_Server.cpp +++ b/src/xrGameSpy/GameSpy_GCD_Server.cpp @@ -1,33 +1,32 @@ -#include "StdAfx.h" #include "GameSpy_GCD_Server.h" +#include "StdAfx.h" -bool CGameSpy_GCD_Server::Init() +bool CGameSpy_GCD_Server::Init() { - int res = gcd_init_qr2(NULL, GAMESPY_GAMEID); - if (res == -1) - { - Msg("! xrGS::CDKey : Failes to Initialize!"); - return false; - }; + int res = gcd_init_qr2(NULL, GAMESPY_GAMEID); + if (res == -1) { + Msg("! xrGS::CDKey : Failes to Initialize!"); + return false; + }; #ifndef MASTER_GOLD - Msg("- xrGS::CDKey : Initialized"); -#endif // #ifndef MASTER_GOLD - return true; + Msg("- xrGS::CDKey : Initialized"); +#endif // #ifndef MASTER_GOLD + return true; }; -void CGameSpy_GCD_Server::ShutDown() +void CGameSpy_GCD_Server::ShutDown() { gcd_shutdown(); } -void CGameSpy_GCD_Server::CreateRandomChallenge(char* challenge, int nchars) +void CGameSpy_GCD_Server::CreateRandomChallenge(char* challenge, int nchars) { - if (nchars > GAMESPY_MAXCHALLANGESIZE) nchars = GAMESPY_MAXCHALLANGESIZE; - challenge[nchars] = 0; - while (nchars--) - { - challenge[nchars] = char('a' + ::Random.randI(26)); - }; + if (nchars > GAMESPY_MAXCHALLANGESIZE) nchars = GAMESPY_MAXCHALLANGESIZE; + challenge[nchars] = 0; + while (nchars--) + { + challenge[nchars] = char('a' + ::Random.randI(26)); + }; } class GSAuthContext @@ -36,53 +35,49 @@ class GSAuthContext using ClientAuthCallback = CGameSpy_GCD_Server::ClientAuthCallback; using ClientReauthCallback = CGameSpy_GCD_Server::ClientReauthCallback; - CGameSpy_GCD_Server::ClientAuthCallback &Auth; - CGameSpy_GCD_Server::ClientReauthCallback &Reauth; + CGameSpy_GCD_Server::ClientAuthCallback& Auth; + CGameSpy_GCD_Server::ClientReauthCallback& Reauth; - GSAuthContext(ClientAuthCallback &auth, ClientReauthCallback &reauth) : - Auth(auth), Reauth(reauth) - {} + GSAuthContext(ClientAuthCallback& auth, ClientReauthCallback& reauth) : Auth(auth), Reauth(reauth) {} }; //--------------------------- CD Key callbacks ----------------------------------- -void __cdecl GSClientAuthCallback(int productid, int localid, int authenticated, char *errmsg, void *instance) +void __cdecl GSClientAuthCallback(int productid, int localid, int authenticated, char* errmsg, void* instance) { auto ctx = static_cast(instance); - if (ctx) - ctx->Auth(localid, authenticated, errmsg); + if (ctx) ctx->Auth(localid, authenticated, errmsg); }; -void __cdecl GSClientReauthCallback(int gameid, int localid, int hint, char *challenge, void *instance) +void __cdecl GSClientReauthCallback(int gameid, int localid, int hint, char* challenge, void* instance) { auto ctx = static_cast(instance); - if (ctx) - ctx->Reauth(localid, hint, challenge); + if (ctx) ctx->Reauth(localid, hint, challenge); }; -void CGameSpy_GCD_Server::AuthUser(int localid, u32 userip, char *challenge, char *response, - ClientAuthCallback &authCallback, ClientReauthCallback &reauthCallback) +void CGameSpy_GCD_Server::AuthUser(int localid, u32 userip, char* challenge, char* response, + ClientAuthCallback& authCallback, ClientReauthCallback& reauthCallback) { GSAuthContext ctx(authCallback, reauthCallback); - gcd_authenticate_user(GAMESPY_GAMEID, localid, userip, challenge, response, - GSClientAuthCallback, GSClientReauthCallback, &ctx); + gcd_authenticate_user( + GAMESPY_GAMEID, localid, userip, challenge, response, GSClientAuthCallback, GSClientReauthCallback, &ctx); }; -void CGameSpy_GCD_Server::ReAuthUser(int localid, int hint,char *response) +void CGameSpy_GCD_Server::ReAuthUser(int localid, int hint, char* response) { - gcd_process_reauth(GAMESPY_GAMEID, localid, hint, response); + gcd_process_reauth(GAMESPY_GAMEID, localid, hint, response); }; -void CGameSpy_GCD_Server::DisconnectUser(int localid) +void CGameSpy_GCD_Server::DisconnectUser(int localid) { - gcd_disconnect_user(GAMESPY_GAMEID, localid); + gcd_disconnect_user(GAMESPY_GAMEID, localid); }; -void CGameSpy_GCD_Server::Think() +void CGameSpy_GCD_Server::Think() { gcd_think(); }; -char* CGameSpy_GCD_Server::GetKeyHash(int localid) +char* CGameSpy_GCD_Server::GetKeyHash(int localid) { - return gcd_getkeyhash(GAMESPY_GAMEID, localid); + return gcd_getkeyhash(GAMESPY_GAMEID, localid); }; \ No newline at end of file diff --git a/src/xrGameSpy/GameSpy_GCD_Server.h b/src/xrGameSpy/GameSpy_GCD_Server.h index d5841ca9879..b7cb7eca4bd 100644 --- a/src/xrGameSpy/GameSpy_GCD_Server.h +++ b/src/xrGameSpy/GameSpy_GCD_Server.h @@ -3,20 +3,20 @@ #include "xrCore/xrCore.h" #include "xrGameSpy/xrGameSpy.h" -#define GAMESPY_MAXCHALLANGESIZE 32 +#define GAMESPY_MAXCHALLANGESIZE 32 class XRGAMESPY_API CGameSpy_GCD_Server { public: - using ClientAuthCallback = fastdelegate::FastDelegate; - using ClientReauthCallback = fastdelegate::FastDelegate; - bool Init(); - void ShutDown(); - void CreateRandomChallenge(char* challenge, int nchars); - void AuthUser(int localid, u32 userip, char *challenge, char *response, - ClientAuthCallback &authCallback, ClientReauthCallback &reauthCallback); - void ReAuthUser(int localid, int hint, char *response); - void DisconnectUser(int localid); - void Think(); - char* GetKeyHash(int localid); + using ClientAuthCallback = fastdelegate::FastDelegate; + using ClientReauthCallback = fastdelegate::FastDelegate; + bool Init(); + void ShutDown(); + void CreateRandomChallenge(char* challenge, int nchars); + void AuthUser(int localid, u32 userip, char* challenge, char* response, ClientAuthCallback& authCallback, + ClientReauthCallback& reauthCallback); + void ReAuthUser(int localid, int hint, char* response); + void DisconnectUser(int localid); + void Think(); + char* GetKeyHash(int localid); }; diff --git a/src/xrGameSpy/GameSpy_GP.cpp b/src/xrGameSpy/GameSpy_GP.cpp index f0bf25289fc..29db945d3de 100644 --- a/src/xrGameSpy/GameSpy_GP.cpp +++ b/src/xrGameSpy/GameSpy_GP.cpp @@ -1,220 +1,134 @@ -#include "stdafx.h" #include "GameSpy_GP.h" +#include "stdafx.h" -shared_str CGameSpy_GP::TryToTranslate(GPResult const & res) -{ - VERIFY(res != GP_NO_ERROR); - LPCSTR tmp_string = NULL; - switch (res) - { - case GP_MEMORY_ERROR: - { - STRCONCAT(tmp_string, "mp_gp_memory_error"); - }break; - case GP_PARAMETER_ERROR: - { - STRCONCAT(tmp_string, "mp_gp_parameter_error"); - }break; - case GP_NETWORK_ERROR: - { - STRCONCAT(tmp_string, "mp_gp_network_error"); - }break; - case GP_SERVER_ERROR: - { - STRCONCAT(tmp_string, "mp_gp_server_error"); - } - default: - { - string16 digit_dest; - _itoa_s(res, digit_dest, 10); - STRCONCAT( - tmp_string, - "mp_gp_unknown_error_", - digit_dest - ); - } - } - return tmp_string; +shared_str CGameSpy_GP::TryToTranslate(GPResult const& res) +{ + VERIFY(res != GP_NO_ERROR); + LPCSTR tmp_string = NULL; + switch (res) + { + case GP_MEMORY_ERROR: { STRCONCAT(tmp_string, "mp_gp_memory_error"); + } + break; + case GP_PARAMETER_ERROR: { STRCONCAT(tmp_string, "mp_gp_parameter_error"); + } + break; + case GP_NETWORK_ERROR: { STRCONCAT(tmp_string, "mp_gp_network_error"); + } + break; + case GP_SERVER_ERROR: { STRCONCAT(tmp_string, "mp_gp_server_error"); + } + default: + { + string16 digit_dest; + _itoa_s(res, digit_dest, 10); + STRCONCAT(tmp_string, "mp_gp_unknown_error_", digit_dest); + } + } + return tmp_string; } CGameSpy_GP::CGameSpy_GP() { - m_GPConnection = NULL; //GPConnection type is: void* - Init (); + m_GPConnection = NULL; // GPConnection type is: void* + Init(); } CGameSpy_GP::~CGameSpy_GP() { - ShutDown (); + ShutDown(); } bool CGameSpy_GP::Init() { - GPResult init_res = gpInitialize(&m_GPConnection, - GAMESPY_PRODUCTID, GAMESPY_GP_NAMESPACE_ID, GP_PARTNERID_GAMESPY); - VERIFY2(init_res == GP_NO_ERROR, "GameSpy GP: failed to initialize"); - if (init_res != GP_NO_ERROR) - { - Msg("! GameSpy GP: failed to initialize, error code: %d", init_res); - return false; - } - gpSetCallback(&m_GPConnection, GP_ERROR, &CGameSpy_GP::OnGameSpyErrorCb, this); - return true; + GPResult init_res = gpInitialize(&m_GPConnection, GAMESPY_PRODUCTID, GAMESPY_GP_NAMESPACE_ID, GP_PARTNERID_GAMESPY); + VERIFY2(init_res == GP_NO_ERROR, "GameSpy GP: failed to initialize"); + if (init_res != GP_NO_ERROR) { + Msg("! GameSpy GP: failed to initialize, error code: %d", init_res); + return false; + } + gpSetCallback(&m_GPConnection, GP_ERROR, &CGameSpy_GP::OnGameSpyErrorCb, this); + return true; } void CGameSpy_GP::Think() { - if (!m_GPConnection) - { - Msg("! GameSpy GP ERROR: GameSpy GP connection not ititialized"); - return; - } - GPResult process_res = gpProcess(&m_GPConnection); - if (process_res != GP_NO_ERROR) - { - Msg("! GameSpy GP ERROR: process failed: %d", process_res); - } + if (!m_GPConnection) { + Msg("! GameSpy GP ERROR: GameSpy GP connection not ititialized"); + return; + } + GPResult process_res = gpProcess(&m_GPConnection); + if (process_res != GP_NO_ERROR) { + Msg("! GameSpy GP ERROR: process failed: %d", process_res); + } } void CGameSpy_GP::ShutDown() { - if (m_GPConnection) - gpDestroy(&m_GPConnection); -} - -GPResult CGameSpy_GP::NewUser(shared_str const & nick, - shared_str const & unique_nick, - shared_str const & email, - shared_str const & password, - GPCallback callback, - void * param) -{ - return gpNewUserA( - &m_GPConnection, - nick.c_str(), - unique_nick.c_str(), - email.c_str(), - password.c_str(), - NULL, - GP_NON_BLOCKING, - callback, - param - ); -} - -GPResult CGameSpy_GP::ProfileSearch(shared_str const & nick, - shared_str const & unique_nick, - shared_str const & email, - GPCallback callback, - void * param) -{ - return gpProfileSearchA( - &m_GPConnection, - nick.c_str(), - unique_nick.c_str(), - email.c_str(), - NULL, - NULL, - 0, - GP_NON_BLOCKING, - callback, - param - ); -} - -GPResult CGameSpy_GP::GetUserNicks(shared_str const & email, - shared_str const & password, - GPCallback callback, - void * param) -{ - return gpGetUserNicksA( - &m_GPConnection, - email.c_str(), - password.c_str(), - GP_NON_BLOCKING, - callback, - param - ); -} - -GPResult CGameSpy_GP::SuggestUNicks(shared_str const & desired_unick, - GPCallback callback, - void * param) -{ - return gpSuggestUniqueNickA( - &m_GPConnection, - desired_unick.c_str(), - GP_NON_BLOCKING, - callback, - param - ); -} - -GPResult CGameSpy_GP::DeleteProfile(GPCallback callback, - void * param) -{ - return gpDeleteProfile(&m_GPConnection, callback, param); -} - - -GPResult CGameSpy_GP::Connect(shared_str const & email, - shared_str const & nick, - shared_str const & password, - GPCallback callback, - void * param) -{ - return gpConnectA( - &m_GPConnection, - nick.c_str(), - email.c_str(), - password.c_str(), - GP_FIREWALL, - GP_NON_BLOCKING, - callback, - param - ); + if (m_GPConnection) gpDestroy(&m_GPConnection); +} + +GPResult CGameSpy_GP::NewUser(shared_str const& nick, shared_str const& unique_nick, shared_str const& email, + shared_str const& password, GPCallback callback, void* param) +{ + return gpNewUserA(&m_GPConnection, nick.c_str(), unique_nick.c_str(), email.c_str(), password.c_str(), NULL, + GP_NON_BLOCKING, callback, param); +} + +GPResult CGameSpy_GP::ProfileSearch( + shared_str const& nick, shared_str const& unique_nick, shared_str const& email, GPCallback callback, void* param) +{ + return gpProfileSearchA(&m_GPConnection, nick.c_str(), unique_nick.c_str(), email.c_str(), NULL, NULL, 0, + GP_NON_BLOCKING, callback, param); +} + +GPResult CGameSpy_GP::GetUserNicks( + shared_str const& email, shared_str const& password, GPCallback callback, void* param) +{ + return gpGetUserNicksA(&m_GPConnection, email.c_str(), password.c_str(), GP_NON_BLOCKING, callback, param); +} + +GPResult CGameSpy_GP::SuggestUNicks(shared_str const& desired_unick, GPCallback callback, void* param) +{ + return gpSuggestUniqueNickA(&m_GPConnection, desired_unick.c_str(), GP_NON_BLOCKING, callback, param); +} + +GPResult CGameSpy_GP::DeleteProfile(GPCallback callback, void* param) +{ + return gpDeleteProfile(&m_GPConnection, callback, param); +} + +GPResult CGameSpy_GP::Connect( + shared_str const& email, shared_str const& nick, shared_str const& password, GPCallback callback, void* param) +{ + return gpConnectA( + &m_GPConnection, nick.c_str(), email.c_str(), password.c_str(), GP_FIREWALL, GP_NON_BLOCKING, callback, param); } void CGameSpy_GP::Disconnect() { - gpDisconnect(&m_GPConnection); + gpDisconnect(&m_GPConnection); } GPResult CGameSpy_GP::GetLoginTicket(char loginTicket[GP_LOGIN_TICKET_LEN]) { - return gpGetLoginTicket(&m_GPConnection, loginTicket); -} - -GPResult CGameSpy_GP::SetUniqueNick(shared_str const & unique_nick, - GPCallback callback, - void * param) -{ - VERIFY(unique_nick.size() < GP_UNIQUENICK_LEN); - return gpRegisterUniqueNickA( - &m_GPConnection, - unique_nick.c_str(), - NULL, - GP_NON_BLOCKING, - callback, - param - ); -} - -void __cdecl CGameSpy_GP::OnGameSpyErrorCb(GPConnection * connection, - void * arg, - void * param) -{ - GPErrorArg* earg = static_cast(arg); - VERIFY(earg); - char const * error_descr = earg->errorString ? earg->errorString : "unknown"; - if (earg->fatal) - { - Msg("! GameSpy FATAL GP ERROR: error code: %d, description: %s", - earg->errorCode, - error_descr); - return; - } - Msg("! GameSpy GP ERROR: error code: %d, description: %s", - earg->errorCode, - error_descr); + return gpGetLoginTicket(&m_GPConnection, loginTicket); +} + +GPResult CGameSpy_GP::SetUniqueNick(shared_str const& unique_nick, GPCallback callback, void* param) +{ + VERIFY(unique_nick.size() < GP_UNIQUENICK_LEN); + return gpRegisterUniqueNickA(&m_GPConnection, unique_nick.c_str(), NULL, GP_NON_BLOCKING, callback, param); +} + +void __cdecl CGameSpy_GP::OnGameSpyErrorCb(GPConnection* connection, void* arg, void* param) +{ + GPErrorArg* earg = static_cast(arg); + VERIFY(earg); + char const* error_descr = earg->errorString ? earg->errorString : "unknown"; + if (earg->fatal) { + Msg("! GameSpy FATAL GP ERROR: error code: %d, description: %s", earg->errorCode, error_descr); + return; + } + Msg("! GameSpy GP ERROR: error code: %d, description: %s", earg->errorCode, error_descr); } diff --git a/src/xrGameSpy/GameSpy_GP.h b/src/xrGameSpy/GameSpy_GP.h index b5ee81666d0..dac934e1e1f 100644 --- a/src/xrGameSpy/GameSpy_GP.h +++ b/src/xrGameSpy/GameSpy_GP.h @@ -7,53 +7,34 @@ class XRGAMESPY_API CGameSpy_GP { public: - CGameSpy_GP (); - ~CGameSpy_GP (); - - bool Init (); - void ShutDown (); - - void Think (); - - //public wrappers to API functions - GPResult NewUser (shared_str const & nick, - shared_str const & unique_nick, - shared_str const & email, - shared_str const & password, - GPCallback callback, - void * param); - GPResult GetUserNicks (shared_str const & email, - shared_str const & password, - GPCallback callback, - void * param); - GPResult Connect (shared_str const & email, - shared_str const & nick, - shared_str const & password, - GPCallback callback, - void * param); - void Disconnect (); - - GPResult ProfileSearch (shared_str const & nick, - shared_str const & unique_nick, - shared_str const & email, - GPCallback callback, - void * param); - GPResult SuggestUNicks (shared_str const & desired_unick, - GPCallback callback, - void * param); - GPResult DeleteProfile (GPCallback callback, - void * param); - GPResult GetLoginTicket (char loginTicket[GP_LOGIN_TICKET_LEN]); - GPResult SetUniqueNick (shared_str const & unique_nick, - GPCallback callback, - void * param); - static shared_str TryToTranslate (GPResult const & res); + CGameSpy_GP(); + ~CGameSpy_GP(); + + bool Init(); + void ShutDown(); + + void Think(); + + // public wrappers to API functions + GPResult NewUser(shared_str const& nick, shared_str const& unique_nick, shared_str const& email, + shared_str const& password, GPCallback callback, void* param); + GPResult GetUserNicks(shared_str const& email, shared_str const& password, GPCallback callback, void* param); + GPResult Connect( + shared_str const& email, shared_str const& nick, shared_str const& password, GPCallback callback, void* param); + void Disconnect(); + + GPResult ProfileSearch(shared_str const& nick, shared_str const& unique_nick, shared_str const& email, + GPCallback callback, void* param); + GPResult SuggestUNicks(shared_str const& desired_unick, GPCallback callback, void* param); + GPResult DeleteProfile(GPCallback callback, void* param); + GPResult GetLoginTicket(char loginTicket[GP_LOGIN_TICKET_LEN]); + GPResult SetUniqueNick(shared_str const& unique_nick, GPCallback callback, void* param); + static shared_str TryToTranslate(GPResult const& res); + private: - GPConnection m_GPConnection; - //main callbacks - static void __cdecl OnGameSpyErrorCb (GPConnection * connection, - void * arg, - void * param); -}; //CGameSpy_GP - -#endif //#ifndef GAMESPY_GP_H + GPConnection m_GPConnection; + // main callbacks + static void __cdecl OnGameSpyErrorCb(GPConnection* connection, void* arg, void* param); +}; // CGameSpy_GP + +#endif //#ifndef GAMESPY_GP_H diff --git a/src/xrGameSpy/GameSpy_HTTP.cpp b/src/xrGameSpy/GameSpy_HTTP.cpp index adf12575f70..7c7ec1cbd48 100644 --- a/src/xrGameSpy/GameSpy_HTTP.cpp +++ b/src/xrGameSpy/GameSpy_HTTP.cpp @@ -1,52 +1,52 @@ -#include "StdAfx.h" #include "GameSpy_HTTP.h" +#include "StdAfx.h" CGameSpy_HTTP::CGameSpy_HTTP() { - m_LastRequest = -1; - StartUp(); + m_LastRequest = -1; + StartUp(); }; CGameSpy_HTTP::~CGameSpy_HTTP() { - CleanUp(); + CleanUp(); } -void CGameSpy_HTTP::StartUp () +void CGameSpy_HTTP::StartUp() { - ghttpStartup(); + ghttpStartup(); } -void CGameSpy_HTTP::CleanUp () +void CGameSpy_HTTP::CleanUp() { ghttpCleanup(); } -void CGameSpy_HTTP::Think () +void CGameSpy_HTTP::Think() { ghttpThink(); } -string128 GHTTPResultStr [] = { - "GHTTPSuccess", // 0: Successfully retrieved file. - "GHTTPOutOfMemory", // 1: A memory allocation failed. - "GHTTPBufferOverflow", // 2: The user-supplied buffer was too small to hold the file. - "GHTTPParseURLFailed", // 3: There was an error parsing the URL. - "GHTTPHostLookupFailed", // 4: Failed looking up the hostname. - "GHTTPSocketFailed", // 5: Failed to create/initialize/read/write a socket. - "GHTTPConnectFailed", // 6: Failed connecting to the http server. - "GHTTPBadResponse", // 7: Error understanding a response from the server. - "GHTTPRequestRejected", // 8: The request has been rejected by the server. - "GHTTPUnauthorized", // 9: Not authorized to get the file. - "GHTTPForbidden", // 10: The server has refused to send the file. - "GHTTPFileNotFound", // 11: Failed to find the file on the server. - "GHTTPServerError", // 12: The server has encountered an internal error. - "GHTTPFileWriteFailed", // 13: An error occured writing to the local file (for ghttpSaveFile[Ex]). - "GHTTPFileReadFailed", // 14: There was an error reading from a local file (for posting files from disk). - "GHTTPFileIncomplete", // 15: Download started but was interrupted. Only reported if file size is known. - "GHTTPFileToBig", // 16: The file is to big to be downloaded (size exceeds range of interal data types) - "GHTTPEncryptionError", // 17: Error with encryption engine. - "GHTTPRequestCancelled" // 18: User requested cancel and/or graceful close. +string128 GHTTPResultStr[] = { + "GHTTPSuccess", // 0: Successfully retrieved file. + "GHTTPOutOfMemory", // 1: A memory allocation failed. + "GHTTPBufferOverflow", // 2: The user-supplied buffer was too small to hold the file. + "GHTTPParseURLFailed", // 3: There was an error parsing the URL. + "GHTTPHostLookupFailed", // 4: Failed looking up the hostname. + "GHTTPSocketFailed", // 5: Failed to create/initialize/read/write a socket. + "GHTTPConnectFailed", // 6: Failed connecting to the http server. + "GHTTPBadResponse", // 7: Error understanding a response from the server. + "GHTTPRequestRejected", // 8: The request has been rejected by the server. + "GHTTPUnauthorized", // 9: Not authorized to get the file. + "GHTTPForbidden", // 10: The server has refused to send the file. + "GHTTPFileNotFound", // 11: Failed to find the file on the server. + "GHTTPServerError", // 12: The server has encountered an internal error. + "GHTTPFileWriteFailed", // 13: An error occured writing to the local file (for ghttpSaveFile[Ex]). + "GHTTPFileReadFailed", // 14: There was an error reading from a local file (for posting files from disk). + "GHTTPFileIncomplete", // 15: Download started but was interrupted. Only reported if file size is known. + "GHTTPFileToBig", // 16: The file is to big to be downloaded (size exceeds range of interal data types) + "GHTTPEncryptionError", // 17: Error with encryption engine. + "GHTTPRequestCancelled" // 18: User requested cancel and/or graceful close. }; class DownloadContext @@ -54,59 +54,55 @@ class DownloadContext public: using CompletionCallback = CGameSpy_HTTP::CompletionCallback; using ProgressCallback = CGameSpy_HTTP::ProgressCallback; - - CompletionCallback &Completed; - ProgressCallback &Progress; - DownloadContext(CompletionCallback &completed, ProgressCallback &progress) : - Completed(completed), Progress(progress) - {} + CompletionCallback& Completed; + ProgressCallback& Progress; + + DownloadContext(CompletionCallback& completed, ProgressCallback& progress) + : Completed(completed), Progress(progress) + { + } }; -void __cdecl ProgressHandler(GHTTPRequest request, GHTTPState state, const char *buffer, - GHTTPByteCount bufferLen, GHTTPByteCount received, GHTTPByteCount total, void *param) +void __cdecl ProgressHandler(GHTTPRequest request, GHTTPState state, const char* buffer, GHTTPByteCount bufferLen, + GHTTPByteCount received, GHTTPByteCount total, void* param) { auto ctx = static_cast(param); - if (state==GHTTPReceivingFile && total) - ctx->Progress(received, total); + if (state == GHTTPReceivingFile && total) ctx->Progress(received, total); } -GHTTPBool __cdecl CompletedHandler(GHTTPRequest request, GHTTPResult result, - char *buffer, GHTTPByteCount bufferLen, void *param) +GHTTPBool __cdecl CompletedHandler( + GHTTPRequest request, GHTTPResult result, char* buffer, GHTTPByteCount bufferLen, void* param) { auto ctx = static_cast(param); - switch (result) - { - case GHTTPSuccess: - ctx->Completed(true); - break; - default: - Msg ("! CompletedCallBack Result - %s", GHTTPResultStr[result]); + switch (result) + { + case GHTTPSuccess: ctx->Completed(true); break; + default: + Msg("! CompletedCallBack Result - %s", GHTTPResultStr[result]); ctx->Completed(false); - break; - } - -// CGameSpy_HTTP* pGSHTTP = (CGameSpy_HTTP*) param; -// if (pGSHTTP) pGSHTTP->StopDownload(); - return GHTTPTrue; + break; + } + + // CGameSpy_HTTP* pGSHTTP = (CGameSpy_HTTP*) param; + // if (pGSHTTP) pGSHTTP->StopDownload(); + return GHTTPTrue; } -void CGameSpy_HTTP::DownloadFile(LPCSTR URL, LPCSTR FileName, - CompletionCallback &completed, ProgressCallback &progress) -{ +void CGameSpy_HTTP::DownloadFile(LPCSTR URL, LPCSTR FileName, CompletionCallback& completed, ProgressCallback& progress) +{ DownloadContext ctx(completed, progress); -// GHTTPRequest res = xrGS_ghttpSaveA(URL, FileName, GHTTPFalse, CompletedCallBack, this); - Msg ("URL: %s",URL); - Msg ("File: %s",FileName); - m_LastRequest = ghttpSaveExA(URL, FileName, "", NULL, GHTTPFalse, GHTTPFalse, ProgressHandler, CompletedHandler, &ctx); - Msg ("Code: %d",m_LastRequest); - if (m_LastRequest < 0) - completed(false); + // GHTTPRequest res = xrGS_ghttpSaveA(URL, FileName, GHTTPFalse, CompletedCallBack, this); + Msg("URL: %s", URL); + Msg("File: %s", FileName); + m_LastRequest = + ghttpSaveExA(URL, FileName, "", NULL, GHTTPFalse, GHTTPFalse, ProgressHandler, CompletedHandler, &ctx); + Msg("Code: %d", m_LastRequest); + if (m_LastRequest < 0) completed(false); } -void CGameSpy_HTTP::StopDownload () +void CGameSpy_HTTP::StopDownload() { - if (m_LastRequest != -1) - ghttpCancelRequest(m_LastRequest); - m_LastRequest = -1; + if (m_LastRequest != -1) ghttpCancelRequest(m_LastRequest); + m_LastRequest = -1; } diff --git a/src/xrGameSpy/GameSpy_HTTP.h b/src/xrGameSpy/GameSpy_HTTP.h index a0d03f477c0..8a10f6af7b4 100644 --- a/src/xrGameSpy/GameSpy_HTTP.h +++ b/src/xrGameSpy/GameSpy_HTTP.h @@ -9,16 +9,16 @@ class XRGAMESPY_API CGameSpy_HTTP using CompletionCallback = fastdelegate::FastDelegate; using ProgressCallback = fastdelegate::FastDelegate; - CGameSpy_HTTP(); - ~CGameSpy_HTTP(); + CGameSpy_HTTP(); + ~CGameSpy_HTTP(); - void StartUp (); - void CleanUp (); + void StartUp(); + void CleanUp(); + + void DownloadFile(LPCSTR URL, LPCSTR FileName, CompletionCallback& completed, ProgressCallback& progress); + void StopDownload(); + void Think(); - void DownloadFile (LPCSTR URL, LPCSTR FileName, CompletionCallback &completed, ProgressCallback &progress); - void StopDownload (); - void Think (); - private: - GHTTPRequest m_LastRequest; + GHTTPRequest m_LastRequest; }; diff --git a/src/xrGameSpy/GameSpy_Keys.h b/src/xrGameSpy/GameSpy_Keys.h index eb79a012375..9e7552c6651 100644 --- a/src/xrGameSpy/GameSpy_Keys.h +++ b/src/xrGameSpy/GameSpy_Keys.h @@ -3,85 +3,84 @@ #define MAX_REGISTERED_KEYS 254 #define NUM_RESERVED_KEYS 50 - -#define HOSTNAME_KEY 1 -#define GAMENAME_KEY 2 -#define GAMEVER_KEY 3 -#define HOSTPORT_KEY 4 -#define MAPNAME_KEY 5 -#define GAMETYPE_KEY 6 -#define GAMEVARIANT_KEY 7 -#define NUMPLAYERS_KEY 8 -#define NUMTEAMS_KEY 9 -#define MAXPLAYERS_KEY 10 -#define GAMEMODE_KEY 11 -#define TEAMPLAY_KEY 12 -#define FRAGLIMIT_KEY 13 -#define TEAMFRAGLIMIT_KEY 14 -#define TIMEELAPSED_KEY 15 -#define TIMELIMIT_KEY 16 -#define ROUNDTIME_KEY 17 -#define ROUNDELAPSED_KEY 18 -#define PASSWORD_KEY 19 -#define GROUPID_KEY 20 -#define PLAYER__KEY 21 -#define SCORE__KEY 22 -#define SKILL__KEY 23 -#define PING__KEY 24 -#define TEAM__KEY 25 -#define DEATHS__KEY 26 -#define PID__KEY 27 -#define TEAM_T_KEY 28 -#define SCORE_T_KEY 29 +#define HOSTNAME_KEY 1 +#define GAMENAME_KEY 2 +#define GAMEVER_KEY 3 +#define HOSTPORT_KEY 4 +#define MAPNAME_KEY 5 +#define GAMETYPE_KEY 6 +#define GAMEVARIANT_KEY 7 +#define NUMPLAYERS_KEY 8 +#define NUMTEAMS_KEY 9 +#define MAXPLAYERS_KEY 10 +#define GAMEMODE_KEY 11 +#define TEAMPLAY_KEY 12 +#define FRAGLIMIT_KEY 13 +#define TEAMFRAGLIMIT_KEY 14 +#define TIMEELAPSED_KEY 15 +#define TIMELIMIT_KEY 16 +#define ROUNDTIME_KEY 17 +#define ROUNDELAPSED_KEY 18 +#define PASSWORD_KEY 19 +#define GROUPID_KEY 20 +#define PLAYER__KEY 21 +#define SCORE__KEY 22 +#define SKILL__KEY 23 +#define PING__KEY 24 +#define TEAM__KEY 25 +#define DEATHS__KEY 26 +#define PID__KEY 27 +#define TEAM_T_KEY 28 +#define SCORE_T_KEY 29 //----- ADDITIONAL KEYS --------------------- //---- Game Keys //---- Global Keys ---- -#define GAMETYPE_NAME_KEY 100 -#define DEDICATED_KEY 101 -//---- game_sv_base --- -#define G_MAP_ROTATION_KEY 102 -#define G_VOTING_ENABLED_KEY 103 -//---- game sv mp ---- -#define G_SPECTATOR_MODES_KEY 104 -//---- game_sv_deathmatch ---- -#define G_FRAG_LIMIT_KEY 105 -#define G_TIME_LIMIT_KEY 106 -#define G_DAMAGE_BLOCK_TIME_KEY 107 -#define G_DAMAGE_BLOCK_INDICATOR_KEY 108 -#define G_ANOMALIES_ENABLED_KEY 109 -#define G_ANOMALIES_TIME_KEY 110 -#define G_WARM_UP_TIME_KEY 111 -#define G_FORCE_RESPAWN_KEY 112 -//---- game_sv_teamdeathmatch ---- -#define G_AUTO_TEAM_BALANCE_KEY 113 -#define G_AUTO_TEAM_SWAP_KEY 114 -#define G_FRIENDLY_INDICATORS_KEY 115 -#define G_FRIENDLY_NAMES_KEY 116 -#define G_FRIENDLY_FIRE_KEY 117 -//---- game_sv_artefacthunt ---- -#define G_ARTEFACTS_COUNT_KEY 118 -#define G_ARTEFACT_STAY_TIME_KEY 119 -#define G_ARTEFACT_RESPAWN_TIME_KEY 120 -#define G_REINFORCEMENT_KEY 121 -#define G_SHIELDED_BASES_KEY 122 -#define G_RETURN_PLAYERS_KEY 123 -#define G_BEARER_CANT_SPRINT_KEY 124 - -//---- Player keys +#define GAMETYPE_NAME_KEY 100 +#define DEDICATED_KEY 101 +//---- game_sv_base --- +#define G_MAP_ROTATION_KEY 102 +#define G_VOTING_ENABLED_KEY 103 +//---- game sv mp ---- +#define G_SPECTATOR_MODES_KEY 104 +//---- game_sv_deathmatch ---- +#define G_FRAG_LIMIT_KEY 105 +#define G_TIME_LIMIT_KEY 106 +#define G_DAMAGE_BLOCK_TIME_KEY 107 +#define G_DAMAGE_BLOCK_INDICATOR_KEY 108 +#define G_ANOMALIES_ENABLED_KEY 109 +#define G_ANOMALIES_TIME_KEY 110 +#define G_WARM_UP_TIME_KEY 111 +#define G_FORCE_RESPAWN_KEY 112 +//---- game_sv_teamdeathmatch ---- +#define G_AUTO_TEAM_BALANCE_KEY 113 +#define G_AUTO_TEAM_SWAP_KEY 114 +#define G_FRIENDLY_INDICATORS_KEY 115 +#define G_FRIENDLY_NAMES_KEY 116 +#define G_FRIENDLY_FIRE_KEY 117 +//---- game_sv_artefacthunt ---- +#define G_ARTEFACTS_COUNT_KEY 118 +#define G_ARTEFACT_STAY_TIME_KEY 119 +#define G_ARTEFACT_RESPAWN_TIME_KEY 120 +#define G_REINFORCEMENT_KEY 121 +#define G_SHIELDED_BASES_KEY 122 +#define G_RETURN_PLAYERS_KEY 123 +#define G_BEARER_CANT_SPRINT_KEY 124 + +//---- Player keys //#define P_NAME__KEY 125 //#define P_FRAGS__KEY 126 //#define P_DEATH__KEY 127 //#define P_RANK__KEY 128 //#define P_TEAM__KEY 129 -#define P_SPECTATOR__KEY 130 -#define P_ARTEFACTS__KEY 131 +#define P_SPECTATOR__KEY 130 +#define P_ARTEFACTS__KEY 131 //---- Team keys -//#define T_NAME_KEY -#define T_SCORE_T_KEY 132 +//#define T_NAME_KEY +#define T_SCORE_T_KEY 132 -#define G_MAX_PING_KEY 133 -#define G_BATTLEYE_KEY 134 -#define G_USER_PASSWORD_KEY 135 -#define SERVER_UP_TIME_KEY 136 +#define G_MAX_PING_KEY 133 +#define G_BATTLEYE_KEY 134 +#define G_USER_PASSWORD_KEY 135 +#define SERVER_UP_TIME_KEY 136 diff --git a/src/xrGameSpy/GameSpy_Patching.cpp b/src/xrGameSpy/GameSpy_Patching.cpp index 9ee37088bb1..367e44849f9 100644 --- a/src/xrGameSpy/GameSpy_Patching.cpp +++ b/src/xrGameSpy/GameSpy_Patching.cpp @@ -1,97 +1,85 @@ -#include "StdAfx.h" #include "GameSpy_Patching.h" +#include "StdAfx.h" -static char const * QueryPatchVersionString(char* dest, u32 dest_size) +static char const* QueryPatchVersionString(char* dest, u32 dest_size) { - HKEY KeyCDKey = 0; - - long res = RegOpenKeyEx(REGISTRY_BASE, - REGISTRY_PATH, 0, KEY_READ, &KeyCDKey); + HKEY KeyCDKey = 0; + + long res = RegOpenKeyEx(REGISTRY_BASE, REGISTRY_PATH, 0, KEY_READ, &KeyCDKey); + + if (res != ERROR_SUCCESS || KeyCDKey == 0) return ""; - if (res != ERROR_SUCCESS || KeyCDKey == 0) - return ""; + // string128 SourceID; + string256 LangID; + DWORD KeyValueSize = sizeof(LangID); + DWORD KeyValueType = REG_SZ; - //string128 SourceID; - string256 LangID; - DWORD KeyValueSize = sizeof(LangID); - DWORD KeyValueType = REG_SZ; + // RegQueryValueEx(KeyCDKey, REGISTRY_VALUE_LANGUAGE, NULL, &KeyValueType, (LPBYTE)LangID, &KeyValueSize); + RegQueryValueEx(KeyCDKey, REGISTRY_VALUE_SKU, NULL, &KeyValueType, (LPBYTE)LangID, &KeyValueSize); - //RegQueryValueEx(KeyCDKey, REGISTRY_VALUE_LANGUAGE, NULL, &KeyValueType, (LPBYTE)LangID, &KeyValueSize); - RegQueryValueEx(KeyCDKey, REGISTRY_VALUE_SKU, NULL, &KeyValueType, (LPBYTE)LangID, &KeyValueSize); + xr_sprintf(dest, dest_size, "-%s", LangID); - xr_sprintf(dest, dest_size, "-%s", LangID); - - RegCloseKey(KeyCDKey); - return dest; + RegCloseKey(KeyCDKey); + return dest; } #define PATCH_SUFFIX ".exe" #define PATCH_SUFFIX_SIZE (sizeof(PATCH_SUFFIX) - 1) #define APPEND_DWURL_INFO_LEN 256 -static char const * ModifyDownloadUrl(char* dest, u32 dest_size, char const * origDownloadUrl) +static char const* ModifyDownloadUrl(char* dest, u32 dest_size, char const* origDownloadUrl) { - if (!origDownloadUrl) - return ""; + if (!origDownloadUrl) return ""; - xr_strcpy(dest, dest_size, origDownloadUrl); - u32 url_size = xr_strlen(dest); - if (url_size < PATCH_SUFFIX_SIZE) - return dest; - - char* search_ptr = (dest + url_size) - PATCH_SUFFIX_SIZE; - char* suffix_ptr = NULL; - while (search_ptr > dest) - { - suffix_ptr = strstr(search_ptr, PATCH_SUFFIX); - if (suffix_ptr) - break; - - search_ptr--; - } - if (!suffix_ptr) - return dest; - - *suffix_ptr = 0; - string256 tmp_append_str; - xr_strcat(dest, dest_size, QueryPatchVersionString(tmp_append_str, sizeof(tmp_append_str))); - xr_strcat(dest, dest_size, PATCH_SUFFIX); - return dest; -}; + xr_strcpy(dest, dest_size, origDownloadUrl); + u32 url_size = xr_strlen(dest); + if (url_size < PATCH_SUFFIX_SIZE) return dest; + char* search_ptr = (dest + url_size) - PATCH_SUFFIX_SIZE; + char* suffix_ptr = NULL; + while (search_ptr > dest) + { + suffix_ptr = strstr(search_ptr, PATCH_SUFFIX); + if (suffix_ptr) break; + search_ptr--; + } + if (!suffix_ptr) return dest; + *suffix_ptr = 0; + string256 tmp_append_str; + xr_strcat(dest, dest_size, QueryPatchVersionString(tmp_append_str, sizeof(tmp_append_str))); + xr_strcat(dest, dest_size, PATCH_SUFFIX); + return dest; +}; bool g_bInformUserThatNoPatchFound = true; -void __cdecl GS_ptPatchCallback ( PTBool available, PTBool mandatory, const char * versionName, int fileID, const char * downloadURL, void * param ) +void __cdecl GS_ptPatchCallback( + PTBool available, PTBool mandatory, const char* versionName, int fileID, const char* downloadURL, void* param) { - if (!param) + if (!param) return; + auto& cb = *static_cast(param); + if (!available) { + Msg("No new patches are available."); + if (g_bInformUserThatNoPatchFound) cb(false, nullptr, nullptr); return; - auto &cb = *static_cast(param); - if (!available) - { - Msg("No new patches are available."); - if (g_bInformUserThatNoPatchFound) - cb(false, nullptr, nullptr); - return; - }; - Msg("Found NewPatch: %s - %s", versionName, downloadURL); - u32 new_url_size = APPEND_DWURL_INFO_LEN + (downloadURL ? xr_strlen(downloadURL) : 0); - char* new_download_url = static_cast(_alloca(new_url_size)); - char const * new_url = ModifyDownloadUrl(new_download_url, new_url_size, downloadURL); - Msg("NewPatch url after updating: %s", new_url); + }; + Msg("Found NewPatch: %s - %s", versionName, downloadURL); + u32 new_url_size = APPEND_DWURL_INFO_LEN + (downloadURL ? xr_strlen(downloadURL) : 0); + char* new_download_url = static_cast(_alloca(new_url_size)); + char const* new_url = ModifyDownloadUrl(new_download_url, new_url_size, downloadURL); + Msg("NewPatch url after updating: %s", new_url); cb(true, versionName, new_url); }; -void CGameSpy_Patching::CheckForPatch(bool InformOfNoPatch, PatchCheckCallback &cb) +void CGameSpy_Patching::CheckForPatch(bool InformOfNoPatch, PatchCheckCallback& cb) { - g_bInformUserThatNoPatchFound = InformOfNoPatch; - bool res = ptCheckForPatchA(GAMESPY_PRODUCTID, - GetGameVersion(), GetGameDistribution(), GS_ptPatchCallback, PTFalse, &cb)!=PTFalse; - if (!res) - Msg("! Unable to send query for patch!"); + g_bInformUserThatNoPatchFound = InformOfNoPatch; + bool res = ptCheckForPatchA(GAMESPY_PRODUCTID, GetGameVersion(), GetGameDistribution(), GS_ptPatchCallback, PTFalse, + &cb) != PTFalse; + if (!res) Msg("! Unable to send query for patch!"); }; -void CGameSpy_Patching::PtTrackUsage (int userID) +void CGameSpy_Patching::PtTrackUsage(int userID) { - ptTrackUsageA(userID, GAMESPY_PRODUCTID, GetGameVersion(), GetGameDistribution(), PTFalse); + ptTrackUsageA(userID, GAMESPY_PRODUCTID, GetGameVersion(), GetGameDistribution(), PTFalse); } diff --git a/src/xrGameSpy/GameSpy_Patching.h b/src/xrGameSpy/GameSpy_Patching.h index 40e6d9e731c..9158280c64c 100644 --- a/src/xrGameSpy/GameSpy_Patching.h +++ b/src/xrGameSpy/GameSpy_Patching.h @@ -6,8 +6,8 @@ class XRGAMESPY_API CGameSpy_Patching { public: - using PatchCheckCallback = fastdelegate::FastDelegate; - - void CheckForPatch (bool InformOfNoPatch, PatchCheckCallback &cb); - void PtTrackUsage (int userID); + using PatchCheckCallback = fastdelegate::FastDelegate; + + void CheckForPatch(bool InformOfNoPatch, PatchCheckCallback& cb); + void PtTrackUsage(int userID); }; diff --git a/src/xrGameSpy/GameSpy_QR2.cpp b/src/xrGameSpy/GameSpy_QR2.cpp index c27ef0ef24a..10e97022de2 100644 --- a/src/xrGameSpy/GameSpy_QR2.cpp +++ b/src/xrGameSpy/GameSpy_QR2.cpp @@ -1,176 +1,152 @@ -#include "StdAfx.h" #include "GameSpy_QR2.h" #include "GameSpy_Keys.h" +#include "StdAfx.h" namespace { - -qr2_error_t xrGS_qr2_initA( - qr2_t *qrec, const gsi_char *ip, int baseport, - int ispublic, int natnegotiate, - qr2_serverkeycallback_t server_key_callback, - qr2_playerteamkeycallback_t player_key_callback, - qr2_playerteamkeycallback_t team_key_callback, - qr2_keylistcallback_t key_list_callback, - qr2_countcallback_t playerteam_count_callback, - qr2_adderrorcallback_t adderror_callback, - void *userdata) +qr2_error_t xrGS_qr2_initA(qr2_t* qrec, const gsi_char* ip, int baseport, int ispublic, int natnegotiate, + qr2_serverkeycallback_t server_key_callback, qr2_playerteamkeycallback_t player_key_callback, + qr2_playerteamkeycallback_t team_key_callback, qr2_keylistcallback_t key_list_callback, + qr2_countcallback_t playerteam_count_callback, qr2_adderrorcallback_t adderror_callback, void* userdata) { - int BasePort = baseport; - if (BasePort == -1) BasePort = GAMESPY_QR2_BASEPORT; - else - { - if (BasePort < START_PORT) BasePort = START_PORT; - if (BasePort > END_PORT) BasePort = END_PORT; - } - - char SecretKey[16]; - FillSecretKey(SecretKey); - - qr2_error_t res = - qr2_initA(qrec, ip, BasePort, GAMESPY_GAMENAME, SecretKey, - ispublic, - natnegotiate, - server_key_callback, - player_key_callback, - team_key_callback, - key_list_callback, - playerteam_count_callback, - adderror_callback, - userdata); - - return res; + int BasePort = baseport; + if (BasePort == -1) + BasePort = GAMESPY_QR2_BASEPORT; + else + { + if (BasePort < START_PORT) BasePort = START_PORT; + if (BasePort > END_PORT) BasePort = END_PORT; + } + + char SecretKey[16]; + FillSecretKey(SecretKey); + + qr2_error_t res = qr2_initA(qrec, ip, BasePort, GAMESPY_GAMENAME, SecretKey, ispublic, natnegotiate, + server_key_callback, player_key_callback, team_key_callback, key_list_callback, playerteam_count_callback, + adderror_callback, userdata); + + return res; } - } -void CGameSpy_QR2::Think (void* qrec) +void CGameSpy_QR2::Think(void* qrec) { - qr2_think(static_cast(qrec)); + qr2_think(static_cast(qrec)); } -void CGameSpy_QR2::ShutDown (void* qrec) +void CGameSpy_QR2::ShutDown(void* qrec) { - qr2_shutdown(static_cast(qrec)); + qr2_shutdown(static_cast(qrec)); } -void CGameSpy_QR2::RegisterAdditionalKeys () +void CGameSpy_QR2::RegisterAdditionalKeys() { - //---- Global Keys ---- - qr2_register_keyA(GAMETYPE_NAME_KEY, ("gametypename")); - qr2_register_keyA(DEDICATED_KEY, ("dedicated")); - //---- game_sv_base --- - qr2_register_keyA(G_MAP_ROTATION_KEY, ("maprotation")); - qr2_register_keyA(G_VOTING_ENABLED_KEY, ("voting")); - //---- game sv mp ---- - qr2_register_keyA(G_SPECTATOR_MODES_KEY, ("spectatormodes")); - qr2_register_keyA(G_MAX_PING_KEY, ("max_ping_limit")); - qr2_register_keyA(G_USER_PASSWORD_KEY, ("user_password")); - - //---- game_sv_deathmatch ---- - qr2_register_keyA(G_FRAG_LIMIT_KEY, ("fraglimit")); - qr2_register_keyA(G_TIME_LIMIT_KEY, ("timelimit")); - qr2_register_keyA(G_DAMAGE_BLOCK_TIME_KEY, ("damageblocktime")); - qr2_register_keyA(G_DAMAGE_BLOCK_INDICATOR_KEY, ("damageblockindicator")); - qr2_register_keyA(G_ANOMALIES_ENABLED_KEY, ("anomalies")); - qr2_register_keyA(G_ANOMALIES_TIME_KEY, ("anomaliestime")); - qr2_register_keyA(G_WARM_UP_TIME_KEY, ("warmuptime")); - qr2_register_keyA(G_FORCE_RESPAWN_KEY, ("forcerespawn")); - //---- game_sv_teamdeathmatch ---- - qr2_register_keyA(G_AUTO_TEAM_BALANCE_KEY, ("autoteambalance")); - qr2_register_keyA(G_AUTO_TEAM_SWAP_KEY, ("autoteamswap")); - qr2_register_keyA(G_FRIENDLY_INDICATORS_KEY, ("friendlyindicators")); - qr2_register_keyA(G_FRIENDLY_NAMES_KEY, ("friendlynames")); - qr2_register_keyA(G_FRIENDLY_FIRE_KEY, ("friendlyfire")); - //---- game_sv_artefacthunt ---- - qr2_register_keyA(G_ARTEFACTS_COUNT_KEY, ("artefactscount")); - qr2_register_keyA(G_ARTEFACT_STAY_TIME_KEY, ("artefactstaytime")); - qr2_register_keyA(G_ARTEFACT_RESPAWN_TIME_KEY, ("artefactrespawntime")); - qr2_register_keyA(G_REINFORCEMENT_KEY, ("reinforcement")); - qr2_register_keyA(G_SHIELDED_BASES_KEY, ("shieldedbases")); - qr2_register_keyA(G_RETURN_PLAYERS_KEY, ("returnplayers")); - qr2_register_keyA(G_BEARER_CANT_SPRINT_KEY, ("bearercant_sprint")); - - //---- Player keys -// qr2_register_keyA(P_NAME__KEY, ("name_")); -// qr2_register_keyA(P_FRAGS__KEY, ("frags_")); -// qr2_register_keyA(P_DEATH__KEY, ("death_")); -// qr2_register_keyA(P_RANK__KEY, ("rank_")); -// qr2_register_keyA(P_TEAM__KEY, ("p_team_")); - qr2_register_keyA(P_SPECTATOR__KEY, ("spectator_")); - qr2_register_keyA(P_ARTEFACTS__KEY, ("artefacts_")); - - //---- Team keys -// qr2_register_keyA(T_NAME_KEY, ("t_name_key")); - qr2_register_keyA(T_SCORE_T_KEY, ("t_score_t")); - qr2_register_keyA(SERVER_UP_TIME_KEY, ("server_up_time")); + //---- Global Keys ---- + qr2_register_keyA(GAMETYPE_NAME_KEY, ("gametypename")); + qr2_register_keyA(DEDICATED_KEY, ("dedicated")); + //---- game_sv_base --- + qr2_register_keyA(G_MAP_ROTATION_KEY, ("maprotation")); + qr2_register_keyA(G_VOTING_ENABLED_KEY, ("voting")); + //---- game sv mp ---- + qr2_register_keyA(G_SPECTATOR_MODES_KEY, ("spectatormodes")); + qr2_register_keyA(G_MAX_PING_KEY, ("max_ping_limit")); + qr2_register_keyA(G_USER_PASSWORD_KEY, ("user_password")); + + //---- game_sv_deathmatch ---- + qr2_register_keyA(G_FRAG_LIMIT_KEY, ("fraglimit")); + qr2_register_keyA(G_TIME_LIMIT_KEY, ("timelimit")); + qr2_register_keyA(G_DAMAGE_BLOCK_TIME_KEY, ("damageblocktime")); + qr2_register_keyA(G_DAMAGE_BLOCK_INDICATOR_KEY, ("damageblockindicator")); + qr2_register_keyA(G_ANOMALIES_ENABLED_KEY, ("anomalies")); + qr2_register_keyA(G_ANOMALIES_TIME_KEY, ("anomaliestime")); + qr2_register_keyA(G_WARM_UP_TIME_KEY, ("warmuptime")); + qr2_register_keyA(G_FORCE_RESPAWN_KEY, ("forcerespawn")); + //---- game_sv_teamdeathmatch ---- + qr2_register_keyA(G_AUTO_TEAM_BALANCE_KEY, ("autoteambalance")); + qr2_register_keyA(G_AUTO_TEAM_SWAP_KEY, ("autoteamswap")); + qr2_register_keyA(G_FRIENDLY_INDICATORS_KEY, ("friendlyindicators")); + qr2_register_keyA(G_FRIENDLY_NAMES_KEY, ("friendlynames")); + qr2_register_keyA(G_FRIENDLY_FIRE_KEY, ("friendlyfire")); + //---- game_sv_artefacthunt ---- + qr2_register_keyA(G_ARTEFACTS_COUNT_KEY, ("artefactscount")); + qr2_register_keyA(G_ARTEFACT_STAY_TIME_KEY, ("artefactstaytime")); + qr2_register_keyA(G_ARTEFACT_RESPAWN_TIME_KEY, ("artefactrespawntime")); + qr2_register_keyA(G_REINFORCEMENT_KEY, ("reinforcement")); + qr2_register_keyA(G_SHIELDED_BASES_KEY, ("shieldedbases")); + qr2_register_keyA(G_RETURN_PLAYERS_KEY, ("returnplayers")); + qr2_register_keyA(G_BEARER_CANT_SPRINT_KEY, ("bearercant_sprint")); + + //---- Player keys + // qr2_register_keyA(P_NAME__KEY, ("name_")); + // qr2_register_keyA(P_FRAGS__KEY, ("frags_")); + // qr2_register_keyA(P_DEATH__KEY, ("death_")); + // qr2_register_keyA(P_RANK__KEY, ("rank_")); + // qr2_register_keyA(P_TEAM__KEY, ("p_team_")); + qr2_register_keyA(P_SPECTATOR__KEY, ("spectator_")); + qr2_register_keyA(P_ARTEFACTS__KEY, ("artefacts_")); + + //---- Team keys + // qr2_register_keyA(T_NAME_KEY, ("t_name_key")); + qr2_register_keyA(T_SCORE_T_KEY, ("t_score_t")); + qr2_register_keyA(SERVER_UP_TIME_KEY, ("server_up_time")); }; -bool CGameSpy_QR2::Init (int PortID, int Public, Context &ctx) -{ - //--------- QR2 Init -------------------------/ - //call qr_init with the query port number and gamename, default IP address, and no user data - -// if (qr2_initA(NULL,NULL,PortID, GAMESPY_GAMENAME, m_SecretKey, Public, 0, - qr2_error_t err = xrGS_qr2_initA( - NULL, - NULL, - PortID, - Public, - 0, - ctx.OnServerKey, - ctx.OnPlayerKey, - ctx.OnTeamKey, - ctx.OnKeyList, - ctx.OnCount, - ctx.OnError, - &ctx - ); +bool CGameSpy_QR2::Init(int PortID, int Public, Context& ctx) +{ + //--------- QR2 Init -------------------------/ + // call qr_init with the query port number and gamename, default IP address, and no user data + + // if (qr2_initA(NULL,NULL,PortID, GAMESPY_GAMENAME, m_SecretKey, Public, 0, + qr2_error_t err = xrGS_qr2_initA(NULL, NULL, PortID, Public, 0, ctx.OnServerKey, ctx.OnPlayerKey, ctx.OnTeamKey, + ctx.OnKeyList, ctx.OnCount, ctx.OnError, &ctx); #ifndef MASTER_GOLD - Msg("xrGS::xrGS_qr2_initA returned code is [%d]", err); -#endif // #ifndef MASTER_GOLD - - if (err != e_qrnoerror) - { - // _tprintf(_T("Error starting query sockets\n")); - Msg("xrGS::QR2 : Failes to Initialize!"); - return false; - } - - RegisterAdditionalKeys(); - - // Set a function to be called when we receive a game specific message - qr2_register_clientmessage_callback(NULL, ctx.OnClientMessage); - - // Set a function to be called when we receive a nat negotiation request - qr2_register_natneg_callback(NULL, ctx.OnNatNeg); - - //Set a function to be called when gamespy responds my IP and port number - //qr2_register_publicaddress_callback(NULL, callback_public); - qr2_register_denyresponsetoip_callback(NULL, ctx.OnDenyIP); + Msg("xrGS::xrGS_qr2_initA returned code is [%d]", err); +#endif // #ifndef MASTER_GOLD + + if (err != e_qrnoerror) { + // _tprintf(_T("Error starting query sockets\n")); + Msg("xrGS::QR2 : Failes to Initialize!"); + return false; + } + + RegisterAdditionalKeys(); + + // Set a function to be called when we receive a game specific message + qr2_register_clientmessage_callback(NULL, ctx.OnClientMessage); + + // Set a function to be called when we receive a nat negotiation request + qr2_register_natneg_callback(NULL, ctx.OnNatNeg); + + // Set a function to be called when gamespy responds my IP and port number + // qr2_register_publicaddress_callback(NULL, callback_public); + qr2_register_denyresponsetoip_callback(NULL, ctx.OnDenyIP); #ifndef MASTER_GOLD - Msg("xrGS::QR2 : Initialized"); -#endif // #ifndef MASTER_GOLD - return true; + Msg("xrGS::QR2 : Initialized"); +#endif // #ifndef MASTER_GOLD + return true; }; -void CGameSpy_QR2::BufferAdd (void* outbuf, const char* value) +void CGameSpy_QR2::BufferAdd(void* outbuf, const char* value) { - qr2_buffer_addA(static_cast(outbuf), value); + qr2_buffer_addA(static_cast(outbuf), value); }; -void CGameSpy_QR2::BufferAdd_Int (void* outbuf, int value) +void CGameSpy_QR2::BufferAdd_Int(void* outbuf, int value) { - qr2_buffer_add_int(static_cast(outbuf), value); + qr2_buffer_add_int(static_cast(outbuf), value); }; -void CGameSpy_QR2::KeyBufferAdd (void* keybuffer, int keyid) +void CGameSpy_QR2::KeyBufferAdd(void* keybuffer, int keyid) { - qr2_keybuffer_add(static_cast(keybuffer), keyid); + qr2_keybuffer_add(static_cast(keybuffer), keyid); } -const char *CGameSpy_QR2::GetGameVersion() -{ return GAME_VERSION; } +const char* CGameSpy_QR2::GetGameVersion() +{ + return GAME_VERSION; +} -const char *CGameSpy_QR2::RegisteredKey(DWORD KeyID) -{ return qr2_registered_key_list[KeyID]; } +const char* CGameSpy_QR2::RegisteredKey(DWORD KeyID) +{ + return qr2_registered_key_list[KeyID]; +} diff --git a/src/xrGameSpy/GameSpy_QR2.h b/src/xrGameSpy/GameSpy_QR2.h index 499dec09fa1..7ae402d50b5 100644 --- a/src/xrGameSpy/GameSpy_QR2.h +++ b/src/xrGameSpy/GameSpy_QR2.h @@ -11,30 +11,30 @@ class XRGAMESPY_API CGameSpy_QR2 class Context { public: - void (__cdecl *OnServerKey)(int keyid, qr2_buffer_t outbuf, void *userdata); - void (__cdecl *OnPlayerKey)(int keyid, int index, qr2_buffer_t outbuf, void *userdata); - void (__cdecl *OnTeamKey)(int keyid, int index, qr2_buffer_t outbuf, void *userdata); - void (__cdecl *OnKeyList)(qr2_key_type keytype, qr2_keybuffer_t keybuffer, void *userdata); - int (__cdecl *OnCount)(qr2_key_type keytype, void *userdata); - void (__cdecl *OnError)(qr2_error_t error, gsi_char *errmsg, void *userdata); - void (__cdecl *OnNatNeg)(int cookie, void *userdata); - void (__cdecl *OnClientMessage)(char *data, int len, void *userdata); - void (__cdecl *OnDenyIP)(void *userdata, u32 senderIP, int *result); - xrGameSpyServer *GSServer; + void(__cdecl* OnServerKey)(int keyid, qr2_buffer_t outbuf, void* userdata); + void(__cdecl* OnPlayerKey)(int keyid, int index, qr2_buffer_t outbuf, void* userdata); + void(__cdecl* OnTeamKey)(int keyid, int index, qr2_buffer_t outbuf, void* userdata); + void(__cdecl* OnKeyList)(qr2_key_type keytype, qr2_keybuffer_t keybuffer, void* userdata); + int(__cdecl* OnCount)(qr2_key_type keytype, void* userdata); + void(__cdecl* OnError)(qr2_error_t error, gsi_char* errmsg, void* userdata); + void(__cdecl* OnNatNeg)(int cookie, void* userdata); + void(__cdecl* OnClientMessage)(char* data, int len, void* userdata); + void(__cdecl* OnDenyIP)(void* userdata, u32 senderIP, int* result); + xrGameSpyServer* GSServer; }; private: -// string16 m_SecretKey; + // string16 m_SecretKey; public: - bool Init (int PortID, int Public, Context &ctx); - void Think (void* qrec); - void ShutDown (void* qrec); - void RegisterAdditionalKeys (); - void BufferAdd (void* outbuf, const char* value); - void BufferAdd_Int (void* outbuf, int value); - void KeyBufferAdd (void* keybuffer, int keyid); + bool Init(int PortID, int Public, Context& ctx); + void Think(void* qrec); + void ShutDown(void* qrec); + void RegisterAdditionalKeys(); + void BufferAdd(void* outbuf, const char* value); + void BufferAdd_Int(void* outbuf, int value); + void KeyBufferAdd(void* keybuffer, int keyid); - const char* GetGameVersion(); - const char *RegisteredKey(DWORD KeyID); + const char* GetGameVersion(); + const char* RegisteredKey(DWORD KeyID); }; diff --git a/src/xrGameSpy/GameSpy_SAKE.cpp b/src/xrGameSpy/GameSpy_SAKE.cpp index d10792a5840..4bd0c0a540c 100644 --- a/src/xrGameSpy/GameSpy_SAKE.cpp +++ b/src/xrGameSpy/GameSpy_SAKE.cpp @@ -1,36 +1,27 @@ -#include "stdafx.h" #include "GameSpy_SAKE.h" +#include "stdafx.h" -shared_str const CGameSpy_SAKE::TryToTranslate(SAKERequestResult const & request_result) +shared_str const CGameSpy_SAKE::TryToTranslate(SAKERequestResult const& request_result) { - string16 digit_dest; - LPCSTR tmp_string = NULL; - _itoa_s(request_result, digit_dest, 10); - STRCONCAT( - tmp_string, - "mp_sake_database_request_error_", - digit_dest - ); - return tmp_string; + string16 digit_dest; + LPCSTR tmp_string = NULL; + _itoa_s(request_result, digit_dest, 10); + STRCONCAT(tmp_string, "mp_sake_database_request_error_", digit_dest); + return tmp_string; } -shared_str const CGameSpy_SAKE::TryToTranslate(SAKEStartRequestResult const & request_result) +shared_str const CGameSpy_SAKE::TryToTranslate(SAKEStartRequestResult const& request_result) { - string16 digit_dest; - LPCSTR tmp_string = NULL; - _itoa_s(request_result, digit_dest, 10); - STRCONCAT( - tmp_string, - "mp_sake_database_start_request_error_", - digit_dest - ); - return tmp_string; + string16 digit_dest; + LPCSTR tmp_string = NULL; + _itoa_s(request_result, digit_dest, 10); + STRCONCAT(tmp_string, "mp_sake_database_start_request_error_", digit_dest); + return tmp_string; } -SAKEStartupResult xrGS_sakeStartup(SAKE *sakePtr) +SAKEStartupResult xrGS_sakeStartup(SAKE* sakePtr) { SAKEStartupResult tmp_res = sakeStartup(sakePtr); - if (tmp_res == SAKEStartupResult_SUCCESS) - { + if (tmp_res == SAKEStartupResult_SUCCESS) { char secret_key[32]; memset(secret_key, 0, sizeof(secret_key)); FillSecretKey(secret_key); @@ -42,8 +33,7 @@ SAKEStartupResult xrGS_sakeStartup(SAKE *sakePtr) void CGameSpy_SAKE::Init() { SAKEStartupResult result = sakeStartup(&m_sake_inst); - if (result == SAKEStartupResult_SUCCESS) - { + if (result == SAKEStartupResult_SUCCESS) { char secret_key[32]; memset(secret_key, 0, sizeof(secret_key)); FillSecretKey(secret_key); @@ -51,76 +41,47 @@ void CGameSpy_SAKE::Init() } else Msg("! GameSpy SAKE: failed to initialize, error code: %d", result); - VERIFY(result == SAKEStartupResult_SUCCESS); + VERIFY(result == SAKEStartupResult_SUCCESS); } CGameSpy_SAKE::CGameSpy_SAKE() { - m_sake_inst = NULL; - Init (); + m_sake_inst = NULL; + Init(); } CGameSpy_SAKE::~CGameSpy_SAKE() { - if (m_sake_inst) - { + if (m_sake_inst) { sakeShutdown(m_sake_inst); - } + } } -void CGameSpy_SAKE::SetProfile(int profileId, - const char *loginTicket) +void CGameSpy_SAKE::SetProfile(int profileId, const char* loginTicket) { sakeSetProfile(m_sake_inst, profileId, loginTicket); } SAKEStartRequestResult CGameSpy_SAKE::GetRequestResult() { - return sakeGetStartRequestResult(m_sake_inst); + return sakeGetStartRequestResult(m_sake_inst); } -SAKERequest CGameSpy_SAKE::GetMyRecords(SAKEGetMyRecordsInput * input, - SAKERequestCallback callback, - void * userData) +SAKERequest CGameSpy_SAKE::GetMyRecords(SAKEGetMyRecordsInput* input, SAKERequestCallback callback, void* userData) { - return sakeGetMyRecords( - m_sake_inst, - input, - callback, - userData - ); + return sakeGetMyRecords(m_sake_inst, input, callback, userData); } -SAKERequest CGameSpy_SAKE::CreateRecord(SAKECreateRecordInput * input, - SAKERequestCallback callback, - void * userdata) +SAKERequest CGameSpy_SAKE::CreateRecord(SAKECreateRecordInput* input, SAKERequestCallback callback, void* userdata) { - return sakeCreateRecord( - m_sake_inst, - input, - callback, - userdata - ); + return sakeCreateRecord(m_sake_inst, input, callback, userdata); } -SAKERequest CGameSpy_SAKE::UpdateRecord(SAKEUpdateRecordInput * input, - SAKERequestCallback callback, - void * userdata) +SAKERequest CGameSpy_SAKE::UpdateRecord(SAKEUpdateRecordInput* input, SAKERequestCallback callback, void* userdata) { - return sakeUpdateRecord( - m_sake_inst, - input, - callback, - userdata - ); + return sakeUpdateRecord(m_sake_inst, input, callback, userdata); } -SAKERequest CGameSpy_SAKE::SearchForRecords(SAKESearchForRecordsInput * input, - SAKERequestCallback callback, - void * userData) +SAKERequest CGameSpy_SAKE::SearchForRecords( + SAKESearchForRecordsInput* input, SAKERequestCallback callback, void* userData) { - return sakeSearchForRecords( - m_sake_inst, - input, - callback, - userData - ); + return sakeSearchForRecords(m_sake_inst, input, callback, userData); } diff --git a/src/xrGameSpy/GameSpy_SAKE.h b/src/xrGameSpy/GameSpy_SAKE.h index 7dc4aa86511..70d0f43ab72 100644 --- a/src/xrGameSpy/GameSpy_SAKE.h +++ b/src/xrGameSpy/GameSpy_SAKE.h @@ -6,37 +6,27 @@ namespace gamespy_sake { - -} //namespace gamespy_sake +} // namespace gamespy_sake class XRGAMESPY_API CGameSpy_SAKE { public: - CGameSpy_SAKE (); - ~CGameSpy_SAKE (); + CGameSpy_SAKE(); + ~CGameSpy_SAKE(); + void SetProfile(int profileId, const char* loginTicket); + SAKEStartRequestResult GetRequestResult(); + SAKERequest GetMyRecords(SAKEGetMyRecordsInput* input, SAKERequestCallback callback, void* userData); + SAKERequest CreateRecord(SAKECreateRecordInput* input, SAKERequestCallback callback, void* userdata); + SAKERequest UpdateRecord(SAKEUpdateRecordInput* input, SAKERequestCallback callback, void* userdata); + SAKERequest SearchForRecords(SAKESearchForRecordsInput* input, SAKERequestCallback callback, void* userData); + static shared_str const TryToTranslate(SAKERequestResult const& request_result); + static shared_str const TryToTranslate(SAKEStartRequestResult const& request_result); - void SetProfile (int profileId, - const char *loginTicket); - SAKEStartRequestResult GetRequestResult(); - SAKERequest GetMyRecords (SAKEGetMyRecordsInput * input, - SAKERequestCallback callback, - void * userData); - SAKERequest CreateRecord (SAKECreateRecordInput * input, - SAKERequestCallback callback, - void * userdata); - SAKERequest UpdateRecord (SAKEUpdateRecordInput * input, - SAKERequestCallback callback, - void * userdata); - SAKERequest SearchForRecords(SAKESearchForRecordsInput * input, - SAKERequestCallback callback, - void * userData); - static shared_str const TryToTranslate (SAKERequestResult const & request_result); - static shared_str const TryToTranslate (SAKEStartRequestResult const & request_result); private: - SAKE m_sake_inst; - - void Init (); -}; //class GameSpy_SAKE + SAKE m_sake_inst; -#endif //#ifndef GAMESPY_SAKE + void Init(); +}; // class GameSpy_SAKE + +#endif //#ifndef GAMESPY_SAKE diff --git a/src/xrGameSpy/stdafx.h b/src/xrGameSpy/stdafx.h index 66d33990588..4ec98c691fc 100644 --- a/src/xrGameSpy/stdafx.h +++ b/src/xrGameSpy/stdafx.h @@ -3,14 +3,14 @@ #define WIN32_LEAN_AND_MEAN #include -#include #include -#include -#include +#include #include #include -#include -#include +#include #include +#include +#include #include #include +#include diff --git a/src/xrGameSpy/xrGameSpy.cpp b/src/xrGameSpy/xrGameSpy.cpp index 8d5f248684b..c19187435cc 100644 --- a/src/xrGameSpy/xrGameSpy.cpp +++ b/src/xrGameSpy/xrGameSpy.cpp @@ -1,98 +1,97 @@ -#include "stdafx.h" #include "xrGameSpy.h" +#include "stdafx.h" -void FillSecretKey(char *secretKey) +void FillSecretKey(char* secretKey) { - secretKey[0] = 'L'; - secretKey[1] = 'T'; - secretKey[2] = 'U'; - secretKey[3] = '2'; - secretKey[4] = 'z'; - secretKey[5] = '2'; - secretKey[6] = '\0'; + secretKey[0] = 'L'; + secretKey[1] = 'T'; + secretKey[2] = 'U'; + secretKey[3] = '2'; + secretKey[4] = 'z'; + secretKey[5] = '2'; + secretKey[6] = '\0'; } -const char* GetGameVersion() { return GAME_VERSION; } +const char* GetGameVersion() +{ + return GAME_VERSION; +} // WORD: Bit masks for languages -#define SKU_HAS_E 0x0001 // English -#define SKU_HAS_F 0x0002 // French -#define SKU_HAS_I 0x0004 // Italian -#define SKU_HAS_G 0x0008 // German -#define SKU_HAS_S 0x0010 // Spanish -#define SKU_HAS_R 0x0020 // Russian -#define SKU_HAS_P 0x0040 // Polish -#define SKU_HAS_C 0x0080 // Czech -#define SKU_HAS_H 0x0100 // China +#define SKU_HAS_E 0x0001 // English +#define SKU_HAS_F 0x0002 // French +#define SKU_HAS_I 0x0004 // Italian +#define SKU_HAS_G 0x0008 // German +#define SKU_HAS_S 0x0010 // Spanish +#define SKU_HAS_R 0x0020 // Russian +#define SKU_HAS_P 0x0040 // Polish +#define SKU_HAS_C 0x0080 // Czech +#define SKU_HAS_H 0x0100 // China // BYTE: Bit masks for protection -#define SKU_PRT_NONE 0x10 // Without protection -#define SKU_PRT_SECU 0x20 // SecuROM -#define SKU_PRT_STAR 0x40 // StarForce -#define SKU_PRT_PACK 0x80 // Different DB packing algorithm +#define SKU_PRT_NONE 0x10 // Without protection +#define SKU_PRT_SECU 0x20 // SecuROM +#define SKU_PRT_STAR 0x40 // StarForce +#define SKU_PRT_PACK 0x80 // Different DB packing algorithm // and subprotection -#define SKU_SUB_KEYDISK 0x01 // Binding to key-disk -#define SKU_SUB_ONLINE 0x02 // Binding to hardware with online activation +#define SKU_SUB_KEYDISK 0x01 // Binding to key-disk +#define SKU_SUB_ONLINE 0x02 // Binding to hardware with online activation int GetGameDistribution() { - HKEY KeyCDKey = 0; - - long res = RegOpenKeyEx(REGISTRY_BASE, - REGISTRY_PATH, 0, KEY_READ, &KeyCDKey); + HKEY KeyCDKey = 0; + + long res = RegOpenKeyEx(REGISTRY_BASE, REGISTRY_PATH, 0, KEY_READ, &KeyCDKey); + + // char KeyValue[1024] = ""; + int KeyValue; + DWORD KeyValueSize = 1024; + DWORD KeyValueType = REG_DWORD; + if (res == ERROR_SUCCESS && KeyCDKey != 0) { + res = RegQueryValueEx( + KeyCDKey, REGISTRY_VALUE_INSTALL_PATCH_ID, NULL, &KeyValueType, (LPBYTE)&KeyValue, &KeyValueSize); + }; + if (KeyCDKey != 0) RegCloseKey(KeyCDKey); -// char KeyValue[1024] = ""; - int KeyValue; - DWORD KeyValueSize = 1024; - DWORD KeyValueType = REG_DWORD; - if (res == ERROR_SUCCESS && KeyCDKey != 0) - { - res = RegQueryValueEx(KeyCDKey, REGISTRY_VALUE_INSTALL_PATCH_ID, NULL, &KeyValueType, (LPBYTE)&KeyValue, &KeyValueSize); - }; - if (KeyCDKey != 0) RegCloseKey(KeyCDKey); + if (res == ERROR_PATH_NOT_FOUND || res == ERROR_FILE_NOT_FOUND || KeyValueSize == 0) { + return int(0); + }; - if (res == ERROR_PATH_NOT_FOUND || - res == ERROR_FILE_NOT_FOUND || - KeyValueSize == 0) - { - return int(0); - }; - - return KeyValue; + return KeyValue; } /* int _tmain(int argc, _TCHAR* argv[]) { - char *SKUs[] = { - "stk-for-pack-securom-activ-e" , - "stk-for-pack-securom-keydisk-efis" , - "stk-for-pack-securom-keydisk-eg" , - "stk-for-pack-securom-keydisk-p" , - "stk-for-pack-securom-keydisk-c" , - "stk-for-pack-securom-keydisk-h" , - "stk-rus-pack-starforce-keydisk-r" , - "stk-for-pack-noprot-efis" - }; + char *SKUs[] = { + "stk-for-pack-securom-activ-e" , + "stk-for-pack-securom-keydisk-efis" , + "stk-for-pack-securom-keydisk-eg" , + "stk-for-pack-securom-keydisk-p" , + "stk-for-pack-securom-keydisk-c" , + "stk-for-pack-securom-keydisk-h" , + "stk-rus-pack-starforce-keydisk-r" , + "stk-for-pack-noprot-efis" + }; - for ( int i = 0; i < 8; i ++ ) - printf( "%s : %i\n" , SKUs[ i ] , GetCodeSKU( SKUs[ i ] ) ); + for ( int i = 0; i < 8; i ++ ) + printf( "%s : %i\n" , SKUs[ i ] , GetCodeSKU( SKUs[ i ] ) ); - return 0; + return 0; } */ -void GetGameID (int* GameID, int verID) +void GetGameID(int* GameID, int verID) { - *GameID = int(GAMESPY_GAMEID); + *GameID = int(GAMESPY_GAMEID); #ifdef DEMO_BUILD - switch (verID) - { - case 1: *GameID = int(1067); break; - case 2: *GameID = int(1576); break; - case 3: *GameID = int(1620); break; - default: *GameID = int(GAMESPY_GAMEID); break; - } + switch (verID) + { + case 1: *GameID = int(1067); break; + case 2: *GameID = int(1576); break; + case 3: *GameID = int(1620); break; + default: *GameID = int(GAMESPY_GAMEID); break; + } #endif } diff --git a/src/xrGameSpy/xrGameSpy.h b/src/xrGameSpy/xrGameSpy.h index 54cb1fb6b9f..258cd28ce13 100644 --- a/src/xrGameSpy/xrGameSpy.h +++ b/src/xrGameSpy/xrGameSpy.h @@ -7,28 +7,28 @@ #define XRGAMESPY_API XR_IMPORT #endif -#include #include -#include -#include +#include #include #include -#include -#include +#include #include +#include +#include #include #include +#include #undef max -#include "xrGameSpy/xrGameSpy_MainDefs.h" #include "xrGameSpy/GameSpy_Available.h" #include "xrGameSpy/GameSpy_Browser.h" -#include "xrGameSpy/GameSpy_QR2.h" #include "xrGameSpy/GameSpy_GCD_Client.h" #include "xrGameSpy/GameSpy_GCD_Server.h" +#include "xrGameSpy/GameSpy_QR2.h" +#include "xrGameSpy/xrGameSpy_MainDefs.h" XRGAMESPY_API const char* GetGameVersion(); XRGAMESPY_API int GetGameDistribution(); -XRGAMESPY_API void GetGameID(int *GameID, int verID); +XRGAMESPY_API void GetGameID(int* GameID, int verID); -void FillSecretKey(char *secretKey); +void FillSecretKey(char* secretKey); diff --git a/src/xrGameSpy/xrGameSpy_MainDefs.h b/src/xrGameSpy/xrGameSpy_MainDefs.h index 05f6ca67ea8..7a82d0ea407 100644 --- a/src/xrGameSpy/xrGameSpy_MainDefs.h +++ b/src/xrGameSpy/xrGameSpy_MainDefs.h @@ -10,41 +10,41 @@ //#define DEMO_BUILD #ifdef DEMO_BUILD - #define GAMESPY_GAMENAME "stalkercoppc" - #define GAMESPY_GAMEID 2760 - #define GAMESPY_PRODUCTID 11994 - #define GAME_VERSION "1.6.02" - #define REGISTRY_PATH "Software\\GSC Game World\\STALKER-COP_DBG\\" +#define GAMESPY_GAMENAME "stalkercoppc" +#define GAMESPY_GAMEID 2760 +#define GAMESPY_PRODUCTID 11994 +#define GAME_VERSION "1.6.02" +#define REGISTRY_PATH "Software\\GSC Game World\\STALKER-COP_DBG\\" #else - #define GAMESPY_GAMENAME "stalkercoppc" - #define GAMESPY_GAMEID 2760 - #define GAMESPY_PRODUCTID 11994 - #define GAME_VERSION "1.6.02" - #define REGISTRY_PATH "Software\\GSC Game World\\STALKER-COP\\" +#define GAMESPY_GAMENAME "stalkercoppc" +#define GAMESPY_GAMEID 2760 +#define GAMESPY_PRODUCTID 11994 +#define GAME_VERSION "1.6.02" +#define REGISTRY_PATH "Software\\GSC Game World\\STALKER-COP\\" #endif -#define GAMESPY_GP_NAMESPACE_ID 1 /*gamespy global namespace*/ - -#define GAMESPY_QR2_BASEPORT 5445 -#define GAMESPY_BROWSER_MAX_UPDATES 20 - -#define START_PORT 0 -#define END_PORT 65535 -#define START_PORT_LAN GAMESPY_QR2_BASEPORT -#define START_PORT_LAN_SV START_PORT_LAN + 1 -#define START_PORT_LAN_CL START_PORT_LAN + 2 -#define END_PORT_LAN START_PORT_LAN + 250//GameSpy only process 500 ports - -#define REGISTRY_BASE HKEY_LOCAL_MACHINE -#define REGISTRY_VALUE_GSCDKEY "InstallCDKEY" -#define REGISTRY_VALUE_VERSION "InstallVers" -#define REGISTRY_VALUE_USERNAME "InstallUserName" -#define REGISTRY_VALUE_SKU "InstallSource" -#define REGISTRY_VALUE_INSTALL_PATCH_ID "InstallPatchID" -#define REGISTRY_VALUE_LANGUAGE "InstallLang" -#define REGISTRY_VALUE_USEREMAIL "GPUserEmail" -#define REGISTRY_VALUE_USERPASSWORD "GPUserPassword" -#define REGISTRY_VALUE_REMEMBER_PROFILE "GPRememberMe" - -#define GAMESPY_PATCHING_VERSIONUNIQUE_ID "test_version_1" -#define GAMESPY_PATCHING_DISTRIBUTION_ID 0 +#define GAMESPY_GP_NAMESPACE_ID 1 /*gamespy global namespace*/ + +#define GAMESPY_QR2_BASEPORT 5445 +#define GAMESPY_BROWSER_MAX_UPDATES 20 + +#define START_PORT 0 +#define END_PORT 65535 +#define START_PORT_LAN GAMESPY_QR2_BASEPORT +#define START_PORT_LAN_SV START_PORT_LAN + 1 +#define START_PORT_LAN_CL START_PORT_LAN + 2 +#define END_PORT_LAN START_PORT_LAN + 250 // GameSpy only process 500 ports + +#define REGISTRY_BASE HKEY_LOCAL_MACHINE +#define REGISTRY_VALUE_GSCDKEY "InstallCDKEY" +#define REGISTRY_VALUE_VERSION "InstallVers" +#define REGISTRY_VALUE_USERNAME "InstallUserName" +#define REGISTRY_VALUE_SKU "InstallSource" +#define REGISTRY_VALUE_INSTALL_PATCH_ID "InstallPatchID" +#define REGISTRY_VALUE_LANGUAGE "InstallLang" +#define REGISTRY_VALUE_USEREMAIL "GPUserEmail" +#define REGISTRY_VALUE_USERPASSWORD "GPUserPassword" +#define REGISTRY_VALUE_REMEMBER_PROFILE "GPRememberMe" + +#define GAMESPY_PATCHING_VERSIONUNIQUE_ID "test_version_1" +#define GAMESPY_PATCHING_DISTRIBUTION_ID 0