sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

Add OnServerHibernate() and OnServerHibernate_Post() forwards

Open PlayBoy31 opened this issue 4 years ago • 4 comments

Hello,

Can some implement a forward to be notified when server goes on hibernate state please?

Cases for exemple:

  • setup plugins/scripts just before hibernate
  • make sql queries just before the sleep (because we need to use the main thread before it sleep, otherwise it can cause troubles)
  • others actions that must be done when the server goes in this state

2 forwards like OnServerHibernate() and OnServerHibernate_Post() will be very nice !

PlayBoy31 avatar Apr 20 '21 15:04 PlayBoy31

Why not just use the last client disconnecting from the server?

I'm not sure any forward here would be useful for executing further async work, as you'll have no way to keep the server ticking until your results are processed.

asherkin avatar Apr 20 '21 16:04 asherkin

Why not just use the last client disconnecting from the server?

That was my first idea but there is 2 problems:

1st: When on map start, no way to detect this state if server go to hibernate state directly after the mapstart 2nd: When server change map, all players go throught disconnect, its not a hibernate state and no way to filter this case (mapend arrive after players disconnections).

PlayBoy31 avatar Apr 20 '21 23:04 PlayBoy31

Wow! Great idea.

I'm not sure any forward here would be useful for executing further async work, as you'll have no way to keep the server ticking until your results are processed.

But you can assign this to the system in the game thread and an asynchronous response when the server is unfrozen in theory.

Wend4r avatar Apr 21 '21 00:04 Wend4r

2nd: When server change map, all players go throught disconnect, its not a hibernate state and no way to filter this case (mapend arrive after players disconnections).

That's not correct. You are able to filter really disconnected players using "player_disconnect" game event. Those raised only for player who disconnected themselves. Only OnClientDisconnect() forward is affected by both cases. Anyway, for the plugin to process successfully, you have to temporarily switch the state of "sv_hibernate_when_empty" ConVar. You can see an example in this plugin.

dragokas avatar Apr 26 '21 11:04 dragokas