Skip to content

Commit 10fa15f

Browse files
author
L'In20Cible
committed
Fix for issue #181.
1 parent 9496a62 commit 10fa15f

File tree

1 file changed

+36
-3
lines changed
  • addons/source-python/packages/source-python/listeners

1 file changed

+36
-3
lines changed

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@
99
import socket
1010
from enum import IntEnum
1111
from urllib.error import URLError
12+
1213
# Source.Python Imports
13-
# Cvars
14-
from cvars import ConVar
15-
from cvars import cvar
1614
# Core
1715
from core import AutoUnload
16+
from core import SOURCE_ENGINE
1817
from core.settings import _core_settings
1918
from core.version import get_last_successful_build_number
2019
from core.version import is_unversioned
2120
from core.version import VERSION
21+
# Cvars
22+
from cvars import ConVar
23+
from cvars import cvar
24+
# Engines
25+
from engines.server import server_game_dll
26+
# Memory
27+
from memory import get_virtual_function
2228
# Players
2329
from players.constants import PlayerButtons
2430
# Loggers
@@ -519,3 +525,30 @@ def _pre_call_global_change_callbacks(args):
519525
convar = make_object(ConVar, args[1])
520526
old_value = args[2]
521527
on_convar_changed_listener_manager.notify(convar, old_value)
528+
529+
530+
# ============================================================================
531+
# >> Fix for issue #181.
532+
# ============================================================================
533+
# Get the function name to hook...
534+
if SOURCE_ENGINE in ('bms', 'orangebox'):
535+
_hibernation_function_name = 'SetServerHibernation'
536+
elif SOURCE_ENGINE in ('blade', 'csgo', 'l4d2'):
537+
_hibernation_function_name = 'ServerHibernationUpdate'
538+
else:
539+
# To remind us to add newly supported engines...
540+
raise NotImplementedError('No hibernation function exposed.')
541+
542+
543+
@PreHook(get_virtual_function(server_game_dll, _hibernation_function_name))
544+
def _pre_hineration_function(stack_data):
545+
"""Called when the server is hibernating."""
546+
if not stack_data[1]:
547+
return
548+
549+
# Cyclic import...
550+
from filters.players import PlayerIter
551+
552+
# Notify OnClientDisconnect listener for all bots...
553+
for bot in PlayerIter('bot'):
554+
on_client_disconnect_listener_manager.notify(bot.index)

0 commit comments

Comments
 (0)