fix player disconnect hook firing on mapchange

bump version
This commit is contained in:
BotoX 2018-09-06 19:03:52 +02:00
parent 3cf54e32eb
commit cc68fe8e3c
3 changed files with 30 additions and 14 deletions

View File

@ -41,6 +41,7 @@
*/ */
Connect g_Connect; /**< Global singleton for extension's main interface */ Connect g_Connect; /**< Global singleton for extension's main interface */
ConnectEvents g_ConnectEvents;
SMEXT_LINK(&g_Connect); SMEXT_LINK(&g_Connect);
@ -50,6 +51,7 @@ ConVar g_SvForceSteam("sv_forcesteam", "0", FCVAR_NOTIFY, "Force steam authentic
IGameConfig *g_pGameConf = NULL; IGameConfig *g_pGameConf = NULL;
IForward *g_pConnectForward = NULL; IForward *g_pConnectForward = NULL;
IGameEventManager2 *g_pGameEvents = NULL;
class IClient; class IClient;
class CBaseClient; 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); 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; return true;
} }
bool Connect::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) 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); GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
ConVar_Register(0, this); ConVar_Register(0, this);
@ -560,7 +563,7 @@ void Connect::SDK_OnUnload()
g_Detour_CSteam3Server__OnValidateAuthTicketResponse = NULL; g_Detour_CSteam3Server__OnValidateAuthTicketResponse = NULL;
} }
playerhelpers->RemoveClientListener(&g_Connect); g_pGameEvents->RemoveListener(&g_ConnectEvents);
gameconfs->CloseGameConfigFile(g_pGameConf); gameconfs->CloseGameConfigFile(g_pGameConf);
} }
@ -646,13 +649,21 @@ void Connect::SDK_OnAllLoaded()
sharesys->AddNatives(myself, MyNatives); sharesys->AddNatives(myself, MyNatives);
} }
void Connect::OnClientDisconnecting(int client) void ConnectEvents::FireGameEvent(IGameEvent *event)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); const char *name = event->GetName();
if(pPlayer)
if(strcmp(name, "player_disconnect") == 0)
{ {
const char *pSteamID = pPlayer->GetSteam2Id(false); int userid = event->GetInt("userid");
g_pSM->LogMessage(myself, "%s OnClientDisconnecting: %d", pSteamID, client); int client = playerhelpers->GetClientOfUserId(userid);
g_ConnectClientStorage.remove(pSteamID);
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);
}
} }
} }

View File

@ -38,6 +38,7 @@
*/ */
#include "smsdk_ext.h" #include "smsdk_ext.h"
#include <igameevents.h>
/** /**
@ -46,8 +47,7 @@
*/ */
class Connect : class Connect :
public SDKExtension, public SDKExtension,
public IConCommandBaseAccessor, public IConCommandBaseAccessor
public IClientListener
{ {
public: public:
/** /**
@ -120,9 +120,14 @@ public:
public: // IConCommandBaseAccessor public: // IConCommandBaseAccessor
virtual bool RegisterConCommandBase(ConCommandBase *pVar); 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_ #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_

View File

@ -40,7 +40,7 @@
/* Basic information exposed publicly */ /* Basic information exposed publicly */
#define SMEXT_CONF_NAME "Connect" #define SMEXT_CONF_NAME "Connect"
#define SMEXT_CONF_DESCRIPTION "Forward for early connection" #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_AUTHOR "Asher \"asherkin\" Baker + BotoX"
#define SMEXT_CONF_URL "https://github.com/CSSZombieEscape/sm-ext-connect" #define SMEXT_CONF_URL "https://github.com/CSSZombieEscape/sm-ext-connect"
#define SMEXT_CONF_LOGTAG "CONNECT" #define SMEXT_CONF_LOGTAG "CONNECT"