Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OnServerHibernationUpdate forward (closes #1483) #2151

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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