Search code examples
iosmobilemultiplayerhigh-load

Building Turn-based Multiplayer Game Server


I started to make multiplayer game but as I have no expirience I tried it different ways but something doesn't feel right to me. So, I really need an advice about which platforms/tools/languages/techniches I should use best. I must say that I don't believe in things such as: Photon, AppWrap, Skiller, Gamooga and others. I dont believe they will scale great and it won't be too pricey, or they are too big (I don't mean size, I mean how much things they has that I don't need) for my needs.

First, I'll describe simplified game session proccess.

  1. Three players starting the game session
  2. Each player receives a question and should answer within 10 seconds.
  3. When player answered he should be able to see any answers that were given already by any other players (if any) and he should be able to see any answer given as soon as it was given. Basically, any answers should be received by other clients in realtime but only after we answered (to avoid cheating). If time is out then any who doesn't answered will receive no score and next question goes.
  4. Deciding winner and goes to the next question. Finish the game session after N rounds.

Second, I'll explain few requirements that I taken into consideration.

  • Game should be run on iOS/Android/Web. This leaves me no choice but to make it based on HTTP.
  • I looked for Google Cloud Endpoints about which I was really enjoyed. It has iOS/Android/JS SDKs, Google Cloud Platform has Google BigQuery, and many other great things. But because I need realtime answer delivery I don't know if that suitable (there is Channel API but no client SDK for iOS, and people saying its not that good).
  • Then I looked for Node.js and long polling (AFNetworking on client side) but it is so hard to manage. I need to serve game state updates to clients (and I need to send deltas). That way I need to track all changes individually for each player. And when player connects I should check if there any changes already; if it is then send right away; if it isn't then listen for 'change' event and then send. In the end code looks so awkward and hard to understand and I don't know how to make it right. There is socket.io which should make things better on the server side but again no iOS SDK for client.

I don't know where to go from here. Any help would be very appreciated.


Solution

  • Turn based architectures are actually not too complicated as lag is really not a huge concern, and data is not being sent constantly.

    I would create two web services, one for matchmaking and another to handle the actual game.

    The matchmaking would simply queue up players, when there were enough for a match, the service would pick a group of players and assign them a sessionID and pass the players to the game service.

    For the game service, it is important to differentiate what can be handled on the client and the service.

    The game service would store all game information for each sessionID including clients. This would allow a single service to manage hundreds of games at once with ease. When a player answered a question it would send that in a request to the server with the sessionID. The server would iterate over the clients in the session and send the information to them.

    The client could handle hiding questions until the user has answered. (You could even encrypt the other question information if you were concerned about hacking).

    The server would also track the timer for the session, when the timer expired it would send a response to all the clients, as well as ignore any later answers. A round integer could be stored in the session, and wrapped in communication with sessionID so as to differentiate answers to past questions. You could have a timer for prediction on the client, but the server needs to be the authority over the timer to avoid cheating.