Advertisement

Ongoing game connection over potentially days

Started by May 16, 2017 07:43 PM
20 comments, last by flodihn 7 years, 6 months ago

the last PN you received might not contain the most recent game state


Push notifications should generally not contain the full state, but instead just be a signal that it's time for the app to go fetch the state from the server.
The app should also treat "user started/brought to foreground" as a signal to go to server and get latest state.
Finally, because nothing is perfect, you could also arrange to do that check, say, every 8 hours. How you do this varies by OS, and by how far back in OS version compatibility you want to go.
Android allows you to start system services, which can run in the background. iOS needs to have you ask for notifications/schedules explicitly, and doesn't allow arbitrary background services.

I would probably not fall back to email, though. Users who care will likely enable push notifications, or check the game manually ("is it my turn yet?") and the every-8-hours or whatever check will take care of the rest.
enum Bool { True, False, FileNotFound };

This is how I would do it.

  1. Make a authoritative server where clients can use a RestFUL protocol to create/join/leave/play a game. I would use json structures to save the whole state of a game.
  2. Make a unique ID for each created game session and store in the database.
  3. Make the game session have two modes, active and deactived.
  4. When a game session is active, the json structure is stored in the servers memory. If no action from a player happens within a reasonable time, lets say 10-15 minutes, zip the game state, dump it to a key/value database and mark the game session as deactived.
  5. When a game session is deactiveced, but a player makes a play operation request, load the game state from db, unzip and mark game session as active.

Before starting, I would look up things such as this on the Internet: "restful design best practices", "key value databases", "best restful api frameworks".

PS. also a push notification sent out to all clients when a turn has been completed is probably a good idea, so clients does not have to poll all the time.

This topic is closed to new replies.

Advertisement