Skip to content

Commit 779e11d

Browse files
committed
Fixed client/say command filters, events, and tick listeners not unregistering when using the decorator classes for each.
Fixed a few paths in CMakeLists.txt. Added a few missing args() lists in the <module>_wrap_python files. Fixed an issue that caused cvars to go out of scope and be dropped from the server.
1 parent a5588ed commit 779e11d

File tree

14 files changed

+143
-66
lines changed

14 files changed

+143
-66
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def __init__(self, callback):
3333
# Store the callback
3434
self.callback = callback
3535

36+
# Set the instance module so that the filter
37+
# can be unregistered properly on unload
38+
self.__module__ = self.callback.__module__
39+
3640
# Register the filter
3741
self._manager_class.register_filter(self.callback)
3842

addons/source-python/packages/source-python/events/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def __init__(self, callback):
4545
# Store the callback
4646
self.callback = callback
4747

48+
# Set the instance module so that the event
49+
# can be unregistered properly on unload
50+
self.__module__ = self.callback.__module__
51+
4852
# Register the event
4953
EventRegistry.register_for_event(self.callback.__name__, self.callback)
5054

51-
def __call__(self, game_event):
52-
'''Calls the Event callback with the GameEvent instance'''
53-
return self.callback(game_event)
54-
5555
def _unload_instance(self):
5656
'''Unregisters the event'''
5757
EventRegistry.unregister_for_event(

addons/source-python/packages/source-python/tick/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def __init__(self, callback):
5050
# Store the callback
5151
self.callback = callback
5252

53+
# Set the instance module so that the listener
54+
# can be unregistered properly on unload
55+
self.__module__ = self.callback.__module__
56+
5357
# Register the tick listener
5458
TickListenerManager.register_listener(self.callback)
5559

src/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,15 @@ Source_Group("Header Files\\Module\\Cvar" FILES ${SOURCEPYTHON
365365
Source_Group("Header Files\\Module\\Effects" FILES ${SOURCEPYTHON_EFFECTS_MODULE_HEADERS})
366366
Source_Group("Header Files\\Module\\Engine" FILES ${SOURCEPYTHON_ENGINE_MODULE_HEADERS})
367367
Source_Group("Header Files\\Module\\Event" FILES ${SOURCEPYTHON_EVENT_MODULE_HEADERS})
368-
Source_Group("Header Files\\Module\\Entities" FILES ${SOURCEPYTHON_ENTITY_MODULE_HEADERS})
368+
Source_Group("Header Files\\Module\\Entity" FILES ${SOURCEPYTHON_ENTITY_MODULE_HEADERS})
369369
Source_Group("Header Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_HEADERS})
370370
Source_Group("Header Files\\Module\\KeyValues" FILES ${SOURCEPYTHON_KEYVALUES_MODULE_HEADERS})
371-
Source_Group("Header Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_HEADERS})
371+
Source_Group("Header Files\\Module\\Listener" FILES ${SOURCEPYTHON_LISTENERS_MODULE_HEADERS})
372372
Source_Group("Header Files\\Module\\Mathlib" FILES ${SOURCEPYTHON_MATHLIB_MODULE_HEADERS})
373373
Source_Group("Header Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_HEADERS})
374-
Source_Group("Header Files\\Module\\Players" FILES ${SOURCEPYTHON_PLAYERS_MODULE_HEADERS})
375-
Source_Group("Header Files\\Module\\RecipientFilters" FILES ${SOURCEPYTHON_RECIPIENTFILTER_MODULE_HEADERS})
376-
Source_Group("Header Files\\Module\\Usermessages" FILES ${SOURCEPYTHON_USERMESSAGE_MODULE_HEADERS})
374+
Source_Group("Header Files\\Module\\Player" FILES ${SOURCEPYTHON_PLAYERS_MODULE_HEADERS})
375+
Source_Group("Header Files\\Module\\RecipientFilter" FILES ${SOURCEPYTHON_RECIPIENTFILTER_MODULE_HEADERS})
376+
Source_Group("Header Files\\Module\\Usermessage" FILES ${SOURCEPYTHON_USERMESSAGE_MODULE_HEADERS})
377377

378378
Source_Group("Source Files\\Addons" FILES ${SOURCEPYTHON_ADDON_SOURCES})
379379
Source_Group("Source Files\\Core" FILES ${SOURCEPYTHON_CORE_SOURCES})
@@ -385,17 +385,17 @@ Source_Group("Source Files\\Module\\Conversions" FILES ${SOURCEPYTHON
385385
Source_Group("Source Files\\Module\\Cvar" FILES ${SOURCEPYTHON_CVAR_MODULE_SOURCES})
386386
Source_Group("Source Files\\Module\\Effects" FILES ${SOURCEPYTHON_EFFECTS_MODULE_SOURCES})
387387
Source_Group("Source Files\\Module\\Engine" FILES ${SOURCEPYTHON_ENGINE_MODULE_SOURCES})
388-
Source_Group("Source Files\\Module\\Entities" FILES ${SOURCEPYTHON_ENTITY_MODULE_SOURCES})
388+
Source_Group("Source Files\\Module\\Entity" FILES ${SOURCEPYTHON_ENTITY_MODULE_SOURCES})
389389
Source_Group("Source Files\\Module\\Event" FILES ${SOURCEPYTHON_EVENT_MODULE_SOURCES})
390390
Source_Group("Source Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_SOURCES})
391391
Source_Group("Source Files\\Module\\KeyValues" FILES ${SOURCEPYTHON_KEYVALUES_MODULE_SOURCES})
392-
Source_Group("Source Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_SOURCES})
392+
Source_Group("Source Files\\Module\\Listener" FILES ${SOURCEPYTHON_LISTENERS_MODULE_SOURCES})
393393
Source_Group("Source Files\\Module\\Mathlib" FILES ${SOURCEPYTHON_MATHLIB_MODULE_SOURCES})
394394
Source_Group("Source Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_SOURCES})
395-
Source_Group("Source Files\\Module\\Players" FILES ${SOURCEPYTHON_PLAYERS_MODULE_SOURCES})
396-
Source_Group("Source Files\\Module\\RecipientFilters" FILES ${SOURCEPYTHON_RECIPIENTFILTER_MODULE_SOURCES})
397-
Source_Group("Source Files\\Module\\Usermessages" FILES ${SOURCEPYTHON_USERMESSAGE_MODULE_SOURCES})
398-
Source_Group("Source Files\\Module\\Usermessages\\${SDK}" FILES ${SOURCEPYTHON_MODULE_USERMESSAGES_GAME_SOURCES})
395+
Source_Group("Source Files\\Module\\Player" FILES ${SOURCEPYTHON_PLAYERS_MODULE_SOURCES})
396+
Source_Group("Source Files\\Module\\RecipientFilter" FILES ${SOURCEPYTHON_RECIPIENTFILTER_MODULE_SOURCES})
397+
Source_Group("Source Files\\Module\\Usermessage" FILES ${SOURCEPYTHON_USERMESSAGE_MODULE_SOURCES})
398+
Source_Group("Source Files\\Module\\Usermessage\\${SDK}" FILES ${SOURCEPYTHON_MODULE_USERMESSAGES_GAME_SOURCES})
399399

400400
# ------------------------------------------------------------------
401401
# All SourcePython source files. Ideally we break out each group of

src/core/modules/bot/bot_wrap_python.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ void export_botmanager()
5757
.def("get_bot_controller",
5858
&IBotManager::GetBotController,
5959
"Returns the BotController object for the given bot edict.",
60+
args("edict"),
6061
reference_existing_object_policy()
6162
)
6263

6364
.def("create_bot",
6465
&IBotManager::CreateBot,
6566
"Creates a new bot and spawns it into the server.",
67+
args("bot_name"),
6668
reference_existing_object_policy()
6769
)
6870
;
@@ -75,17 +77,20 @@ void export_botcontroller()
7577
class_<IBotController, boost::noncopyable>("BotController", no_init)
7678
.def("set_abs_origin",
7779
&IBotController::SetAbsOrigin,
78-
"Sets the bot's absolute origin."
80+
"Sets the bot's absolute origin.",
81+
args("vec")
7982
)
8083

8184
.def("set_abs_angles",
8285
&IBotController::SetAbsAngles,
83-
"Sets the bot's absolute angles."
86+
"Sets the bot's absolute angles.",
87+
args("ang")
8488
)
8589

8690
.def("set_local_origin",
8791
&IBotController::SetLocalOrigin,
88-
"Sets the bot's local origin."
92+
"Sets the bot's local origin.",
93+
args("origin")
8994
)
9095

9196
.def("get_local_origin",
@@ -95,7 +100,8 @@ void export_botcontroller()
95100

96101
.def("set_local_angles",
97102
&IBotController::SetLocalAngles,
98-
"Sets the bot's local angles."
103+
"Sets the bot's local angles.",
104+
args("angles")
99105
)
100106

101107
.def("get_local_angles",
@@ -105,22 +111,26 @@ void export_botcontroller()
105111

106112
.def("remove_all_items",
107113
&IBotController::RemoveAllItems,
108-
"Removes all items the bot is wearing."
114+
"Removes all items the bot is wearing.",
115+
args("bsuit")
109116
)
110117

111118
.def("set_active_weapon",
112119
&IBotController::SetActiveWeapon,
113-
"Gives the bot a weapon."
120+
"Gives the bot a weapon.",
121+
args("weapon_name")
114122
)
115123

116124
.def("is_eflag_set",
117125
&IBotController::IsEFlagSet,
118-
"Returns whether the given effect flag is set."
126+
"Returns whether the given effect flag is set.",
127+
args("eflag")
119128
)
120129

121130
.def("run_player_move",
122131
&IBotController::RunPlayerMove,
123-
"Fires a virtual move command to the bot."
132+
"Fires a virtual move command to the bot.",
133+
args("cmd")
124134
)
125135
;
126136
}

0 commit comments

Comments
 (0)