From cc68fe8e3ce3da2b6c5c4a3d088bc733008db847 Mon Sep 17 00:00:00 2001 From: BotoX Date: Thu, 6 Sep 2018 19:03:52 +0200 Subject: [PATCH] fix player disconnect hook firing on mapchange bump version --- extension.cpp | 27 +++++++++++++++++++-------- extension.h | 15 ++++++++++----- smsdk_config.h | 2 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/extension.cpp b/extension.cpp index 7723efa..6e45c21 100644 --- a/extension.cpp +++ b/extension.cpp @@ -41,6 +41,7 @@ */ Connect g_Connect; /**< Global singleton for extension's main interface */ +ConnectEvents g_ConnectEvents; SMEXT_LINK(&g_Connect); @@ -50,6 +51,7 @@ ConVar g_SvForceSteam("sv_forcesteam", "0", FCVAR_NOTIFY, "Force steam authentic IGameConfig *g_pGameConf = NULL; IForward *g_pConnectForward = NULL; +IGameEventManager2 *g_pGameEvents = NULL; class IClient; class CBaseClient; @@ -521,13 +523,14 @@ bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late) g_pConnectForward = g_pForwards->CreateForward("OnClientPreConnectEx", ET_LowEvent, 5, NULL, Param_String, Param_String, Param_String, Param_String, Param_String); - playerhelpers->AddClientListener(&g_Connect); + g_pGameEvents->AddListener(&g_ConnectEvents, "player_disconnect", true); return true; } bool Connect::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) { + GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameEvents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2); GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION); ConVar_Register(0, this); @@ -560,7 +563,7 @@ void Connect::SDK_OnUnload() g_Detour_CSteam3Server__OnValidateAuthTicketResponse = NULL; } - playerhelpers->RemoveClientListener(&g_Connect); + g_pGameEvents->RemoveListener(&g_ConnectEvents); gameconfs->CloseGameConfigFile(g_pGameConf); } @@ -646,13 +649,21 @@ void Connect::SDK_OnAllLoaded() sharesys->AddNatives(myself, MyNatives); } -void Connect::OnClientDisconnecting(int client) +void ConnectEvents::FireGameEvent(IGameEvent *event) { - IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); - if(pPlayer) + const char *name = event->GetName(); + + if(strcmp(name, "player_disconnect") == 0) { - const char *pSteamID = pPlayer->GetSteam2Id(false); - g_pSM->LogMessage(myself, "%s OnClientDisconnecting: %d", pSteamID, client); - g_ConnectClientStorage.remove(pSteamID); + int userid = event->GetInt("userid"); + int client = playerhelpers->GetClientOfUserId(userid); + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if(pPlayer) + { + const char *pSteamID = pPlayer->GetSteam2Id(false); + g_pSM->LogMessage(myself, "%s OnClientDisconnecting: %d", pSteamID, client); + g_ConnectClientStorage.remove(pSteamID); + } } } diff --git a/extension.h b/extension.h index 05b0a5c..25c1f0b 100644 --- a/extension.h +++ b/extension.h @@ -38,6 +38,7 @@ */ #include "smsdk_ext.h" +#include /** @@ -46,8 +47,7 @@ */ class Connect : public SDKExtension, - public IConCommandBaseAccessor, - public IClientListener + public IConCommandBaseAccessor { public: /** @@ -120,9 +120,14 @@ public: public: // IConCommandBaseAccessor virtual bool RegisterConCommandBase(ConCommandBase *pVar); - -public: // IClientListener - void OnClientDisconnecting(int client); }; +class ConnectEvents : public IGameEventListener2 +{ +public: + virtual void FireGameEvent( IGameEvent *event ); +}; + +extern ConnectEvents g_ConnectEvents; + #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ diff --git a/smsdk_config.h b/smsdk_config.h index 68c41c9..c23d3e7 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -40,7 +40,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "Connect" #define SMEXT_CONF_DESCRIPTION "Forward for early connection" -#define SMEXT_CONF_VERSION "2.3" +#define SMEXT_CONF_VERSION "2.4" #define SMEXT_CONF_AUTHOR "Asher \"asherkin\" Baker + BotoX" #define SMEXT_CONF_URL "https://github.com/CSSZombieEscape/sm-ext-connect" #define SMEXT_CONF_LOGTAG "CONNECT"