From 53e9972b1bfac88d7945e6fc32d02b206f0d9074 Mon Sep 17 00:00:00 2001 From: Odin Landers Date: Sun, 5 May 2024 23:20:34 -0400 Subject: [PATCH 1/3] Add OnServerHibernationUpdate forward (closes #1483) --- core/PlayerManager.cpp | 7 +++++++ plugins/include/clients.inc | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 3feb79478e..f938ca0114 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -59,6 +59,7 @@ bool g_OnMapStarted = false; IForward *PreAdminCheck = NULL; IForward *PostAdminCheck = NULL; IForward *PostAdminFilter = NULL; +IForward *ServerHibernationUpdate = NULL; const unsigned int *g_NumPlayersToAuth = NULL; int lifestate_offset = -1; @@ -203,6 +204,7 @@ void PlayerManager::OnSourceModAllInitialized() PreAdminCheck = forwardsys->CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1); PostAdminCheck = forwardsys->CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1); PostAdminFilter = forwardsys->CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1); + ServerHibernationUpdate = forwardsys->CreateForward("OnServerHibernationUpdate", ET_Ignore, 1, NULL, Param_Cell); m_bIsListenServer = !engine->IsDedicatedServer(); m_ListenClient = 0; @@ -254,6 +256,7 @@ void PlayerManager::OnSourceModShutdown() forwardsys->ReleaseForward(PreAdminCheck); forwardsys->ReleaseForward(PostAdminCheck); forwardsys->ReleaseForward(PostAdminFilter); + forwardsys->ReleaseForward(ServerHibernationUpdate); delete [] m_Players; @@ -778,6 +781,10 @@ void PlayerManager::OnSourceModLevelEnd() void PlayerManager::OnServerHibernationUpdate(bool bHibernating) { + cell_t res; + cell_t data = static_cast(bHibernating); + ServerHibernationUpdate->PushCell(data); + ServerHibernationUpdate->Execute(&res); /* If bots were added at map start, but not fully inited before hibernation, there will * be no OnClientDisconnect for them, despite them getting booted right before this. */ diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index d88262f1c1..a5f6487a6d 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -215,6 +215,15 @@ forward Action OnClientPreAdminCheck(int client); */ forward void OnClientPostAdminFilter(int client); +/** + * Called directly before the server hibernation state changes. + * This is your last chance to do anything in the plugin before + * hibernation occurs, as SV_Frame will no longer be called. + * + * @param state The new hibernation state. + */ +forward void OnServerHibernationUpdate(bool state); + /** * Called once a client is authorized and fully in-game, and * after all post-connection authorizations have been performed. From 27e25fc549df4737ca4b2da867e0ebd2d2843fda Mon Sep 17 00:00:00 2001 From: ojlanders <143576142+ojlanders@users.noreply.github.com> Date: Mon, 6 May 2024 02:34:01 -0400 Subject: [PATCH 2/3] Clarify hibernation state --- plugins/include/clients.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index a5f6487a6d..2a266d1917 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -220,7 +220,7 @@ forward void OnClientPostAdminFilter(int client); * This is your last chance to do anything in the plugin before * hibernation occurs, as SV_Frame will no longer be called. * - * @param state The new hibernation state. + * @param state The new hibernation state (true for hibernating, false for not). */ forward void OnServerHibernationUpdate(bool state); From 4751ef6871fbc35beb29f8592aa4d5e1e5e60063 Mon Sep 17 00:00:00 2001 From: Odin Landers Date: Mon, 6 May 2024 13:12:23 -0400 Subject: [PATCH 3/3] make it 2 forwards instead of 1 --- core/PlayerManager.cpp | 16 ++++++++++------ plugins/include/clients.inc | 11 +++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index f938ca0114..1d541daa36 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -59,7 +59,8 @@ bool g_OnMapStarted = false; IForward *PreAdminCheck = NULL; IForward *PostAdminCheck = NULL; IForward *PostAdminFilter = NULL; -IForward *ServerHibernationUpdate = NULL; +IForward *ServerEnterHibernation = NULL; +IForward *ServerExitHibernation = NULL; const unsigned int *g_NumPlayersToAuth = NULL; int lifestate_offset = -1; @@ -204,7 +205,8 @@ void PlayerManager::OnSourceModAllInitialized() PreAdminCheck = forwardsys->CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1); PostAdminCheck = forwardsys->CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1); PostAdminFilter = forwardsys->CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1); - ServerHibernationUpdate = forwardsys->CreateForward("OnServerHibernationUpdate", ET_Ignore, 1, NULL, Param_Cell); + ServerEnterHibernation = forwardsys->CreateForward("OnServerEnterHibernation", ET_Ignore, 0, NULL); + ServerExitHibernation = forwardsys->CreateForward("OnServerExitHibernation", ET_Ignore, 0, NULL); m_bIsListenServer = !engine->IsDedicatedServer(); m_ListenClient = 0; @@ -256,7 +258,8 @@ void PlayerManager::OnSourceModShutdown() forwardsys->ReleaseForward(PreAdminCheck); forwardsys->ReleaseForward(PostAdminCheck); forwardsys->ReleaseForward(PostAdminFilter); - forwardsys->ReleaseForward(ServerHibernationUpdate); + forwardsys->ReleaseForward(ServerEnterHibernation); + forwardsys->ReleaseForward(ServerExitHibernation); delete [] m_Players; @@ -782,9 +785,10 @@ void PlayerManager::OnSourceModLevelEnd() void PlayerManager::OnServerHibernationUpdate(bool bHibernating) { cell_t res; - cell_t data = static_cast(bHibernating); - ServerHibernationUpdate->PushCell(data); - ServerHibernationUpdate->Execute(&res); + if (bHibernating) + ServerEnterHibernation->Execute(&res); + else + ServerExitHibernation->Execute(&res); /* If bots were added at map start, but not fully inited before hibernation, there will * be no OnClientDisconnect for them, despite them getting booted right before this. */ diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index a5f6487a6d..51ed0bb1ef 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -216,13 +216,16 @@ forward Action OnClientPreAdminCheck(int client); forward void OnClientPostAdminFilter(int client); /** - * Called directly before the server hibernation state changes. + * Called directly before the server enters hibernation. * This is your last chance to do anything in the plugin before * hibernation occurs, as SV_Frame will no longer be called. - * - * @param state The new hibernation state. */ -forward void OnServerHibernationUpdate(bool state); +forward void OnServerEnterHibernation(); + +/** + * Called directly before the server leaves hibernation. + */ +forward void OnServerExitHibernation(); /** * Called once a client is authorized and fully in-game, and