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

Conversation

ojlanders
Copy link
Contributor

@ojlanders ojlanders commented May 6, 2024

Adds the OnServerHibernationUpdate forward. OnServerHibernationUpdate_Post() isn't possible to implement because there would be no place for it to be called from after SV_Frame stops executing.
Link to Discord discussion:
https://discord.com/channels/335290997317697536/335290997317697536/1236880595448233995

@ojlanders
Copy link
Contributor Author

Test script:

#include <sourcemod>

public void OnServerHibernationUpdate(bool state)
{
    PrintToServer("Server hibernation state changed to: %s", state ? "true" : "false");
}

here's the output:

sm_cvar sv_hibernate_when_empty 0
[SM] Changed cvar "sv_hibernate_when_empty" to "0".
L 05/05/2024 - 23:11:48: [basecommands.smx] "Console<0><Console><Console>" changed cvar (cvar "sv_hibernate_when_empty") (value "0")
Server waking up from hibernation
Server hibernation state changed to: false
sm_cvar sv_hibernate_when_empty 1
[SM] Changed cvar "sv_hibernate_when_empty" to "1".
L 05/05/2024 - 23:11:49: [basecommands.smx] "Console<0><Console><Console>" changed cvar (cvar "sv_hibernate_when_empty") (value "1")
Server is hibernating
Server hibernation state changed to: true

Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! - I just have some dev-user clarifications from me

* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new state? we should mention what true means here so it's clear we have begun hibernating, does false mean we have just awakened? Name it isHibernating

Copy link
Contributor Author

@ojlanders ojlanders May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a bit to explain this

*
* @param state The new hibernation state.
*/
forward void OnServerHibernationUpdate(bool state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnHibernationChanged? Update implies to me we're getting this every frame, but this could just be me..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general there's not a better way to do this: the function name "ServerHibernationUpdate" is well known, and the proper nomenclature used both in the engine and in everywhere i've seen it (like master server comms) is "hibernation state" unfortunately

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps having two forwards instead could help

  • OnServerEnterHibernation
  • OnServerExitHibernation

Would make it more clear and be less confusing than bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@psychonic psychonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@psychonic psychonic merged commit e60c672 into alliedmodders:master May 7, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants