Skip to content

Commit 97625a6

Browse files
committed
- Implemented the listeners in sp_addon.cpp [Some listeners will need extra work however!]
- Removed accidental commit of configure-csgo - Kopie.bat - Removed unnecessary inclusions in some files - Added client_connect listeners
1 parent 5d68949 commit 97625a6

18 files changed

+382
-27
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Set(SOURCEPYTHON_LISTENERS_MODULE_HEADERS
253253
core/modules/listeners/listenermanager.h
254254
# Listeners
255255
core/modules/listeners/client_active_listeners_wrap.h
256+
core/modules/listeners/client_connect_listeners_wrap.h
256257
core/modules/listeners/client_disconnect_listeners_wrap.h
257258
core/modules/listeners/client_fully_connect_listeners_wrap.h
258259
core/modules/listeners/client_put_in_server_listeners_wrap.h
@@ -272,6 +273,7 @@ Set(SOURCEPYTHON_LISTENERS_MODULE_SOURCES
272273
core/modules/listeners/listeners_wrap_python.cpp
273274
# Listeners
274275
core/modules/listeners/client_active_listeners_wrap.cpp
276+
core/modules/listeners/client_connect_listeners_wrap.cpp
275277
core/modules/listeners/client_disconnect_listeners_wrap.cpp
276278
core/modules/listeners/client_fully_connect_listeners_wrap.cpp
277279
core/modules/listeners/client_put_in_server_listeners_wrap.cpp

src/configure-csgo - Kopie.bat

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

src/core/addons/sp_addon.cpp

Lines changed: 232 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,237 @@ void CAddonManager::NetworkIDValidated( const char *pszUserName, const char *psz
7777
{
7878
// Wrap the parameters
7979
CListenerManager::Param p1, p2;
80-
p1.name="pszUserName"; p1.type=CListenerManager::CHAR; p1.char_ptr = pszUserName;
81-
p2.name="pszNetworkID"; p2.type=CListenerManager::CHAR; p2.char_ptr = pszNetworkID;
80+
81+
p1.name="playername";
82+
p1.type=CListenerManager::CONST_CHAR_PTR;
83+
p1.const_char_ptr = pszUserName;
84+
85+
p2.name="networkid";
86+
p2.type=CListenerManager::CONST_CHAR_PTR;
87+
p2.const_char_ptr = pszNetworkID;
8288
// Dispatch all NetwordIDValidatedListeners
8389
get_networkid_validated_listener_manager()->call_listeners(2, p1, p2);
84-
}
90+
}
91+
92+
93+
//---------------------------------------------------------------------------------
94+
// Calls level init listeners.
95+
//---------------------------------------------------------------------------------
96+
void CAddonManager::LevelInit( char const *pMapName )
97+
{
98+
// Wrap the parameters
99+
CListenerManager::Param p1;
100+
101+
p1.name="mapname";
102+
p1.type=CListenerManager::CONST_CHAR_PTR;
103+
p1.const_char_ptr= pMapName;
104+
// Dispatch all LevelInit listeners
105+
get_level_init_listener_manager()->call_listeners(1, p1);
106+
}
107+
108+
//---------------------------------------------------------------------------------
109+
// Calls server activate listeners.
110+
//---------------------------------------------------------------------------------
111+
// TODO: will not work if this is really a list
112+
void CAddonManager::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
113+
{
114+
// Wrap the parameters
115+
CListenerManager::Param p1, p2, p3;
116+
117+
p1.name="edictlist";
118+
p1.type=CListenerManager::EDICT_T_PTR;
119+
p1.edict_t_ptr= pEdictList;
120+
121+
p2.name="edict_count";
122+
p2.type=CListenerManager::INT;
123+
p2.int_value=edictCount;
124+
125+
p3.name="max_clients";
126+
p3.type=CListenerManager::INT;
127+
p3.int_value=clientMax;
128+
// Dispatch all LevelInit listeners
129+
get_server_activate_listener_manager()->call_listeners(3, p1, p2, p3);
130+
}
131+
132+
//---------------------------------------------------------------------------------
133+
// Calls level shutdown listeners.
134+
//---------------------------------------------------------------------------------
135+
void CAddonManager::LevelShutdown( void )
136+
{
137+
// Dispatch all tick listeners
138+
get_level_shutdown_listener_manager()->call_listeners(0);
139+
}
140+
141+
142+
//---------------------------------------------------------------------------------
143+
// Calls client active listeners.
144+
//---------------------------------------------------------------------------------
145+
void CAddonManager::ClientActive( edict_t *pEntity )
146+
{
147+
// Wrap the parameters
148+
CListenerManager::Param p1;
149+
150+
p1.name="edict";
151+
p1.type=CListenerManager::EDICT_T_PTR;
152+
p1.edict_t_ptr= pEntity;
153+
// Dispatch all LevelInit listeners
154+
get_client_active_listener_manager()->call_listeners(1, p1);
155+
}
156+
157+
//---------------------------------------------------------------------------------
158+
// Calls client disconnect listeners.
159+
//---------------------------------------------------------------------------------
160+
void CAddonManager::ClientDisconnect( edict_t *pEntity )
161+
{
162+
// Wrap the parameters
163+
CListenerManager::Param p1;
164+
165+
p1.name="edict";
166+
p1.type=CListenerManager::EDICT_T_PTR;
167+
p1.edict_t_ptr= pEntity;
168+
// Dispatch all LevelInit listeners
169+
get_client_disconnect_listener_manager()->call_listeners(1, p1);
170+
}
171+
172+
//---------------------------------------------------------------------------------
173+
// Calls client put in server listeners.
174+
//---------------------------------------------------------------------------------
175+
void CAddonManager::ClientPutInServer( edict_t *pEntity, char const *playername )
176+
{
177+
// Wrap the parameters
178+
CListenerManager::Param p1, p2;
179+
180+
p1.name="edict";
181+
p1.type=CListenerManager::EDICT_T_PTR;
182+
p1.edict_t_ptr= pEntity;
183+
184+
p2.name="playername";
185+
p2.type=CListenerManager::CONST_CHAR_PTR;
186+
p2.const_char_ptr= playername;
187+
// Dispatch all LevelInit listeners
188+
get_client_put_in_server_listener_manager()->call_listeners(2, p1, p2);
189+
}
190+
191+
//---------------------------------------------------------------------------------
192+
// Calls client settings changed listeners.
193+
//---------------------------------------------------------------------------------
194+
void CAddonManager::ClientSettingsChanged( edict_t *pEdict )
195+
{
196+
// Wrap the parameters
197+
CListenerManager::Param p1;
198+
199+
p1.name="edict";
200+
p1.type=CListenerManager::EDICT_T_PTR;
201+
p1.edict_t_ptr= pEdict;
202+
// Dispatch all LevelInit listeners
203+
get_client_settings_changed_listener_manager()->call_listeners(1, p1);
204+
}
205+
206+
//---------------------------------------------------------------------------------
207+
// Calls client connect listeners.
208+
//---------------------------------------------------------------------------------
209+
void CAddonManager::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
210+
{
211+
// Wrap the parameters
212+
CListenerManager::Param p1, p2, p3, p4, p5, p6;
213+
214+
p1.name="is_allowed_to_connect";
215+
p1.type=CListenerManager::BOOL;
216+
p1.bool_value=bAllowConnect;
217+
218+
p2.name="edict";
219+
p2.type=CListenerManager::EDICT_T_PTR;
220+
p2.edict_t_ptr=pEntity;
221+
222+
p3.name="playername";
223+
p3.type=CListenerManager::CONST_CHAR_PTR;
224+
p3.const_char_ptr=pszName;
225+
226+
p4.name="network_address";
227+
p4.type=CListenerManager::CONST_CHAR_PTR;
228+
p4.const_char_ptr=pszAddress;
229+
230+
// Is this an int? Maybe just convert and remove unnused CHAR_PTR
231+
p5.name="reject";
232+
p5.type=CListenerManager::CHAR_PTR;
233+
p5.char_ptr=reject;
234+
235+
p6.name="max_recject_len";
236+
p6.type=CListenerManager::INT;
237+
p6.int_value=maxrejectlen;
238+
// Dispatch all LevelInit listeners
239+
get_client_connect_listener_manager()->call_listeners(6, p1, p2, p3, p4, p5, p6);
240+
}
241+
242+
void CAddonManager::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
243+
{
244+
// Wrap the parameters
245+
CListenerManager::Param p1, p2, p3, p4, p5;
246+
247+
p1.name="cookie_id";
248+
p1.type=CListenerManager::INT;
249+
// iCookie is just an int
250+
p1.int_value=(int)iCookie;
251+
252+
p2.name="edict";
253+
p2.type=CListenerManager::EDICT_T_PTR;
254+
p2.edict_t_ptr=pPlayerEntity;
255+
256+
p3.name="edict";
257+
p3.type=CListenerManager::EDICT_T_PTR;
258+
p3.edict_t_ptr=pPlayerEntity;
259+
260+
p4.name="cvar_name";
261+
p4.type=CListenerManager::CONST_CHAR_PTR;
262+
p4.const_char_ptr=pCvarName;
263+
264+
p5.name="cvar_value";
265+
p5.type=CListenerManager::CONST_CHAR_PTR;
266+
p5.const_char_ptr=pCvarValue;
267+
// Dispatch all LevelInit listeners
268+
get_client_fully_connect_listener_manager()->call_listeners(5, p1, p2, p3, p4, p5);
269+
}
270+
//
271+
//
272+
//
273+
#if(SOURCE_ENGINE >= 3)
274+
void CAddonManager::ClientFullyConnect( edict_t *pEntity )
275+
{
276+
// Wrap the parameters
277+
CListenerManager::Param p1;
278+
279+
p1.name="edict";
280+
p1.type=CListenerManager::EDICT_T_PTR;
281+
p1.edict_t_ptr=pEntity;
282+
// Dispatch all LevelInit listeners
283+
get_client_fully_connect_listener_manager()->call_listeners(1, p1);
284+
}
285+
286+
void CAddonManager::OnEdictAllocated( edict_t *edict )
287+
{
288+
// Wrap the parameters
289+
CListenerManager::Param p1;
290+
291+
p1.name="edict";
292+
p1.type=CListenerManager::EDICT_T_PTR;
293+
p1.edict_t_ptr=edict;
294+
// Dispatch all LevelInit listeners
295+
get_on_edict_allocated_listener_manager()->call_listeners(1, p1);
296+
}
297+
298+
void CAddonManager::OnEdictFreed( const edict_t *edict )
299+
{
300+
// Wrap the parameters
301+
/*CListenerManager::Param p1;
302+
303+
TODO: Const edict
304+
305+
p1.name="edict";
306+
p1.type=CListenerManager::EDICT_T_PTR;
307+
p1.edict_t_ptr=edict;
308+
// Dispatch all LevelInit listeners
309+
get_on_edict_freed_listener_manager()->call_listeners(1, p1);*/
310+
311+
get_on_edict_freed_listener_manager()->call_listeners(0);
312+
}
313+
#endif

src/core/addons/sp_addon.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "core/sp_python.h"
3333
#include "utllinkedlist.h"
3434
#include "igameevents.h"
35+
#include "engine/iserverplugin.h"
3536

3637
//---------------------------------------------------------------------------------
3738
// Addon manager.
@@ -44,6 +45,22 @@ class CAddonManager
4445

4546
void GameFrame();
4647
void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );
48+
void LevelInit( char const *pMapName );
49+
void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
50+
void LevelShutdown( void );
51+
void ClientActive( edict_t *pEntity );
52+
void ClientDisconnect( edict_t *pEntity );
53+
void ClientPutInServer( edict_t *pEntity, char const *playername );
54+
void ClientSettingsChanged( edict_t *pEdict );
55+
void ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
56+
57+
void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue );
58+
59+
#if(SOURCE_ENGINE >= 3)
60+
void ClientFullyConnect( edict_t *pEntity );
61+
void OnEdictAllocated( edict_t *edict );
62+
void OnEdictFreed( const edict_t *edict );
63+
#endif
4764
};
4865

