From 67e8a5b6462a5c2bc875da5ad6a422d908e84a63 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 Nov 2015 03:52:25 +0600 Subject: [PATCH] ReHLDS API: Implemented SV_DropClient hook --- rehlds/engine/host.cpp | 38 +++++++++++++++++-------------- rehlds/engine/host.h | 1 + rehlds/public/rehlds/rehlds_api.h | 5 ++++ rehlds/rehlds/rehlds_api_impl.cpp | 4 ++++ rehlds/rehlds/rehlds_api_impl.h | 6 +++++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/rehlds/engine/host.cpp b/rehlds/engine/host.cpp index 9e5c889..50c7e26 100644 --- a/rehlds/engine/host.cpp +++ b/rehlds/engine/host.cpp @@ -442,40 +442,44 @@ void Host_ClientCommands(const char *fmt, ...) va_end(argptr); } +void EXT_FUNC SV_DropClient_hook(IGameClient* cl, bool crash, const char *string) +{ + SV_DropClient_internal(cl->GetClient(), crash ? TRUE : FALSE, string); +} + void EXT_FUNC SV_DropClient_api(IGameClient* cl, bool crash, const char* fmt, ...) { char buf[1024]; va_list argptr; + va_start(argptr, fmt); - - Q_vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, (va_list)argptr); + Q_vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr); va_end(argptr); - buf[ARRAYSIZE(buf) - 1] = 0; - SV_DropClient(cl->GetClient(), crash ? TRUE : FALSE, "%s", buf); + g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, cl, crash, buf); +} + +void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...) +{ + char buf[1024]; + va_list argptr; + + va_start(argptr, fmt); + Q_vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr); + va_end(argptr); + + g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, GetRehldsApiClient(cl), crash != FALSE, buf); } /* <35f4e> ../engine/host.c:673 */ -void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...) +void SV_DropClient_internal(client_t *cl, qboolean crash, const char *string) { int i; - char string[1024]; unsigned char final[512]; float connection_time; - va_list argptr; - va_start(argptr, fmt); i = 0; -#ifdef REHLDS_CHECKS - Q_vsnprintf(string, sizeof(string) - 1, fmt, (va_list)argptr); - string[sizeof(string) - 1] = 0; -#else - Q_vsnprintf(string, sizeof(string), fmt, (va_list)argptr); -#endif // REHLDS_CHECKS - - va_end(argptr); - if (!crash) { if (!cl->fakeclient) diff --git a/rehlds/engine/host.h b/rehlds/engine/host.h index f6232b6..4794b08 100644 --- a/rehlds/engine/host.h +++ b/rehlds/engine/host.h @@ -136,6 +136,7 @@ void SV_BroadcastPrintf(const char *fmt, ...); void Host_ClientCommands(const char *fmt, ...); void SV_DropClient_api(IGameClient* cl, bool crash, const char* fmt, ...); void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...); +void SV_DropClient_internal(client_t *cl, qboolean crash, const char *string); void Host_ClearClients(qboolean bFramesOnly); void Host_ShutdownServer(qboolean crash); void SV_ClearClientStates(void); diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index d8fe084..5ae051b 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -145,6 +145,10 @@ typedef IVoidHookChainRegistry IRehldsHook_SV_CheckConsistencyResponce; typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckConsistencyResponce; +//SV_DropClient hook +typedef IVoidHookChain IRehldsHook_SV_DropClient; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_DropClient; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -176,6 +180,7 @@ public: virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I() = 0; virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate() = 0; virtual IRehldsHookRegistry_SV_CheckConsistencyResponce* SV_CheckConsistencyResponce() = 0; + virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 6807620..229cafc 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -264,6 +264,10 @@ IRehldsHookRegistry_SV_CheckConsistencyResponce* CRehldsHookchains::SV_CheckCons return &m_SV_CheckConsistencyResponce; } +IRehldsHookRegistry_SV_DropClient* CRehldsHookchains::SV_DropClient() { + return &m_SV_DropClient; +} + int EXT_FUNC CRehldsApi::GetMajorVersion() { return REHLDS_API_VERSION_MAJOR; diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h index 6f1e27c..e5d1e78 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -139,6 +139,10 @@ typedef IVoidHookChainRegistryImpl CRehldsHook_SV_CheckConsistencyResponce; typedef IHookChainRegistryImpl CRehldsHookRegistry_SV_CheckConsistencyResponce; +//SV_DropClient hook +typedef IVoidHookChainImpl CRehldsHook_SV_DropClient; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_DropClient; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -168,6 +172,7 @@ public: CRehldsHookRegistry_PF_BuildSoundMsg_I m_PF_BuildSoundMsg_I; CRehldsHookRegistry_SV_WriteFullClientUpdate m_SV_WriteFullClientUpdate; CRehldsHookRegistry_SV_CheckConsistencyResponce m_SV_CheckConsistencyResponce; + CRehldsHookRegistry_SV_DropClient m_SV_DropClient; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -197,6 +202,7 @@ public: virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I(); virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate(); virtual IRehldsHookRegistry_SV_CheckConsistencyResponce* SV_CheckConsistencyResponce(); + virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient(); }; extern CRehldsHookchains g_RehldsHookchains;