Sign in to follow this  

Server Design

Recommended Posts

Hi I have a server design question. After reading through the posts I found that some if not all people used a command queue which is processed on the server end. I thought of implementing my network in this way for my MMORPG but I came to the problem of when a user interrupts their previous command. For example: 1) Character A moves from 0,0 to 10,10 2) Server traces a path from 0,0 to 10,10 3) When Character A is at 5,5 the user tells it to goto 7,50 The server needs to abandon the remaining path from the first call and reroute from 5,5 to 7,50. If the commands of ALL users were in the same queue then how do you replace the remaining path. OR this may be a misunderstanding on my behalf and a command queue is required for every user and every server iteration, it processes one command from the queue of each connected socket. I've been boggling my mind as to how to design this efficiently and simply. Thanks for any comments!

Share this post

Link to post
Share on other sites
You don't replace commands. User cancelling something doesn't mean you manipulate the command stream.

Command stream is a sequence of commands. "Cancel Action" is a command.

Now it's up to you to establish the causality and synchronization.

In your case you don't even have those problems. When user selects a new destination, new path is simply calculated. That's it.

A very simple way of enforcing time order is bucket synchronization. For 100ms, you collect the commands from all clients. During the same time, you process commands from previous 100ms collection.

Most importantly, the user didn't cancel the action, so you don't replace the command.
1) "MoveToCommand(10, 10)"
2) "MoveToCommand(7, 50)"

on 1) Calculate path from current position to (10, 10) -> (0,0), (1, 1), ... (10, 10)
on 2) We're at (5,5). Calculate path to (7,50) -> (5, 6), (5, 7), ... (7, 50)

On each server tick you have an interpolator or some other means of pointing at which location each unit is. You can do this simply by setting unit's current location to first element of the path array, then deleting that element. Once the array is empty, unit stops.

Note that client can do the same. You don't need to send full array, or unit updates on every tick, since client is just as capable of this interpolation.

Share this post

Link to post
Share on other sites
Also the client shouldn't give orders to the server. It should just pass along commands like, "forward was pressed". Then the server determines what to do and where the client goes, passing this info back to the client ordering it move the player. You queue them up server side and process. Of course you can add in priority levels so some things can get bumped ahead.

Share this post

Link to post
Share on other sites
Thanks for the replies. I have a better understanding of what to do now. As it stands now I have every client connection running as a seperate thread on the server end to receive messages simultaneously. I would presume this "100ms" quantum would be used as a seperate thread to process all the bufferred messages in the previous 100ms?

0-100) Receive messages from all clients (n threads for n users)
100-200) Process messages from 0-100 (1 server thread)
100-200 (at the same time) ) continue to receive messages from all clients (n threads from before)
200-300) process messages from 100-200 (1 server thread)

The reason why I think I need a seperate server thread is because the main server process idles on winsock's accept call to listen for any incoming connections.

I didn't know that the solution was this simple. I spent all week thinking of ways to interrupt the command stream =(. It was worth a shot though =D.

However, as you suggested interpolation would be a good choice. Which I think is an awesome way to save bandwidth and perhaps other methods of using dead reckoning, but IF for example an attack command is issued, I presume you would have to calculate the distance to the target using the target's interpolated location and pray that everything is in sync? I remember playing RO back in the days and weird things happening when the server was lagging and the interpolated positions were all over the place and no where near where I wanted to go ^^.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this