4966
//---------------------------------------------------------------------------------

src/core/core/sp_main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ const char *CSourcePython::GetPluginDescription( void )
270270
//---------------------------------------------------------------------------------
271271
void CSourcePython::LevelInit( char const *pMapName )
272272
{
273-
273+
g_AddonManager.LevelInit(pMapName);
274274
}
275275

276276
//---------------------------------------------------------------------------------
@@ -279,6 +279,7 @@ void CSourcePython::LevelInit( char const *pMapName )
279279
//---------------------------------------------------------------------------------
280280
void CSourcePython::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
281281
{
282+
g_AddonManager.ServerActivate(pEdictList, edictCount, clientMax);
282283
}
283284

284285
//---------------------------------------------------------------------------------
@@ -294,27 +295,31 @@ void CSourcePython::GameFrame( bool simulating )
294295
//---------------------------------------------------------------------------------
295296
void CSourcePython::LevelShutdown( void ) // !!!!this can get called multiple times per map change
296297
{
298+
g_AddonManager.LevelShutdown();
297299
}
298300

299301
//---------------------------------------------------------------------------------
300302
// Purpose: called when a client spawns into a server (i.e as they begin to play)
301303
//---------------------------------------------------------------------------------
302304
void CSourcePython::ClientActive( edict_t *pEntity )
303305
{
306+
g_AddonManager.ClientActive(pEntity);
304307
}
305308

