0

I have a player that is playing my game in Facebook Gameroom. In my database there is a flag telling me the player is logged in with Facebook so I can tell he is online. In Unity I have a script implementing MonoBehaviour.OnApplicationQuit() to flag the player as offline and MonoBehaviour.OnApplicationFocus(bool) to flag the player as NoFocus or AFK.

  1. Case 1: Let's say that electricity problem shuts down player's PC. How can I flag the player as offline? Is there anyway to detect that the player is shut down?
  2. Case 2: Player closes Gameroom window. Is there anyway to detect this action? OnApplicationQuit() didn't work on this.
  • Do you have a `List` with all the currently active players? – Hristo Apr 07 '17 at 11:46
  • I have a database, where every player is a record and I use a lastseen = timestamp() and a label working as a flag ONLINE and OFFLINE – SotirisTsartsaris Apr 07 '17 at 12:07
  • Well, what you could do is get the `List` of players from the database and use it in your app. Then you could show who is active/online/offline. – Hristo Apr 07 '17 at 12:11

2 Answers2

0

The standard way to handle this is to set up a timeout for your lastseen datetime stamp. Your game should refresh the time stamp regularly (such as on a timed interval, or on an event such as sending a chat message or accomplishing something)...

Then you set up a job on your database (such as an Agent Job in MSSQL Server) to pull all records logged in that the timestamp has expired. The job then changed the LoggedIn flag so that the user is logged out. Also, the job's agent could easily be a program that runs in the background on one of your servers that handles this... but, this is the basic method to handle the situations that you asked about.

Good luck and hope that this helps!!

CherryCoke
  • 309
  • 3
  • 17
0

I can offer both as a single solution:

I suggest you to ping the Internet service using a delayed loop (like wait 2sec and loop again...) and check the room window you are talking about. The sure solution for internet connections is to ping the Internet (google.com / yourhost.com)while doing this loop, in the same loop you can also check the room window