Jump to content
kaleb c0d3

Clientside OnPlayerDisconnected Event Handler

Recommended Posts

Sup all!

 

Do you know if there's a event handler that fires from the client side when the player disconnects? I'm working on a survival mod wich persists player info into a database, and need to force an update when the client disconnects. If I use the serverside events (HandleDisconnect, onPlayerDisconnected, and so on), some player data is not available because the client is no more online, and cannot query for it.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
2 hours ago, kaleb c0d3 said:

Sup all!

 

Do you know if there's a event handler that fires from the client side when the player disconnects? I'm working on a survival mod wich persists player info into a database, and need to force an update when the client disconnects. If I use the serverside events (HandleDisconnect, onPlayerDisconnected, and so on), some player data is not available because the client is no more online, and cannot query for it.

 

Thanks in advance.

 

Depends what you're after, do you want to handle players quitting or their game crashing?

 

If the former @sarogahtyp got you covered.

 

If the latter those are harder to reliably catch client-side. I recommend implementing an autosave, periodically query the player for their latest info and store that. As long as the query isn't too heavy you should be able to do it often enough the player shouldn't notice any major loss of play.

 

Edit: Obviously if you want both you may implement both. 😛

  • Like 1

Share this post


Link to post
Share on other sites

Thank you @sarogahtyp & @mrcurry. I already have the 'autosave' mechanic, with a configurable frequency (1 per minute atm).
I have 2 different scenarios for wich I need a disconnect EH on the client-side:

1. Player lost connection: I have the last autosave data, <= 1 minute of the last save. No major problem here... it is obvious that the client went on a critical state and any data (updated or not) is better than nothing. 
2. Player quits (via menu or alt+f4): I want to take that 'last update before leaving', so when the player comes back, will be in the exact same state. I think the 'save on pause menu' is a good approach; not the best, but a very good one.

 

Extra: performance wise, I've made the persistence engine this way:

Client request save to server >>> Server saves data via API to a webservice >>> Client gets operation status

Doing this, the server only have to kick the api with the data, and all the database stuff is made on another hardware. Very low performance impact so far.
The webservice is running in a Debian 11: Laravel APP, MySQL, Apache, running smoothly.

Share this post


Link to post
Share on other sites
2 hours ago, kaleb c0d3 said:

I think the 'save on pause menu' is a good approach; not the best, but a very good one.

The best u can get...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×