Skip to content

Commit 94db95e

Browse files
committed
Reworked command_c module
- Fixed crash when entering just "say" or "say_team" into the server console - Fixed say filter parameter "teamonly" - Fixed typo (ConVar.set_bool) - Removed ConVar.set/get
1 parent 4e30f13 commit 94db95e

14 files changed

+174
-328
lines changed

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ Set(SOURCEPYTHON_COMMAND_MODULE_HEADERS
113113

114114
Set(SOURCEPYTHON_COMMAND_MODULE_SOURCES
115115
core/modules/commands/client_command_wrap.cpp
116-
core/modules/commands/command_wrap.cpp
117116
core/modules/commands/command_wrap_python.cpp
118117
core/modules/commands/say_command_wrap.cpp
119118
core/modules/commands/server_command_wrap.cpp

src/core/modules/commands/client_command_wrap.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
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;

src/core/modules/commands/client_command_wrap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class CClientCommandManager
4848
CClientCommandManager(const char* szName);
4949
~CClientCommandManager();
5050

51-
void add_callback(PyObject* pCallable);
52-
void remove_callback(PyObject* pCallable);
51+
void AddCallback(PyObject* pCallable);
52+
void RemoveCallback(PyObject* pCallable);
5353

54-
CommandReturn Dispatch(IPlayerInfo* pPlayerInfo, CICommand* ccommand);
54+
CommandReturn Dispatch(IPlayerInfo* pPlayerInfo, const CCommand& ccommand);
5555

5656
private:
5757
CUtlVector<object> m_vecCallables;

src/core/modules/commands/command_wrap.cpp

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/core/modules/commands/command_wrap.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626
#ifndef _COMMAND_WRAP_H
2727
#define _COMMAND_WRAP_H
2828

29-
//-----------------------------------------------------------------------------
30-
// Includes
31-
//-----------------------------------------------------------------------------
32-
#include "convar.h"
33-
#include "utlvector.h"
34-
#include "utility/sp_util.h"
35-
#include "utility/wrap_macros.h"
36-
3729
//-----------------------------------------------------------------------------
3830
// Return values.
3931
//-----------------------------------------------------------------------------
@@ -43,34 +35,4 @@ enum CommandReturn
4335
CONTINUE
4436
};
4537

46-
//-----------------------------------------------------------------------------
47-
// CICommand class.
48-
//-----------------------------------------------------------------------------
49-
class CICommand
50-
{
51-
public:
52-
CICommand();
53-
CICommand( const CCommand* command );
54-
55-
int get_arg_count();
56-
const char *get_arg_string();
57-
const char *get_command_string();
58-
const char *get_arg( int iIndex );
59-
60-
private:
61-
const CCommand* m_CCommand_ptr;
62-
};
63-
64-
//-----------------------------------------------------------------------------
65-
// Base Filter class.
66-
//-----------------------------------------------------------------------------
67-
class BaseFilters
68-
{
69-
public:
70-
void register_filter(PyObject* pCallable);
71-
void unregister_filter(PyObject* pCallable);
72-
73-
CUtlVector<object> m_vecCallables;
74-
};
75-
7638
#endif // _COMMAND_WRAP_H

0 commit comments

Comments
 (0)