I am thinking of writing a server-side app to support social gaming. You can identify one common feature in many social games and that is they utilize real-life time as part of the gameplay. For example, in FarmVille, you plant and water crops and after 8 real-life hours, you can harvest them. Some of these timing can be as long as 24 hours, some others are as short as 1 minute.
I want to try making a server that can handle this feature, and I have two options:
- Lazy Server / Active Client. You store the time when a task (i.e harvesting a crop) should be completed by in the database server. When a client loads up, it will get that time, and display the countdown timer from the client-side. When this timer elapses, client does a POST to the server indicating that this particular crop should progress to the next state. This moves all the processing power to the client side, and so server becomes dumb and only stores the time. This has some issues:
- Cheaters and Hacking. If someone figures out what data to send to the server, anyone will be able to cheat. This is very easy to do with wireshark and netstat.
- Activities are disabled when players are offline. There are games where that allow a player to interact with another player even when both players are offline. For example, in a game like Travian, a player can attack another player. Based on the distance of their villages and the unit types, the server calculates how long till the attack actually happens. Even when both players are offline, the attack is still happening. The accuracy of this game is down to seconds. This is not possible with this option.
- Server to continually keeps tabs of all the activities across all players, and update the timing accordingly. This seems to be the right thing to do. It prevents malformed requests from messing with the game, and it also allows certain activities to be executed even when players are offline. I don't have much experience dealing with server-side technologies, would cron do the job for this? Is cron effective in handling timing jobs from millions of players? If not, what would the be ideal program to handle this? Should I make my own app that continually update the database?