Remove unfinished ConVar queries on client disconnect (bug 6003, r=psychonic).
authorKyle Sanderson <kyle.leet@gmail.com>
Thu Feb 27 19:55:13 2014 -0700 (2014-02-27)
changeset 4257fbe69cd9afdf
parent 4256 9f0db041581a
child 4258 3d7fa1d33f56
Remove unfinished ConVar queries on client disconnect (bug 6003, r=psychonic).
core/ConVarManager.cpp
core/ConVarManager.h
     1.1 --- a/core/ConVarManager.cpp	Thu Feb 27 20:22:01 2014 -0500
     1.2 +++ b/core/ConVarManager.cpp	Thu Feb 27 19:55:13 2014 -0700
     1.3 @@ -123,6 +123,8 @@
     1.4  	}
     1.5  #endif
     1.6  
     1.7 +	g_Players.AddClientListener(this);
     1.8 +
     1.9  #if SOURCE_ENGINE >= SE_ORANGEBOX
    1.10  	SH_ADD_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false);
    1.11  #else
    1.12 @@ -194,6 +196,8 @@
    1.13  	}
    1.14  #endif
    1.15  
    1.16 +	g_Players.RemoveClientListener(this);
    1.17 +
    1.18  #if SOURCE_ENGINE >= SE_ORANGEBOX
    1.19  	SH_REMOVE_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false);
    1.20  #else
    1.21 @@ -310,6 +314,22 @@
    1.22  	}
    1.23  }
    1.24  
    1.25 +void ConVarManager::OnClientDisconnected(int client)
    1.26 +{
    1.27 +	/* Remove convar queries for this client that haven't returned results yet */
    1.28 +	for (List<ConVarQuery>::iterator iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();)
    1.29 +	{
    1.30 +		ConVarQuery &query = (*iter);
    1.31 +		if (query.client == client)
    1.32 +		{
    1.33 +			iter = m_ConVarQueries.erase(iter);
    1.34 +			continue;
    1.35 +		}
    1.36 +
    1.37 +		++iter;
    1.38 +	}
    1.39 +}
    1.40 +
    1.41  void ConVarManager::OnHandleDestroy(HandleType_t type, void *object)
    1.42  {
    1.43  }
    1.44 @@ -628,7 +648,7 @@
    1.45  		return InvalidQueryCvarCookie;
    1.46  	}
    1.47  
    1.48 -	ConVarQuery query = {cookie, pCallback, (cell_t)hndl};
    1.49 +	ConVarQuery query = {cookie, pCallback, (cell_t)hndl, IndexOfEdict(pPlayer)};
    1.50  	m_ConVarQueries.push_back(query);
    1.51  #endif
    1.52  
     2.1 --- a/core/ConVarManager.h	Thu Feb 27 20:22:01 2014 -0500
     2.2 +++ b/core/ConVarManager.h	Thu Feb 27 19:55:13 2014 -0700
     2.3 @@ -39,8 +39,10 @@
     2.4  #include <IForwardSys.h>
     2.5  #include <IHandleSys.h>
     2.6  #include <IRootConsoleMenu.h>
     2.7 +#include <IPlayerHelpers.h>
     2.8  #include <compat_wrappers.h>
     2.9  #include "concmd_cleaner.h"
    2.10 +#include "PlayerManager.h"
    2.11  
    2.12  #if SOURCE_ENGINE == SE_DARKMESSIAH
    2.13  class EQueryCvarValueStatus;
    2.14 @@ -80,6 +82,7 @@
    2.15  	QueryCvarCookie_t cookie;			/**< Cookie that identifies query */
    2.16  	IPluginFunction *pCallback;			/**< Function that will be called when query is finished */
    2.17  	cell_t value;						/**< Optional value passed to query function */
    2.18 +	cell_t client;						/**< Only used for cleaning up on client disconnection */
    2.19  };
    2.20  
    2.21  class ConVarManager :
    2.22 @@ -87,7 +90,8 @@
    2.23  	public IHandleTypeDispatch,
    2.24  	public IPluginsListener,
    2.25  	public IRootConsoleCommand,
    2.26 -	public IConCommandTracker
    2.27 +	public IConCommandTracker,
    2.28 +	public IClientListener
    2.29  {
    2.30  public:
    2.31  	ConVarManager();
    2.32 @@ -106,6 +110,8 @@
    2.33  	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    2.34  public: //IConCommandTracker
    2.35  	void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
    2.36 +public: //IClientListener
    2.37 +	void OnClientDisconnected(int client);
    2.38  public:
    2.39  	/**
    2.40  	 * Create a convar and return a handle to it.