Sunday, July 29, 2018

c# - How can I handle game-state updates in an MMO while the player is logged out?


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 ;)



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...