diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp index 63c4cdbd3..d8d3d19e8 100644 --- a/core/ConVarManager.cpp +++ b/core/ConVarManager.cpp @@ -126,6 +126,8 @@ void ConVarManager::OnSourceModAllInitialized() } #endif + g_Players.AddClientListener(this); + SH_ADD_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false); g_PluginSys.AddPluginsListener(this); @@ -191,6 +193,8 @@ void ConVarManager::OnSourceModShutdown() } #endif + g_Players.RemoveClientListener(this); + SH_REMOVE_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false); /* Remove the 'convars' option from the 'sm' console command */ @@ -307,6 +311,22 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin) } } +void ConVarManager::OnClientDisconnected(int client) +{ + /* Remove convar queries for this client that haven't returned results yet */ + for (List::iterator iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) + { + ConVarQuery &query = (*iter); + if (query.client == client) + { + iter = m_ConVarQueries.erase(iter); + continue; + } + + ++iter; + } +} + void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) { } @@ -619,7 +639,7 @@ QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char return InvalidQueryCvarCookie; } - ConVarQuery query = {cookie, pCallback, hndl}; + ConVarQuery query = {cookie, pCallback, (cell_t)hndl, IndexOfEdict(pPlayer)}; m_ConVarQueries.push_back(query); #endif diff --git a/core/ConVarManager.h b/core/ConVarManager.h index 6c9ddc9a2..1d532d908 100644 --- a/core/ConVarManager.h +++ b/core/ConVarManager.h @@ -39,8 +39,10 @@ #include #include #include +#include #include #include "concmd_cleaner.h" +#include "PlayerManager.h" #if SOURCE_ENGINE == SE_DARKMESSIAH class EQueryCvarValueStatus; @@ -75,6 +77,7 @@ struct ConVarQuery QueryCvarCookie_t cookie; /**< Cookie that identifies query */ IPluginFunction *pCallback; /**< Function that will be called when query is finished */ cell_t value; /**< Optional value passed to query function */ + cell_t client; /**< Only used for cleaning up on client disconnection */ }; class ConVarManager : @@ -82,7 +85,8 @@ class ConVarManager : public IHandleTypeDispatch, public IPluginsListener, public IRootConsoleCommand, - public IConCommandTracker + public IConCommandTracker, + public IClientListener { public: ConVarManager(); @@ -101,6 +105,8 @@ public: //IRootConsoleCommand void OnRootConsoleCommand(const char *cmdname, const CCommand &command); public: //IConCommandTracker void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); +public: //IClientListener + void OnClientDisconnected(int client); public: /** * Create a convar and return a handle to it.