Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Do I need a gameloop on the server too?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 melanke   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 April 2012 - 03:11 PM

I'm working on an MMORPG and it is going really well, but I am taking a time to research the better way to keep data of server and client synchronized, avoid hack and overprocessing.

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?

Thank you

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5725

Like
0Likes
Like

Posted 20 April 2012 - 03:29 PM

Without knowing more about your specific constraints and requirements, I would suggest:

- 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.


enum Bool { True, False, FileNotFound };

#3 Ravyne   GDNet+   -  Reputation: 8193

Like
0Likes
Like

Posted 20 April 2012 - 03:45 PM

Databases are for persistence--that is, if the state represents something that's going to matter the next time the player logs on, then it needs to go into the database. If its something that isn't going to matter, then it can sit in RAM. Now, because hitting a database frequently for small bits of data is a lot of overhead, you're going to cache information related to the players that are online in RAM to speed up access.

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS