Skip to content

Commit

Permalink
Add OnServerHibernationUpdate forward (closes #1483) (#2151)
Browse files Browse the repository at this point in the history
* Add OnServerHibernationUpdate forward (closes #1483)

* Clarify hibernation state

* make it 2 forwards instead of 1

---------

Co-authored-by: Odin Landers <[email protected]>
  • Loading branch information
ojlanders and Odin Landers authored May 7, 2024
1 parent 908ffdb commit e60c672
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/PlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ bool g_OnMapStarted = false;
IForward *PreAdminCheck = NULL;
IForward *PostAdminCheck = NULL;
IForward *PostAdminFilter = NULL;
IForward *ServerEnterHibernation = NULL;
IForward *ServerExitHibernation = NULL;

const unsigned int *g_NumPlayersToAuth = NULL;
int lifestate_offset = -1;
Expand Down Expand Up @@ -203,6 +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);
ServerEnterHibernation = forwardsys->CreateForward("OnServerEnterHibernation", ET_Ignore, 0, NULL);
ServerExitHibernation = forwardsys->CreateForward("OnServerExitHibernation", ET_Ignore, 0, NULL);

m_bIsListenServer = !engine->IsDedicatedServer();
m_ListenClient = 0;
Expand Down Expand Up @@ -254,6 +258,8 @@ void PlayerManager::OnSourceModShutdown()
forwardsys->ReleaseForward(PreAdminCheck);
forwardsys->ReleaseForward(PostAdminCheck);
forwardsys->ReleaseForward(PostAdminFilter);
forwardsys->ReleaseForward(ServerEnterHibernation);
forwardsys->ReleaseForward(ServerExitHibernation);

delete [] m_Players;

Expand Down Expand Up @@ -778,6 +784,11 @@ void PlayerManager::OnSourceModLevelEnd()

void PlayerManager::OnServerHibernationUpdate(bool bHibernating)
{
cell_t 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.
*/
Expand Down
12 changes: 12 additions & 0 deletions plugins/include/clients.inc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ forward Action OnClientPreAdminCheck(int client);
*/
forward void OnClientPostAdminFilter(int client);

/**
* 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.
*/
forward void OnServerEnterHibernation();

/**
* Called directly before the server leaves hibernation.
*/
forward void OnServerExitHibernation();

/**
* Called once a client is authorized and fully in-game, and
* after all post-connection authorizations have been performed.
Expand Down

0 comments on commit e60c672

Please sign in to comment.