|
9 | 9 | import socket |
10 | 10 | from enum import IntEnum |
11 | 11 | from urllib.error import URLError |
| 12 | + |
12 | 13 | # Source.Python Imports |
13 | | -# Cvars |
14 | | -from cvars import ConVar |
15 | | -from cvars import cvar |
16 | 14 | # Core |
17 | 15 | from core import AutoUnload |
| 16 | +from core import SOURCE_ENGINE |
18 | 17 | from core.settings import _core_settings |
19 | 18 | from core.version import get_last_successful_build_number |
20 | 19 | from core.version import is_unversioned |
21 | 20 | 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 |
22 | 28 | # Players |
23 | 29 | from players.constants import PlayerButtons |
24 | 30 | # Loggers |
@@ -519,3 +525,30 @@ def _pre_call_global_change_callbacks(args): |
519 | 525 | convar = make_object(ConVar, args[1]) |
520 | 526 | old_value = args[2] |
521 | 527 | 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