Skip to content

Commit 8ba9c07

Browse files
committed
Not tested ingame yet!
- Shared class for Listeners - Moved Tick listener to a common listener directory (tick_c module is gone, it's now listener_c) - Added a NetworkIDValidated listener
1 parent e05edc9 commit 8ba9c07

12 files changed

+276
-96
lines changed

src/CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,19 @@ Set(SOURCEPYTHON_PLAYERS_MODULE_SOURCES
246246
)
247247

248248
# ------------------------------------------------------------------
249-
# Tick Listener module
249+
# Listener module
250250
# ------------------------------------------------------------------
251-
Set(SOURCEPYTHON_TICKLISTENER_MODULE_HEADERS
252-
core/modules/ticklisteners/ticklisteners_wrap.h
251+
Set(SOURCEPYTHON_LISTENERS_MODULE_HEADERS
252+
core/modules/listeners/listenermanager.h
253+
core/modules/listeners/tick_listeners_wrap.h
254+
core/modules/listeners/networkid_validated_listeners_wrap.h
253255
)
254256

255-
Set(SOURCEPYTHON_TICKLISTENER_MODULE_SOURCES
256-
core/modules/ticklisteners/ticklisteners_wrap.cpp
257-
core/modules/ticklisteners/ticklisteners_wrap_python.cpp
257+
Set(SOURCEPYTHON_LISTENERS_MODULE_SOURCES
258+
core/modules/listeners/listenermanager.cpp
259+
core/modules/listeners/tick_listeners_wrap.cpp
260+
core/modules/listeners/networkid_validated_listeners_wrap.cpp
261+
core/modules/listeners/listeners_wrap_python.cpp
258262
)
259263

260264
# ------------------------------------------------------------------
@@ -322,8 +326,8 @@ Set(SOURCEPYTHON_MODULE_FILES
322326
${SOURCEPYTHON_PLAYERS_MODULE_HEADERS}
323327
${SOURCEPYTHON_PLAYERS_MODULE_SOURCES}
324328

325-
${SOURCEPYTHON_TICKLISTENER_MODULE_HEADERS}
326-
${SOURCEPYTHON_TICKLISTENER_MODULE_SOURCES}
329+
${SOURCEPYTHON_LISTENERS_MODULE_HEADERS}
330+
${SOURCEPYTHON_LISTENERS_MODULE_SOURCES}
327331

328332
${SOURCEPYTHON_GLOBALS_MODULE_HEADERS}
329333
${SOURCEPYTHON_GLOBALS_MODULE_SOURCES}
@@ -354,7 +358,7 @@ Source_Group("Header Files\\Module\\Event" FILES ${SOURCEPYTHON_
354358
Source_Group("Header Files\\Module\\Entities" FILES ${SOURCEPYTHON_ENTITY_MODULE_HEADERS})
355359
Source_Group("Header Files\\Module\\KeyValues" FILES ${SOURCEPYTHON_KEYVALUES_MODULE_HEADERS})
356360
Source_Group("Header Files\\Module\\Players" FILES ${SOURCEPYTHON_PLAYERS_MODULE_HEADERS})
357-
Source_Group("Header Files\\Module\\TickListeners" FILES ${SOURCEPYTHON_TICKLISTENER_MODULE_HEADERS})
361+
Source_Group("Header Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_HEADERS})
358362
Source_Group("Header Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_HEADERS})
359363
Source_Group("Header Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_HEADERS})
360364
Source_Group("Header Files\\Module\\Vecmath" FILES ${SOURCEPYTHON_VECMATH_MODULE_HEADERS})
@@ -373,7 +377,7 @@ Source_Group("Source Files\\Module\\Event" FILES ${SOURCEPYTHON_
373377
Source_Group("Source Files\\Module\\Entities" FILES ${SOURCEPYTHON_ENTITY_MODULE_SOURCES})
374378
Source_Group("Source Files\\Module\\KeyValues" FILES ${SOURCEPYTHON_KEYVALUES_MODULE_SOURCES})
375379
Source_Group("Source Files\\Module\\Players" FILES ${SOURCEPYTHON_PLAYERS_MODULE_SOURCES})
376-
Source_Group("Source Files\\Module\\TickListeners" FILES ${SOURCEPYTHON_TICKLISTENER_MODULE_SOURCES})
380+
Source_Group("Source Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_SOURCES})
377381
Source_Group("Source Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_SOURCES})
378382
Source_Group("Source Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_SOURCES})
379383
Source_Group("Source Files\\Module\\Vecmath" FILES ${SOURCEPYTHON_VECMATH_MODULE_SOURCES})

src/configure-csgo - Kopie.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cmake -G"Visual Studio 11" -DGAME=csgo
2+
pause

src/core/addons/sp_addon.cpp

Lines changed: 12 additions & 2 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/ticklisteners/ticklisteners_wrap.h"
36+
#include "modules/listeners/tick_listeners_wrap.h"
37+
#include "modules/listeners/networkid_validated_listeners_wrap.h"
3738

3839
//---------------------------------------------------------------------------------
3940
// External variables
@@ -67,5 +68,14 @@ CAddonManager::~CAddonManager( void )
6768
void CAddonManager::GameFrame()
6869
{
6970
// Dispatch all tick listeners
70-
get_tick_listener_manager()->call_tick_listeners();
71+
get_tick_listener_manager()->call_listeners();
7172
}
73+
74+
//---------------------------------------------------------------------------------
75+
// Calls tick listener.
76+
//---------------------------------------------------------------------------------
77+
void CAddonManager::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
78+
{
79+
// Dispatch all NetwordIDValidatedListeners
80+
get_networkid_validated_listener_manager()->call_listeners(pszUserName, pszNetworkID);
81+
}

src/core/addons/sp_addon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CAddonManager
4343
~CAddonManager( void );
4444

4545
void GameFrame();
46+
void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );
4647
};
4748

4849
//---------------------------------------------------------------------------------

src/core/core/sp_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ PLUGIN_RESULT CSourcePython::ClientConnect( bool *bAllowConnect, edict_t *pEntit
357357
//---------------------------------------------------------------------------------
358358
PLUGIN_RESULT CSourcePython::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
359359
{
360+
g_AddonManager.NetworkIDValidated(pszUserName, pszNetworkID);
360361
return PLUGIN_CONTINUE;
361362
}
362363

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//-----------------------------------------------------------------------------
2+
// Includes
3+
//-----------------------------------------------------------------------------
4+
#include "listenermanager.h"
5+
#include "utility/call_python.h"
6+
7+
//-----------------------------------------------------------------------------
8+
// Adds a callable to the end of the CListenerManager vector.
9+
//-----------------------------------------------------------------------------
10+
void CListenerManager::register_listener(PyObject* pCallable)
11+
{
12+
// Get the object instance of the callable
13+
object oCallable = object(handle<>(borrowed(pCallable)));
14+
15+
// Is the callable already in the vector?
16+
if( !m_vecCallables.HasElement(oCallable) )
17+
{
18+
// Add the callable to the vector
19+
m_vecCallables.AddToTail(oCallable);
20+
}
21+
}
22+
23+
//-----------------------------------------------------------------------------
24+
// Removes all instances of a callable from the CListenerManager vector.
25+
//-----------------------------------------------------------------------------
26+
void CListenerManager::unregister_listener(PyObject* pCallable)
27+
{
28+
// Get the object instance of the callable
29+
object oCallable = object(handle<>(borrowed(pCallable)));
30+
31+
// Remove the callback from the ServerCommandManager instance
32+
m_vecCallables.FindAndRemove(oCallable);
33+
}
34+
35+
//-----------------------------------------------------------------------------
36+
// Calls all registered listeners.
37+
//-----------------------------------------------------------------------------
38+
// FSS No C++11 suport? In neither, VS2010 and VS2012?
39+
// template<typename... Types> void CListenerManager::call_listeners(typename... args)
40+
void CListenerManager::call_listeners()
41+
{
42+
for(int i = 0; i < m_vecCallables.Count(); i++)
43+
{
44+
BEGIN_BOOST_PY()
45+
46+
// Get the PyObject instance of the callable
47+
PyObject* pCallable = m_vecCallables[i].ptr();
48+
49+
// Call the callable
50+
CALL_PY_FUNC(pCallable);
51+
52+
END_BOOST_PY_NORET()
53+
}
54+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _LISTENERMANAGER_H
2+
#define _LISTENERMANAGER_H
3+
4+
//-----------------------------------------------------------------------------
5+
// Includes
6+
//-----------------------------------------------------------------------------
7+
#include "utlvector.h"
8+
#include "utility/wrap_macros.h"
9+
10+
//-----------------------------------------------------------------------------
11+
// CListenerManager class
12+
//-----------------------------------------------------------------------------
13+
class CListenerManager
14+
{
15+
public:
16+
17+
void register_listener(PyObject* pCallable);
18+
void unregister_listener(PyObject* pCallable);
19+
20+
void call_listeners();
21+
22+
protected:
23+
CUtlVector<object> m_vecCallables;
24+
};
25+
26+
#endif // _LISTENERMANAGER_H

src/core/modules/ticklisteners/ticklisteners_wrap.cpp renamed to src/core/modules/listeners/listeners_wrap_python.cpp

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,75 @@
2727
//-----------------------------------------------------------------------------
2828
// Includes
2929
//-----------------------------------------------------------------------------
30-
#include "ticklisteners_wrap.h"
31-
#include "utility/call_python.h"
30+
#include "modules/export_main.h"
31+
#include "tick_listeners_wrap.h"
32+
#include "networkid_validated_listeners_wrap.h"
3233

3334
//-----------------------------------------------------------------------------
34-
// Static singletons.
35+
// Functions that expose tick listener functionality to us.
3536
//-----------------------------------------------------------------------------
36-
static CTickListenerManager s_TickListenerManager;
37+
void export_tick_listener();
38+
void export_networkid_validated_listener();
3739

3840
//-----------------------------------------------------------------------------
39-
// TickListenerManager accessor.
41+
// Exposes the tick_c module.
4042
//-----------------------------------------------------------------------------
41-
CTickListenerManager* get_tick_listener_manager()
43+
DECLARE_SP_MODULE(listener_c)
4244
{
43-
return &s_TickListenerManager;
45+
export_tick_listener();
46+
export_networkid_validated_listener();
4447
}
4548

4649
//-----------------------------------------------------------------------------
47-
// Adds a callable to the end of the CTickListenerManager vector.
50+
// Exposes CTickListenerManager
4851
//-----------------------------------------------------------------------------
49-
void CTickListenerManager::register_listener(PyObject* pCallable)
52+
void export_tick_listener()
5053
{
51-
// Get the object instance of the callable
52-
object oCallable = object(handle<>(borrowed(pCallable)));
54+
BOOST_ABSTRACT_CLASS(CTickListenerManager)
5355

54-
// Is the callable already in the vector?
55-
if( !m_vecCallables.HasElement(oCallable) )
56-
{
57-
// Add the callable to the vector
58-
m_vecCallables.AddToTail(oCallable);
59-
}
60-
}
56+
CLASS_METHOD(CTickListenerManager,
57+
register_listener,
58+
"Adds the given callable to the end of the tick listener vector.",
59+
args("pCallable")
60+
)
6161

62-
//-----------------------------------------------------------------------------
63-
// Removes all instances of a callable from the CTickListenerManager vector.
64-
//-----------------------------------------------------------------------------
65-
void CTickListenerManager::unregister_listener(PyObject* pCallable)
66-
{
67-
// Get the object instance of the callable
68-
object oCallable = object(handle<>(borrowed(pCallable)));
62+
CLASS_METHOD(CTickListenerManager,
63+
unregister_listener,
64+
"Removes the given callable from the tick listener vector.",
65+
args("pCallable")
66+
)
6967

70-
// Remove the callback from the ServerCommandManager instance
71-
m_vecCallables.FindAndRemove(oCallable);
68+
BOOST_END_CLASS()
69+
70+
BOOST_FUNCTION(get_tick_listener_manager,
71+
"Returns the CTickListListenerManager instance",
72+
reference_existing_object_policy()
73+
);
7274
}
7375

7476
//-----------------------------------------------------------------------------
75-
// Calls all registered tick listeners.
77+
// Exposes CNetworkIDValidatedListenerManager
7678
//-----------------------------------------------------------------------------
77-
void CTickListenerManager::call_tick_listeners()
79+
void export_networkid_validated_listener()
7880
{
79-
for(int i = 0; i < m_vecCallables.Count(); i++)
80-
{
81-
BEGIN_BOOST_PY()
81+
BOOST_ABSTRACT_CLASS(CNetworkIDValidatedListenerManager)
8282

83-
// Get the PyObject instance of the callable
84-
PyObject* pCallable = m_vecCallables[i].ptr();
83+
CLASS_METHOD(CNetworkIDValidatedListenerManager,
84+
register_listener,
85+
"Adds the given callable to the end of the network ID validated listener vector.",
86+
args("pCallable")
87+
)
8588

86-
// Call the callable
87-
CALL_PY_FUNC(pCallable);
89+
CLASS_METHOD(CNetworkIDValidatedListenerManager,
90+
unregister_listener,
91+
"Removes the given callable from the network ID validated listener vector.",
92+
args("pCallable")
93+
)
8894

89-
END_BOOST_PY_NORET()
90-
}
91-
}
95+
BOOST_END_CLASS()
96+
97+
BOOST_FUNCTION(get_networkid_validated_listener_manager,
98+
"Returns the CNetworkIDValidatedListenerManager instance",
99+
reference_existing_object_policy()
100+
);
101+
}

src/core/modules/ticklisteners/ticklisteners_wrap_python.cpp renamed to src/core/modules/listeners/networkid_validated_listeners_wrap.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,36 @@
2727
//-----------------------------------------------------------------------------
2828
// Includes
2929
//-----------------------------------------------------------------------------
30-
#include "modules/export_main.h"
31-
#include "ticklisteners_wrap.h"
30+
#include "networkid_validated_listeners_wrap.h"
3231

3332
//-----------------------------------------------------------------------------
34-
// Functions that expose tick listener functionality to us.
33+
// Static singletons.
3534
//-----------------------------------------------------------------------------
36-
void export_ticklistener();
35+
static CNetworkIDValidatedListenerManager s_NetworkIDValidatedListenerManager;
3736

3837
//-----------------------------------------------------------------------------
39-
// Exposes the tick_c module.
38+
// Overload for passing the arguments
4039
//-----------------------------------------------------------------------------
41-
DECLARE_SP_MODULE(tick_c)
40+
void CNetworkIDValidatedListenerManager::call_listeners( const char *pszUserName, const char *pszNetworkID )
4241
{
43-
export_ticklistener();
42+
for(int i = 0; i < m_vecCallables.Count(); i++)
43+
{
44+
BEGIN_BOOST_PY()
45+
46+
// Get the PyObject instance of the callable
47+
PyObject* pCallable = m_vecCallables[i].ptr();
48+
49+
// Call the callable
50+
CALL_PY_FUNC(pCallable, pszUserName, pszNetworkID);
51+
52+
END_BOOST_PY_NORET()
53+
}
4454
}
4555

4656
//-----------------------------------------------------------------------------
47-
// Exposes CTickListenerManager
57+
// CNetworkIDValidatedListenerManager accessor.
4858
//-----------------------------------------------------------------------------
49-
void export_ticklistener()
59+
CNetworkIDValidatedListenerManager* get_networkid_validated_listener_manager()
5060
{
51-
BOOST_ABSTRACT_CLASS(CTickListenerManager)
52-
53-
CLASS_METHOD(CTickListenerManager,
54-
register_listener,
55-
"Adds the given callable to the end of the tick listener vector.",
56-
args("pCallable")
57-
)
58-
59-
CLASS_METHOD(CTickListenerManager,
60-
unregister_listener,
61-
"Removes the given callable from the tick listener vector.",
62-
args("pCallable")
63-
)
64-
65-
BOOST_END_CLASS()
66-
67-
BOOST_FUNCTION(get_tick_listener_manager,
68-
"Returns the CTickListListenerManager instance",
69-
reference_existing_object_policy()
70-
);
61+
return &s_NetworkIDValidatedListenerManager;
7162
}

0 commit comments

Comments
 (0)