306309
//---------------------------------------------------------------------------------
307310
// Purpose: called when a client leaves a server (or is timed out)
308311
//---------------------------------------------------------------------------------
309312
void CSourcePython::ClientDisconnect( edict_t *pEntity )
310313
{
314+
g_AddonManager.ClientDisconnect(pEntity);
311315
}
312316

313317
//---------------------------------------------------------------------------------
314318
// Purpose: called on
315319
//---------------------------------------------------------------------------------
316320
void CSourcePython::ClientPutInServer( edict_t *pEntity, char const *playername )
317321
{
322+
g_AddonManager.ClientPutInServer(pEntity, playername);
318323
}
319324

320325
//---------------------------------------------------------------------------------
@@ -341,14 +346,15 @@ void ClientPrint( edict_t *pEdict, char *format, ... )
341346
//---------------------------------------------------------------------------------
342347
void CSourcePython::ClientSettingsChanged( edict_t *pEdict )
343348
{
344-
349+
g_AddonManager.ClientSettingsChanged(pEdict);
345350
}
346351

347352
//---------------------------------------------------------------------------------
348353
// Purpose: called when a client joins a server
349354
//---------------------------------------------------------------------------------
350355
PLUGIN_RESULT CSourcePython::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
351356
{
357+
g_AddonManager.ClientConnect(bAllowConnect, pEntity, pszName, pszAddress, reject, maxrejectlen);
352358
return PLUGIN_CONTINUE;
353359
}
354360

