Our game uses Google Play Services for authentication, multiplayer and cloud saves. We save the users inventory as a cloud save, and as the player partakes in multiplayer matches they might use items out of their inventory (coins, etc). Also, they may use in app purchases to add items to their inventory.

I want to try and avoid the hassle of cloud save game conflicts when the player (for whatever reason) decides to play the game on 2 devices at the same time.

I worry they may lose data when resolving save games and as their save games may contain coins and other items obtained via IAPs, this is unacceptable.

Is there a way to check if the user is currently logged in to the game on anther device and is actively playing on that device? We don't have our own servers and use GPS for all our work. What is a possible solution here?

  • 1
    \$\begingroup\$ Have you tried setting a bit when the player connects to your server, then unsetting it when they disconnect and disallowing connections while the bit is set? (Am I missing something?) \$\endgroup\$
    – Anko
    Commented Oct 11, 2014 at 19:17
  • \$\begingroup\$ Sure, considered that, but they'd have to manually log in and out. I'd like then to be able to put down the phone, pick up their tablet, and carry on playing. Also, if they have to manually sign out what happens if they loose their phone? \$\endgroup\$
    – Prodigga
    Commented Oct 11, 2014 at 21:23
  • 1
    \$\begingroup\$ You could just make the game automatically use whichever one was opened most recently. So when a new one connects it transfers over to that one and disconnects whatever was there before. That way, they cant have it open on more than one device at a time but they don't have to log out. \$\endgroup\$
    – Chachmu
    Commented Oct 12, 2014 at 0:39
  • \$\begingroup\$ I am a little confused with your suggestion, so we make note of what device is currently 'playing' the game in the save file, so if another device pulls down the cloud save it will see that the file is busy? This would work, except I have no way to actively disconnect a device from the save file (ie: when the user goes offline all of a sudden, or if the user shuts down the app). This would 'lock up' the file. \$\endgroup\$
    – Prodigga
    Commented Oct 12, 2014 at 3:57
  • \$\begingroup\$ @Prodigga Why can't you "actively" disconnect a user? Just have the client ping a "are we good" request every 5 seconds and if the server sees someone new connected with that identity, it tells the old one it's time to break up; polling, it's that simple. Most MMOs use it. \$\endgroup\$
    – AturSams
    Commented Oct 21, 2014 at 7:25

1 Answer 1


The client side asks the service "Am I allowed to keep playing with you?" every five seconds and the server responds with true or false. You store the date value that represents the last time the player "pinged" the service. Also store a single session key that is randomized and sent to the client upon logging in or at the beginning a game (if no login is needed). The client keeps polling with a packet or http request or whatever is good for you that tells the server and in turn, the database the player is connected and active.

When someone connects the server with the same identity, the server replaces the session key. When the previous player or device continues to communicate with the old session key, they get informed that they have been disconnected because someone connected the game with their identity from another device. This happens as a response to the "Are we still good packet".

The alternative is to check when was the last time the user with this identity was alive and if that date is less than say 15 seconds ago, tell the new person / device attempting to connect that this account is already active.

As you may have constraints as far as the amount of requests that could be made to the server, simply add this "You are still allowed to play" response as an answer to every request you are already making. Only save player state when they make a valid request and they are still allowed to play the game.

Like you suggested, you could store the unique session ID in the saved state, if a player logs in from another device, they will do a login request, randomize another session ID and update the DB. When the other device makes any request, the server will kindly notify them this session has been discontinues as another session was started with a different device.

This way it won't cost you any additional API calls (I think).

After reading this question once more, I wonder if you could simply save the state for multiple devices like branches, then perhaps merge the delta as needed. Instead of overwriting, load the current state that will describe the the amount of achievements and or accomplishments on each device so far and when you save back, save changes for the currently used device.

  • \$\begingroup\$ Let me know if this makes sense and if you need more details. \$\endgroup\$
    – AturSams
    Commented Oct 21, 2014 at 7:22
  • 1
    \$\begingroup\$ Yes, totally, though that means I need my own server which is what I was trying to avoid. Maybe I can replicate that using another save slot in the users cloud saves to store the active "session key". Though I guess that would mean I would have to keep polling Google to see if the data has changed, and I think I'd chew through my API calls pretty quickly that way. \$\endgroup\$
    – Prodigga
    Commented Oct 21, 2014 at 11:04
  • 1
    \$\begingroup\$ I am not sure you specified all the constraints? So what are you allowed to do on the server and how often? \$\endgroup\$
    – AturSams
    Commented Oct 21, 2014 at 11:07
  • 1
    \$\begingroup\$ It's just using the Google Play Services. Nothing Else. I don't have a personal server to use. The GPS offers a cloud saving solution, which is what I use to sync the users game across multiple devices. No 'servers' are involved other than the GPS servers. \$\endgroup\$
    – Prodigga
    Commented Oct 21, 2014 at 12:34
  • \$\begingroup\$ If you have a database then you can add a lastSessionID in there like you suggested and only check it when you are pulling data from the GPS. From what you said I understand this is multiplayer so it should be commonly accessed every minute or so at least? \$\endgroup\$
    – AturSams
    Commented Oct 21, 2014 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .