Original Post
I am wondering if what I have developed so far is a good way to approach designing a two dimensional side scrolling massively multi-player server (2000+ clients)
I have programmed and designed a "prototype" to see whether the following solution would work well:
1) Completely programmed in C#
2) Uses NoDelay TCP using .net Sockets (WinSock) therefore I am not using a network library.
3) The server only has two threads in total, one is for accepting TCP connections and another for doing everything else. The other is a high-priority thread in which I may add the task parallel library (TPL) to later on. All this thread does is download traffic, then update the world, then upload all traffic (including any updated world objects from the previous world update) then check the connection status of all connected players, this loops every 16.6667 milliseconds.
4) Data is only sent when someone actually DOES something, i.e. nothing will happen if no one moves, even when someone starts moving left only 1 message would have been sent to all connected players (including the person that moved in the first place) until there is another message indicating this player has stopped (the move key on the keyboard has been released). Both start moving/stop moving messages sent from the server contain positions of where the player started moving from and where the player stopped moving from and the reason for this is so that the server can sync all connected players seamlessly. For example, when the client receives a start moving from here (x,y) the client program is then on its own and updates the player's position each frame starting from the (x,y) position that was received in the message. The same thing happens when the client receives a stop moving from here (x,y), in which the client starts moving the velocity to 0 of the specified player that was moving in the first place.
5) The whole game is server-based, players have no authority at all (AT ALL). When a player wants to move the input gets sent to the server in which the server transmits back where the player should start moving from. Same thing happens for a client to stop moving.
6) I am designing two programs and one library, which includes: the client, the server and the library that both client and server use. The client code and server code will probably 50% similar, the reason why I am doing this is so I can design the server as efficiently as possible.
Result: IT WORKS (haven't tested it large scale yet though)! The only problem I am seeing though is that it is completely server based, if a player that has 300 latency presses the key to move right, they would only move right after 300 milliseconds PLUS the frame time (16.66667). I'm thinking of making the client's player be client-based so they move instantly but if this is the case I will need to make sure the client can send a "I STARTED MOVING LEFT FROM HERE" message and make sure the server checks if the player is not x-units away from the last received position, if it is though the server has authority and moves the player back to the right position.
The question: Id would just like to know what other programmers thing about this approach. I probably wrote this awfully but I am usually terrible at writing what my own code does, sorry :|
All replies are greatly appreciated.
Thanks, Xanather.
I have programmed and designed a "prototype" to see whether the following solution would work well:
1) Completely programmed in C#
2) Uses NoDelay TCP using .net Sockets (WinSock) therefore I am not using a network library.
3) The server only has two threads in total, one is for accepting TCP connections and another for doing everything else. The other is a high-priority thread in which I may add the task parallel library (TPL) to later on. All this thread does is download traffic, then update the world, then upload all traffic (including any updated world objects from the previous world update) then check the connection status of all connected players, this loops every 16.6667 milliseconds.
4) Data is only sent when someone actually DOES something, i.e. nothing will happen if no one moves, even when someone starts moving left only 1 message would have been sent to all connected players (including the person that moved in the first place) until there is another message indicating this player has stopped (the move key on the keyboard has been released). Both start moving/stop moving messages sent from the server contain positions of where the player started moving from and where the player stopped moving from and the reason for this is so that the server can sync all connected players seamlessly. For example, when the client receives a start moving from here (x,y) the client program is then on its own and updates the player's position each frame starting from the (x,y) position that was received in the message. The same thing happens when the client receives a stop moving from here (x,y), in which the client starts moving the velocity to 0 of the specified player that was moving in the first place.
5) The whole game is server-based, players have no authority at all (AT ALL). When a player wants to move the input gets sent to the server in which the server transmits back where the player should start moving from. Same thing happens for a client to stop moving.
6) I am designing two programs and one library, which includes: the client, the server and the library that both client and server use. The client code and server code will probably 50% similar, the reason why I am doing this is so I can design the server as efficiently as possible.
Result: IT WORKS (haven't tested it large scale yet though)! The only problem I am seeing though is that it is completely server based, if a player that has 300 latency presses the key to move right, they would only move right after 300 milliseconds PLUS the frame time (16.66667). I'm thinking of making the client's player be client-based so they move instantly but if this is the case I will need to make sure the client can send a "I STARTED MOVING LEFT FROM HERE" message and make sure the server checks if the player is not x-units away from the last received position, if it is though the server has authority and moves the player back to the right position.
The question: Id would just like to know what other programmers thing about this approach. I probably wrote this awfully but I am usually terrible at writing what my own code does, sorry :|
All replies are greatly appreciated.
Thanks, Xanather.