From c2d311c6dfb3f9da72cfc2cb9fdb311428ced15e Mon Sep 17 00:00:00 2001 From: Asmodai Date: Thu, 27 Sep 2018 01:00:11 +0300 Subject: [PATCH] Add hookchain for connectionless limiter --- rehlds/engine/sv_main.cpp | 2 +- rehlds/public/rehlds/rehlds_api.h | 7 ++++++- rehlds/rehlds/rehlds_api_impl.cpp | 5 +++++ rehlds/rehlds/rehlds_api_impl.h | 20 +++++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index c22a672..9e777e2 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -3599,7 +3599,7 @@ void SV_ReadPackets(void) if (*(uint32 *)net_message.data == 0xFFFFFFFF) { // Connectionless packet - if (SV_CheckConnectionLessRateLimits(net_from)) + if (g_RehldsHookchains.m_SV_CheckConnectionLessRateLimits.callChain([](netadr_t& net_from, const uint8_t *, int) { return SV_CheckConnectionLessRateLimits(net_from); }, net_from, net_message.data, net_message.cursize)) { Steam_HandleIncomingPacket(net_message.data, net_message.cursize, ntohl(*(u_long *)&net_from.ip[0]), htons(net_from.port)); SV_ConnectionlessPacket(); diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index a32af12..4d40262 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -37,7 +37,7 @@ #include "pr_dlls.h" #define REHLDS_API_VERSION_MAJOR 3 -#define REHLDS_API_VERSION_MINOR 4 +#define REHLDS_API_VERSION_MINOR 5 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -195,6 +195,10 @@ typedef IHookChainRegistry IRehldsHook_CreateFakeClient; typedef IHookChainRegistry IRehldsHookRegistry_CreateFakeClient; +//SV_CheckConnectionLessRateLimits +typedef IHookChain IRehldsHook_SV_CheckConnectionLessRateLimits; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckConnectionLessRateLimits; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -238,6 +242,7 @@ public: virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0; virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2() = 0; virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient() = 0; + virtual IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* SV_CheckConnectionLessRateLimits() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 79ff00d..5cb219a 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -571,6 +571,11 @@ IRehldsHookRegistry_CreateFakeClient* CRehldsHookchains::CreateFakeClient() { return &m_CreateFakeClient; } +IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* CRehldsHookchains::SV_CheckConnectionLessRateLimits() +{ + return &m_SV_CheckConnectionLessRateLimits; +} + 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 17f7d78..296ce4b 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -190,6 +190,10 @@ typedef IHookChainRegistryImpl CRehldsHook_CreateFakeClient; typedef IHookChainRegistryImpl CRehldsHookRegistry_CreateFakeClient; +//SV_CheckConnectionLessRateLimits hook +typedef IHookChainImpl CRehldsHook_SV_CheckConnectionLessRateLimits; +typedef IHookChainRegistryImpl CRehldsHookRegistry_SV_CheckConnectionLessRateLimits; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -231,6 +235,7 @@ public: CRehldsHookRegistry_SV_CreatePacketEntities m_SV_CreatePacketEntities; CRehldsHookRegistry_SV_EmitSound2 m_SV_EmitSound2; CRehldsHookRegistry_CreateFakeClient m_CreateFakeClient; + CRehldsHookRegistry_SV_CheckConnectionLessRateLimits m_SV_CheckConnectionLessRateLimits; public: EXT_FUNC virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -260,18 +265,19 @@ public: EXT_FUNC virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I(); EXT_FUNC virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate(); EXT_FUNC virtual IRehldsHookRegistry_SV_CheckConsistencyResponse* SV_CheckConsistencyResponse(); - EXT_FUNC virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient(); - EXT_FUNC virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer(); - EXT_FUNC virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec(); + EXT_FUNC virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient(); + EXT_FUNC virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer(); + EXT_FUNC virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec(); EXT_FUNC virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID(); EXT_FUNC virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo(); EXT_FUNC virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData(); EXT_FUNC virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet(); EXT_FUNC virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase(); - EXT_FUNC virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f(); - EXT_FUNC virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities(); - EXT_FUNC virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2(); - EXT_FUNC virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient(); + EXT_FUNC virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f(); + EXT_FUNC virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities(); + EXT_FUNC virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2(); + EXT_FUNC virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient(); + EXT_FUNC virtual IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* SV_CheckConnectionLessRateLimits(); }; extern CRehldsHookchains g_RehldsHookchains;