@@ -367,6 +373,7 @@ PLUGIN_RESULT CSourcePython::NetworkIDValidated( const char *pszUserName, const
367373
void CSourcePython::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity,
368374
EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
369375
{
376+
g_AddonManager.OnQueryCvarValueFinished(iCookie, pPlayerEntity, eStatus, pCvarName, pCvarValue);
370377
DevMsg(0, "Cvar query (cookie: %d, status: %d) - name: %s, value: %s\n", iCookie, eStatus, pCvarName, pCvarValue );
371378
}
372379

@@ -403,16 +410,16 @@ PLUGIN_RESULT CSourcePython::ClientCommand( edict_t* pEntity )
403410
#if(SOURCE_ENGINE >= 3)
404411
void CSourcePython::ClientFullyConnect( edict_t *pEntity )
405412
{
406-
413+
g_AddonManager.ClientFullyConnect(pEntity);
407414
}
408415

409416
void CSourcePython::OnEdictAllocated( edict_t *edict )
410417
{
411-
418+
g_AddonManager.OnEdictAllocated(edict);
412419
}
413420

414421
void CSourcePython::OnEdictFreed( const edict_t *edict )
415422
{
416-
423+
g_AddonManager.OnEdictFreed(edict);
417424
}
418425
#endif

0 commit comments

Comments
 (0)