I have a plan to build MMO strategy game like Goodgame Empire or Travian for Windows Phone. I want to program it in C# Monogame (because I have some good experience with it).

But I still can't figure out how to do game-server communication.

My plan is communicate with database through web service (WCF).

For example, if player build some building then the game saves information about that building through a web service method to a database.

But what if the player isn't logged in?

For example farms produce some food every hour. How to count how much food the player has when he logs into game after some time?

If you have some idea please let me know ;)


1 Answer 1


Your server would have some kind of background process (could also be implemented as a timer or a thread) which runs at regular intervals and updates all players. The process would run daily, hourly or every few minutes depending on how often you want the players farms to update and generate resources.

Any online players would get notified immediately that their resource count changed. Any offline players would get notified about their new resource count as soon as they are logged in.

An alternative solution would be to update the resource count of an offline player as soon as they log in. You check how much time has passed since they last logged out and update their resource count accordingly. But keep in mind that this makes offline interaction difficult. When other players can see the resources of another player, they won't get an up-to-date number before the player logged in. Checking whether or not the resources of a player grows could be used to see when they are online which might violate their privacy and/or might give the other player knowledge about their opponents online behavior you don't want them to have. Another problem you might run into is that it might get difficult to make sure that offline- and online processing work in exactly the same way. Subtle differences between them could lead to exploitable bugs.

  • \$\begingroup\$ You don't need a background process. Production of resources is often a fixed formula. (1 farm produces 2 food per hour, so if you have 3 farms, and you log in after 4 hours you will have farmsunitstime = 3 * 2 * 4 = 24 more food than before. \$\endgroup\$
    – Roy T.
    Sep 19, 2014 at 8:09
  • 1
    \$\begingroup\$ @RoyT. But what if the player logs out and in 1.2 hours the farm they build is finished and starts producing food, in 2.3 hours they are sabotaged and two farms stop working for 3 hours, in 3.2 hours their ally accepts their trade deal to exchange 100 food for 50 iron, in 3.7 hours someone steals 50% of their then-current food stock and in 6 hours they log in again. How are you going to reconstruct the gamestate after all this has happened? Sure, it might be possible with lots of clever code, but just having a background process handling all this when it happens might be simpler. \$\endgroup\$
    – Philipp
    Sep 19, 2014 at 8:18
  • 1
    \$\begingroup\$ You should not be calculating any that on the client. The server will do the math, its a very tiny amount, and update the client when it connects. If you don't, there will be exploits. \$\endgroup\$ Sep 19, 2014 at 13:13
  • 1
    \$\begingroup\$ @Philipp these more complicated processes can still be calculated once the client logs in, as long as these events are time stamped it is very easy to calculate. \$\endgroup\$
    – Roy T.
    Sep 21, 2014 at 15:58

You must log in to answer this question.

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