Skip to content

Commit 7c8537c

Browse files
committed
- Eased creating listeners
- Fixed issue with sp credits
1 parent 060e0e5 commit 7c8537c

File tree

8 files changed

+76
-358
lines changed

8 files changed

+76
-358
lines changed

addons/source-python/packages/source-python/_core/command.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def delay_execution(*args):
127127
def print_version():
128128
'''Displays Source.Python version information.'''
129129

130-
@staticmethod
131-
def print_credits():
130+
def print_credits(self):
132131
'''Lists all credits for Source.Python.'''
133132

134133
# Get header messages
@@ -156,7 +155,7 @@ def print_credits():
156155
message += '\n'
157156

158157
# Print the message
159-
_CoreCommandsLogger.log_message(message + '=' * 61 + '\n\n')
158+
self.logger.log_message(message + '=' * 61 + '\n\n')
160159

161160
SPSubCommandManager = _SPSubCommandManager('sp', 'Source.Python base command.')
162161

@@ -176,4 +175,4 @@ def print_credits():
176175
SPSubCommandManager['list'] = SPSubCommandManager.print_plugins
177176
SPSubCommandManager['version'] = SPSubCommandManager.print_version
178177
SPSubCommandManager['credits'] = SPSubCommandManager.print_credits
179-
SPSubCommandManager['help'] = SPSubCommandManager.print_help
178+
SPSubCommandManager['help'] = SPSubCommandManager.print_help

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,10 @@ Set(SOURCEPYTHON_PLAYERS_MODULE_SOURCES
249249
# Listener module
250250
# ------------------------------------------------------------------
251251
Set(SOURCEPYTHON_LISTENERS_MODULE_HEADERS
252-
core/modules/listeners/listeners.h
253252
core/modules/listeners/listenermanager.h
254253
)
255254

256255
Set(SOURCEPYTHON_LISTENERS_MODULE_SOURCES
257-
core/modules/listeners/listeners.cpp
258256
core/modules/listeners/listenermanager.cpp
259257
core/modules/listeners/listeners_wrap_python.cpp
260258
)

src/core/addons/sp_addon.cpp

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include "filesystem.h"
3434
#include "core/sp_gamedir.h"
3535
#include "utility/wrap_macros.h"
36-
#include "modules/listeners/listeners.h"
36+
#include "modules/listeners/listenermanager.h"
37+
#include "modules/entities/entities_wrap.h"
3738

3839
//---------------------------------------------------------------------------------
3940
// External variables
@@ -66,27 +67,23 @@ CAddonManager::~CAddonManager( void )
6667
//---------------------------------------------------------------------------------
6768
void CAddonManager::GameFrame()
6869
{
69-
// Dispatch all tick listeners
70-
get_tick_listener_manager()->call_listeners();
70+
CALL_LISTENERS(get_tick_listener_manager());
7171
}
7272

7373
//---------------------------------------------------------------------------------
7474
// Calls network id validated listeners.
7575
//---------------------------------------------------------------------------------
7676
void CAddonManager::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
7777
{
78-
// Dispatch all NetwordIDValidatedListeners
79-
get_networkid_validated_listener_manager()->call_listeners(pszUserName, pszNetworkID);
78+
CALL_LISTENERS(get_networkid_validated_listener_manager(), pszUserName, pszNetworkID);
8079
}
8180

82-
8381
//---------------------------------------------------------------------------------
8482
// Calls level init listeners.
8583
//---------------------------------------------------------------------------------
8684
void CAddonManager::LevelInit( char const *pMapName )
8785
{
88-
// Dispatch all LevelInit listeners
89-
get_level_init_listener_manager()->call_listeners(pMapName);
86+
CALL_LISTENERS(get_level_init_listener_manager(), pMapName);
9087
}
9188

9289
//---------------------------------------------------------------------------------
@@ -95,54 +92,52 @@ void CAddonManager::LevelInit( char const *pMapName )
9592
// TODO: will not work if this is really a list
9693
void CAddonManager::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
9794
{
98-
// Dispatch all LevelInit listeners
99-
get_server_activate_listener_manager()->call_listeners(pEdictList, edictCount, clientMax);
95+
CEdict edict = CEdict(pEdictList);
96+
CALL_LISTENERS(get_server_activate_listener_manager(), edict, edictCount, clientMax);
10097
}
10198

10299
//---------------------------------------------------------------------------------
103100
// Calls level shutdown listeners.
104101
//---------------------------------------------------------------------------------
105102
void CAddonManager::LevelShutdown( void )
106103
{
107-
// Dispatch all tick listeners
108-
get_level_shutdown_listener_manager()->call_listeners();
104+
CALL_LISTENERS(get_level_shutdown_listener_manager());
109105
}
110106

111-
112107
//---------------------------------------------------------------------------------
113108
// Calls client active listeners.
114109
//---------------------------------------------------------------------------------
115110
void CAddonManager::ClientActive( edict_t *pEntity )
116111
{
117-
// Dispatch all LevelInit listeners
118-
get_client_active_listener_manager()->call_listeners(pEntity);
112+
CEdict edict = CEdict(pEntity);
113+
CALL_LISTENERS(get_client_active_listener_manager(), edict);
119114
}
120115

121116
//---------------------------------------------------------------------------------
122117
// Calls client disconnect listeners.
123118
//---------------------------------------------------------------------------------
124119
void CAddonManager::ClientDisconnect( edict_t *pEntity )
125120
{
126-
// Dispatch all LevelInit listeners
127-
get_client_disconnect_listener_manager()->call_listeners(pEntity);
121+
CEdict edict = CEdict(pEntity);
122+
CALL_LISTENERS(get_client_disconnect_listener_manager(), edict);
128123
}
129124

130125
//---------------------------------------------------------------------------------
131126
// Calls client put in server listeners.
132127
//---------------------------------------------------------------------------------
133128
void CAddonManager::ClientPutInServer( edict_t *pEntity, char const *playername )
134129
{
135-
// Dispatch all LevelInit listeners
136-
get_client_put_in_server_listener_manager()->call_listeners(pEntity, playername);
130+
CEdict edict = CEdict(pEntity);
131+
CALL_LISTENERS(get_client_put_in_server_listener_manager(), edict, playername);
137132
}
138133

139134
//---------------------------------------------------------------------------------
140135
// Calls client settings changed listeners.
141136
//---------------------------------------------------------------------------------
142137
void CAddonManager::ClientSettingsChanged( edict_t *pEdict )
143138
{
144-
// Dispatch all LevelInit listeners
145-
get_client_settings_changed_listener_manager()->call_listeners(pEdict);
139+
CEdict edict = CEdict(pEdict);
140+
CALL_LISTENERS(get_client_settings_changed_listener_manager(), edict);
146141
}
147142

148143
//---------------------------------------------------------------------------------
@@ -151,8 +146,8 @@ void CAddonManager::ClientSettingsChanged( edict_t *pEdict )
151146
void CAddonManager::ClientConnect( bool *bAllowConnect, edict_t *pEntity,
152147
const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
153148
{
154-
// Dispatch all LevelInit listeners
155-
get_client_connect_listener_manager()->call_listeners(bAllowConnect, pEntity, pszName, pszAddress, reject, maxrejectlen);
149+
CEdict edict = CEdict(pEntity);
150+
CALL_LISTENERS(get_client_connect_listener_manager(), *bAllowConnect, edict, pszName, pszAddress, reject, maxrejectlen);
156151
}
157152

158153
//---------------------------------------------------------------------------------
@@ -162,29 +157,28 @@ void CAddonManager::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie,
162157
edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName,
163158
const char *pCvarValue )
164159
{
165-
166-
// Dispatch all LevelInit listeners
167-
get_client_fully_connect_listener_manager()->call_listeners(iCookie, pPlayerEntity, eStatus, pCvarName, pCvarValue);
160+
CEdict edict = CEdict(pPlayerEntity);
161+
CALL_LISTENERS(get_on_query_cvar_value_finished_listener_manager(), (int) iCookie, edict, eStatus, pCvarName, pCvarValue);
168162
}
169163
//
170164
//
171165
//
172166
#if(SOURCE_ENGINE >= 3)
173167
void CAddonManager::ClientFullyConnect( edict_t *pEntity )
174168
{
175-
// Dispatch all LevelInit listeners
176-
get_client_fully_connect_listener_manager()->call_listeners(pEntity);
169+
CEdict edict = CEdict(pEntity);
170+
CALL_LISTENERS(get_client_fully_connect_listener_manager(), edict);
177171
}
178172

179173
void CAddonManager::OnEdictAllocated( edict_t *edict )
180174
{
181-
// Dispatch all LevelInit listeners
182-
get_on_edict_allocated_listener_manager()->call_listeners(edict);
175+
CEdict edict = CEdict(pEntity);
176+
CALL_LISTENERS(get_on_edict_allocated_listener_manager(), edict);
183177
}
184178

185179
void CAddonManager::OnEdictFreed( const edict_t *edict )
186180
{
187-
// Dispatch all LevelInit listeners
188-
get_on_edict_freed_listener_manager()->call_listeners(const_cast<edict_t*>(edict));
181+
CEdict edict = CEdict(pEntity);
182+
CALL_LISTENERS(get_on_edict_freed_listener_manager(), edict);
189183
}
190184
#endif

src/core/modules/listeners/listenermanager.cpp

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@
22
// Includes
33
//-----------------------------------------------------------------------------
44
#include "listenermanager.h"
5-
#include "utility/call_python.h"
6-
#include "boost/python.hpp"
7-
#include "modules/entities/entities_wrap.h"
85

9-
//-----------------------------------------------------------------------------
10-
// Macros
11-
//-----------------------------------------------------------------------------
12-
13-
#define BEGIN_CALL_LISTENER() \
14-
for(int i = 0; i < m_vecCallables.Count(); i++) \
15-
{ \
16-
BEGIN_BOOST_PY() \
17-
PyObject* pCallable = m_vecCallables[i].ptr(); \
18-
19-
#define END_CALL_LISTENER( ... ) \
20-
END_BOOST_PY_NORET() \
21-
}
226

237
//-----------------------------------------------------------------------------
248
// Adds a callable to the end of the CListenerManager vector.
@@ -46,90 +30,4 @@ void CListenerManager::unregister_listener(PyObject* pCallable)
4630

4731
// Remove the callback from the ServerCommandManager instance
4832
m_vecCallables.FindAndRemove(oCallable);
49-
}
50-
51-
//-----------------------------------------------------------------------------
52-
// Calls all registered listeners.
53-
//-----------------------------------------------------------------------------
54-
55-
void CListenerManager::call_listeners()
56-
{
57-
BEGIN_CALL_LISTENER()
58-
CALL_PY_FUNC(pCallable);
59-
END_CALL_LISTENER()
60-
}
61-
62-
void CListenerManager::call_listeners( edict_t *pEntity )
63-
{
64-
CEdict *entity = new CEdict(pEntity);
65-
66-
BEGIN_CALL_LISTENER()
67-
// Call the callable
68-
CALL_PY_FUNC(pCallable, entity);
69-
END_CALL_LISTENER()
70-
}
71-
72-
// LevelIinit
73-
void CListenerManager::call_listeners(char const *pMapName)
74-
{
75-
BEGIN_CALL_LISTENER()
76-
// Call the callable
77-
CALL_PY_FUNC(pCallable, pMapName);
78-
END_CALL_LISTENER()
79-
}
80-
81-
// ClientFullyConnect
82-
void CListenerManager::call_listeners( edict_t *pEntity, const char *playername )
83-
{
84-
CEdict *entity = new CEdict(pEntity);
85-
86-
BEGIN_CALL_LISTENER()
87-
// Call the callable
88-
CALL_PY_FUNC(pCallable, entity, playername);
89-
END_CALL_LISTENER()
90-
}
91-
92-
// NetworkID
93-
void CListenerManager::call_listeners(const char *pszUserName, const char *pszNetworkID)
94-
{
95-
BEGIN_CALL_LISTENER()
96-
// Call the callable
97-
CALL_PY_FUNC(pCallable, pszUserName, pszNetworkID);
98-
END_CALL_LISTENER()
99-
}
100-
101-
// ServerActivate
102-
void CListenerManager::call_listeners(edict_t *pEdictList, int edictCount, int clientMax)
103-
{
104-
// TODO? Edictlist
105-
CEdict *entity = new CEdict(pEdictList);
106-
107-
BEGIN_CALL_LISTENER()
108-
CALL_PY_FUNC(pCallable, entity, edictCount, clientMax);
109-
END_CALL_LISTENER()
110-
}
111-
// ClientConnect
112-
void CListenerManager::call_listeners(bool *bAllowConnect, edict_t *pEntity,
113-
const char *pszName, const char *pszAddress, char *reject,
114-
int maxrejectlen)
115-
{
116-
bool bAllowConnect_safe = &bAllowConnect;
117-
CEdict *entity = new CEdict(pEntity);
118-
const char *reject_safe = reject;
119-
120-
BEGIN_CALL_LISTENER()
121-
CALL_PY_FUNC(pCallable, bAllowConnect_safe, entity, pszName, pszAddress, reject_safe, maxrejectlen);
122-
END_CALL_LISTENER()
123-
}
124-
// OnQueryCvarValueFinished
125-
void CListenerManager::call_listeners(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity,
126-
EQueryCvarValueStatus eStatus, const char *pCvarName,
127-
const char *pCvarValue)
128-
{
129-
int cookie = (int)iCookie;
130-
CEdict *entity = new CEdict(pPlayerEntity);
131-
132-
BEGIN_CALL_LISTENER()
133-
CALL_PY_FUNC(pCallable, cookie, entity, eStatus, pCvarName, pCvarValue);
134-
END_CALL_LISTENER()
13533
}

0 commit comments

Comments
 (0)