From 36d6311eafd6ea6a49474ef6e0c3ab29b8447c00 Mon Sep 17 00:00:00 2001 From: bionext03 Date: Wed, 20 Oct 2021 16:09:08 +0000 Subject: [PATCH] Add ClientConnected hook (#223) Add `ClientConnected()` hook. Called after processing a client connection request. --- .../amxmodx/scripting/include/reapi_engine_const.inc | 6 ++++++ reapi/src/hook_callback.cpp | 10 ++++++++++ reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 3 ++- reapi/src/hook_list.h | 3 ++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 180e8c6..c9cd95f 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -53,6 +53,12 @@ enum EngineFunc * Params: (const client, buffer, const receiver) */ RH_SV_WriteFullClientUpdate, + + /* + * Description: Called after processing a client connection request. + * Params: (const client) + */ + RH_ClientConnected, }; /** diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 9941d50..6d9c697 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -63,6 +63,16 @@ void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGame SV_WriteFullClientUpdate_AMXX(&data, client, (size_t)buffer, receiver); } +void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl) +{ + auto original = [chain](int client) + { + chain->callNext(g_RehldsSvs->GetClient(client - 1)); + }; + + callVoidForward(RH_ClientConnected, original, cl->GetId() + 1); +} + /* * ReGameDLL functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 3dc3f6e..88154e9 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -331,6 +331,7 @@ void SV_StartSound(IRehldsHook_SV_StartSound *chain, int recipients, edict_t *en void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *fmt); void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics); void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value); +void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl); struct SV_WriteFullClientUpdate_args_t { diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index bf52208..5d7a436 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -86,7 +86,8 @@ hook_t hooklist_engine[] = { ENG(SV_DropClient), ENG(SV_ActivateServer), ENG(Cvar_DirectSet), - ENG(SV_WriteFullClientUpdate, _AMXX) + ENG(SV_WriteFullClientUpdate, _AMXX), + ENG(ClientConnected) }; #define DLL(h,...) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_ReGameHookchains->h()->registerHook(&h); }, [](){ g_ReGameHookchains->h()->unregisterHook(&h); }, false} diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index c95cd47..8f2039e 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -97,7 +97,8 @@ enum EngineFunc RH_SV_DropClient, RH_SV_ActivateServer, RH_Cvar_DirectSet, - RH_SV_WriteFullClientUpdate + RH_SV_WriteFullClientUpdate, + RH_ClientConnected // [...] };