Members - Reputation: 100
Posted 20 April 2012 - 03:11 PM
Should I keep the state of the online players on the program memory or database?
Need I a gameloop on the server too, just to know the expected state of the clients, or should I just validate the player actions based on his last update?
Should the client send his state on every step he take or only in primor actions like: start walking, change direction, walk in the same direction for 70 steps, stop walking?
Should the client presume the state of the other players?
Moderators - Reputation: 8353
Posted 20 April 2012 - 03:29 PM
- Run the game on the server as well as the client, to avoid cheating. Even if it's an MMO and runs at a lower tick rate and simpler physics, you can use an FPS-style model. Sweeping spheres through a BSP tree is super cheap these days, for example.
- Keep all the game state in RAM, and checkpoint important state to database once in a while. Ideally in an incremental or asynchronous way that does not pause the simulation loop. One exception: Trade must be transactional and immediate in the database, else you'll get item duping/poofing bugs.
- I would only send controls each step, and send controls from server to other players, and send a state dump once in a while from the server. Probably more frequent state dumps for more relevant (and/or closer) objects.
- I would assume on the client that the server will accept my input, and "simulate ahead" compared to everyone else's state. This means displaying the local player "in the future" and everyone else "in the past." Other mechanisms may work just as well, too.
- I would use mechanics to hide latency. For example, wind-up for sword swing attacks; casting effects for magic; etc. This allows me to get back results from the server for whether I hit or miss.
GDNet+ - Reputation: 12023
Posted 20 April 2012 - 03:45 PM
The server probably needs a loop of some kind, because there are probably ongoing processes in your game world -- monsters need to spawn at intervals of time, mob/npc AI needs to execute, etc. There are probably many things that can be done in a stateless sort of way, but not everything.
Generally, a client sends state changes to the server when they undertake actions -- the client first checks whether it thinks the action is valid, sends the update, goes ahead with the action, receives validation(or not) from the server, and then rectifies the client state to the server's response. Given an honest client, most server responses should more-or-less match what the client thinks has happened, but if not, the server's version wins. The server always has the final say.
The client generally will update it's "view" or "version" of the game world based on the last actions it's recieved for each entity, and continue doing so while it recieves updates from the server. Generally, the server should be saying things like "Player 1 is here, facing this direction, and currently running" -- messages usually contain an "absolute" part (Player 1 is *here*, facing this *direction*), and a part that implies an action to assume until the next update (currently *running*). However, just like player initiated actions, if the server says something that diverges from what the client thinks happened, due to perhaps missing a previous update, then the client has to fall in line with the server. Usually the disparity between the client and server will be small, and you won't usually notice when the difference is rectified over a few frames. If the state diverges greatly, then the switch becomes noticable, players call this "lag", although they apply the word "lag" to other things as well.
throw table_exception("(ノ ゜Д゜)ノ ︵ ┻━┻");