3636#include " utility/call_python.h"
3737#include " boost/python/call.hpp"
3838#include " boost/shared_array.hpp"
39+ #include " modules/listeners/listenermanager.h"
3940
4041// -----------------------------------------------------------------------------
4142// Global Client command mapping.
@@ -46,12 +47,12 @@ ClientCommandMap g_ClientCommandMap;
4647// -----------------------------------------------------------------------------
4748// Static singletons.
4849// -----------------------------------------------------------------------------
49- static BaseFilters s_ClientCommandFilters;
50+ static CListenerManager s_ClientCommandFilters;
5051
5152// -----------------------------------------------------------------------------
5253// Returns a CClientCommandManager for the given command name.
5354// -----------------------------------------------------------------------------
54- CClientCommandManager* get_client_command (const char * szName)
55+ CClientCommandManager* GetClientCommand (const char * szName)
5556{
5657 // Find if the given name is a registered client command
5758 ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find (szName);
@@ -87,17 +88,17 @@ void RemoveCClientCommandManager(const char* szName)
8788// -----------------------------------------------------------------------------
8889// Register function for client command filter.
8990// -----------------------------------------------------------------------------
90- void register_client_command_filter (PyObject* pCallable)
91+ void RegisterClientCommandFilter (PyObject* pCallable)
9192{
92- s_ClientCommandFilters.register_filter (pCallable);
93+ s_ClientCommandFilters.RegisterListener (pCallable);
9394}
9495
9596// -----------------------------------------------------------------------------
9697// Unregister function for client command filter.
9798// -----------------------------------------------------------------------------
98- void unregister_client_command_filter (PyObject* pCallable)
99+ void UnregisterClientCommandFilter (PyObject* pCallable)
99100{
100- s_ClientCommandFilters.unregister_filter (pCallable);
101+ s_ClientCommandFilters.UnregisterListener (pCallable);
101102}
102103
103104// -----------------------------------------------------------------------------
@@ -108,9 +109,6 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
108109 // Get the IPlayerInfo instance of the player
109110 IPlayerInfo* pPlayerInfo = playerinfomanager->GetPlayerInfo (pEntity);
110111
111- // Get the CICommand instance of the CCommand
112- CICommand* ccommand = new CICommand (&command);
113-
114112 // Loop through all registered Client Command Filters
115113 for (int i = 0 ; i < s_ClientCommandFilters.m_vecCallables .Count (); i++)
116114 {
@@ -120,7 +118,7 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
120118 PyObject* pCallable = s_ClientCommandFilters.m_vecCallables [i].ptr ();
121119
122120 // Call the callable and store its return value
123- object returnValue = CALL_PY_FUNC (pCallable, pPlayerInfo, ccommand );
121+ object returnValue = CALL_PY_FUNC (pCallable, pPlayerInfo, boost::ref (command) );
124122
125123 // Does the Client Command Filter want to block the command?
126124 if ( !returnValue.is_none () && extract<int >(returnValue) == (int )BLOCK)
@@ -143,7 +141,7 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
143141 CClientCommandManager* pCClientCommandManager = commandMapIter->second ;
144142
145143 // Does the command need to be blocked?
146- if ( !pCClientCommandManager->Dispatch (pPlayerInfo, ccommand ))
144+ if ( !pCClientCommandManager->Dispatch (pPlayerInfo, boost::ref (command) ))
147145 {
148146 // Block the command
149147 return PLUGIN_STOP;
@@ -171,7 +169,7 @@ CClientCommandManager::~CClientCommandManager()
171169// -----------------------------------------------------------------------------
172170// Adds a callable to a CClientCommandManager instance.
173171// -----------------------------------------------------------------------------
174- void CClientCommandManager::add_callback ( PyObject* pCallable )
172+ void CClientCommandManager::AddCallback ( PyObject* pCallable )
175173{
176174 // Get the object instance of the callable
177175 object oCallable = object (handle<>(borrowed (pCallable)));
@@ -187,7 +185,7 @@ void CClientCommandManager::add_callback( PyObject* pCallable )
187185// -----------------------------------------------------------------------------
188186// Removes a callable from a CClientCommandManager instance.
189187// -----------------------------------------------------------------------------
190- void CClientCommandManager::remove_callback ( PyObject* pCallable )
188+ void CClientCommandManager::RemoveCallback ( PyObject* pCallable )
191189{
192190 // Get the object instance of the callable
193191 object oCallable = object (handle<>(borrowed (pCallable)));
@@ -206,7 +204,7 @@ void CClientCommandManager::remove_callback( PyObject* pCallable )
206204// -----------------------------------------------------------------------------
207205// Calls all callables for the command when it is called on the client.
208206// -----------------------------------------------------------------------------
209- CommandReturn CClientCommandManager::Dispatch ( IPlayerInfo* pPlayerInfo, CICommand* ccommand )
207+ CommandReturn CClientCommandManager::Dispatch ( IPlayerInfo* pPlayerInfo, const CCommand& command )
210208{
211209 // Loop through all callables registered for the CClientCommandManager instance
212210 for (int i = 0 ; i < m_vecCallables.Count (); i++)
@@ -217,10 +215,10 @@ CommandReturn CClientCommandManager::Dispatch( IPlayerInfo* pPlayerInfo, CIComma
217215 PyObject* pCallable = m_vecCallables[i].ptr ();
218216
219217 // Call the callable and store its return value
220- object returnValue = CALL_PY_FUNC (pCallable, pPlayerInfo, ccommand );
218+ object returnValue = CALL_PY_FUNC (pCallable, pPlayerInfo, boost::ref (command) );
221219
222220 // Does the callable wish to block the command?
223- if ( !returnValue.is_none () && extract<int >(returnValue) == (int )BLOCK)
221+ if ( !returnValue.is_none () && extract<int >(returnValue) == (int ) BLOCK)
224222 {
225223 // Block the command
226224 return BLOCK;
0 commit comments