Skip to content

Commit ab547c5

Browse files
committed
Changed argument order of say and client command callbacks
Moreover an index is passed now (instead of a PlayerInfo object)
1 parent 6f81358 commit ab547c5

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

addons/source-python/packages/source-python/commands/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# Source.Python Imports
99
# Auth
1010
from auth.manager import auth_manager
11+
# Players
12+
from players.helpers import playerinfo_from_index
1113
# Hooks
1214
from hooks.exceptions import except_hooks
1315

@@ -38,7 +40,8 @@ def __call__(self, *args):
3840

3941
# Is the player authorized?
4042
if not auth_manager.is_player_authorized(
41-
args[0], self.level, self.permission, self.flag):
43+
playerinfo_from_index(args[1]), self.level, self.permission,
44+
self.flag):
4245

4346
# Is there fail callback?
4447
if self.fail_callback is not None:

src/core/modules/commands/commands_client.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "boost/python/call.hpp"
3737
#include "boost/shared_array.hpp"
3838
#include "modules/listeners/listeners_manager.h"
39+
#include "utilities/conversions.h"
40+
3941

4042
//-----------------------------------------------------------------------------
4143
// Externals
@@ -110,8 +112,7 @@ void UnregisterClientCommandFilter(PyObject* pCallable)
110112
//-----------------------------------------------------------------------------
111113
PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
112114
{
113-
// Get the IPlayerInfo instance of the player
114-
IPlayerInfo* pPlayerInfo = playerinfomanager->GetPlayerInfo(pEntity);
115+
int iIndex = IndexFromEdict(pEntity);
115116

116117
// Loop through all registered Client Command Filters
117118
for(int i = 0; i < s_ClientCommandFilters.m_vecCallables.Count(); i++)
@@ -122,7 +123,7 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
122123
PyObject* pCallable = s_ClientCommandFilters.m_vecCallables[i].ptr();
123124

124125
// Call the callable and store its return value
125-
object returnValue = CALL_PY_FUNC(pCallable, ptr(pPlayerInfo), boost::ref(command));
126+
object returnValue = CALL_PY_FUNC(pCallable, boost::ref(command), iIndex);
126127

127128
// Does the Client Command Filter want to block the command?
128129
if( !returnValue.is_none() && extract<int>(returnValue) == (int)BLOCK)
@@ -145,7 +146,7 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
145146
CClientCommandManager* pCClientCommandManager = commandMapIter->second;
146147

147148
// Does the command need to be blocked?
148-
if( !pCClientCommandManager->Dispatch(pPlayerInfo, command))
149+
if( !pCClientCommandManager->Dispatch(command, iIndex))
149150
{
150151
// Block the command
151152
return PLUGIN_STOP;
@@ -208,7 +209,7 @@ void CClientCommandManager::RemoveCallback( PyObject* pCallable )
208209
//-----------------------------------------------------------------------------
209210
// Calls all callables for the command when it is called on the client.
210211
//-----------------------------------------------------------------------------
211-
CommandReturn CClientCommandManager::Dispatch( IPlayerInfo* pPlayerInfo, const CCommand& command )
212+
CommandReturn CClientCommandManager::Dispatch( const CCommand& command, int iIndex )
212213
{
213214
// Loop through all callables registered for the CClientCommandManager instance
214215
for(int i = 0; i < m_vecCallables.Count(); i++)
@@ -219,7 +220,7 @@ CommandReturn CClientCommandManager::Dispatch( IPlayerInfo* pPlayerInfo, const C
219220
PyObject* pCallable = m_vecCallables[i].ptr();
220221

221222
// Call the callable and store its return value
222-
object returnValue = CALL_PY_FUNC(pCallable, ptr(pPlayerInfo), boost::ref(command));
223+
object returnValue = CALL_PY_FUNC(pCallable, boost::ref(command), iIndex);
223224

224225
// Does the callable wish to block the command?
225226
if( !returnValue.is_none() && extract<int>(returnValue) == (int) BLOCK)

src/core/modules/commands/commands_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CClientCommandManager
5252
void AddCallback(PyObject* pCallable);
5353
void RemoveCallback(PyObject* pCallable);
5454

55-
CommandReturn Dispatch(IPlayerInfo* pPlayerInfo, const CCommand& ccommand);
55+
CommandReturn Dispatch(const CCommand& ccommand, int iIndex);
5656

5757
private:
5858
CUtlVector<object> m_vecCallables;

src/core/modules/commands/commands_say.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "boost/shared_array.hpp"
3838
#include "sp_main.h"
3939
#include "modules/listeners/listeners_manager.h"
40-
#include "utilities/conversions.h"
4140
#include "convar.h"
4241

4342
//-----------------------------------------------------------------------------
@@ -222,9 +221,6 @@ void SayConCommand::Dispatch( const CCommand& command )
222221
// Get the index of the player that used the command
223222
int iIndex = GetCommandIndex();
224223

225-
// Get the IPlayerInfo instance of the player
226-
IPlayerInfo* pPlayerInfo = PlayerInfoFromIndex(iIndex);
227-
228224
// Get whether the command was say or say_team
229225
bool bTeamOnly = strcmp(command.Arg(0), "say_team") == 0;
230226

@@ -244,7 +240,7 @@ void SayConCommand::Dispatch( const CCommand& command )
244240
PyObject* pCallable = s_SayFilters.m_vecCallables[i].ptr();
245241

246242
// Call the callable and store its return value
247-
object returnValue = CALL_PY_FUNC(pCallable, ptr(pPlayerInfo), bTeamOnly, boost::ref(stripped_command));
243+
object returnValue = CALL_PY_FUNC(pCallable, boost::ref(stripped_command), iIndex, bTeamOnly);
248244

249245
// Does the current Say Filter wish to block the command?
250246
if( !returnValue.is_none() && extract<int>(returnValue) == (int) BLOCK)
@@ -283,7 +279,7 @@ void SayConCommand::Dispatch( const CCommand& command )
283279
CSayCommandManager* pCSayCommandManager = commandMapIter->second;
284280

285281
// Call the command and see it wants to block the command
286-
if( pCSayCommandManager->Dispatch(pPlayerInfo, bTeamOnly, stripped_command) == BLOCK)
282+
if( pCSayCommandManager->Dispatch(stripped_command, iIndex, bTeamOnly) == BLOCK)
287283
{
288284
// Block the command
289285
return;
@@ -353,7 +349,7 @@ void CSayCommandManager::RemoveCallback( PyObject* pCallable )
353349
//-----------------------------------------------------------------------------
354350
// Dispatches the say command.
355351
//-----------------------------------------------------------------------------
356-
CommandReturn CSayCommandManager::Dispatch( IPlayerInfo* pPlayerInfo, bool bTeamOnly, const CCommand& command )
352+
CommandReturn CSayCommandManager::Dispatch( const CCommand& command, int iIndex, bool bTeamOnly)
357353
{
358354
// Loop through all callables registered for the CSayCommandManager instance
359355
for(int i = 0; i < m_vecCallables.Count(); i++)
@@ -364,7 +360,7 @@ CommandReturn CSayCommandManager::Dispatch( IPlayerInfo* pPlayerInfo, bool bTeam
364360
PyObject* pCallable = m_vecCallables[i].ptr();
365361

366362
// Call the callable and store its return value
367-
object returnValue = CALL_PY_FUNC(pCallable, ptr(pPlayerInfo), bTeamOnly, boost::ref(command));
363+
object returnValue = CALL_PY_FUNC(pCallable, boost::ref(command), iIndex, bTeamOnly);
368364

369365
// Does the callable wish to block the command?
370366
if( !returnValue.is_none() && extract<int>(returnValue) == (int) BLOCK)

src/core/modules/commands/commands_say.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CSayCommandManager
8282
void AddCallback(PyObject* pCallable);
8383
void RemoveCallback(PyObject* pCallable);
8484

85-
CommandReturn Dispatch(IPlayerInfo* pPlayerInfo, bool bTeamOnly, const CCommand& ccommand);
85+
CommandReturn Dispatch(const CCommand& ccommand, int iIndex, bool bTeamOnly);
8686

8787
private:
8888
const char* m_Name;

0 commit comments

Comments
 (0)