The game and server are written in C#. I am using async TCP sockets on both client and server components.
So far I made the gamedesign like this:
Client side:
- client connects to the server and sends his nickname (multiple clients may have the same nickname doesn't really matter)
- the client can chat with all the players connected to the server
- the client can join or create a game room (set room name, set the max players, track, password)
- the owner of the game room can start the game
- and then the racing happens
Server side (the tricky part):
- a basic client gets data asynchronously and puts it into a message queue
- made a base class named NetRoom for 3 different room types : UnnamedLobby, MainLobby, GameRoom
- a room may contain more clients
- a NetRoom has a OnTick method and a OnMessageReceived method called by the OnTick that retrives a complete message from a client
- when a client connects it is added to the UnnamedLobby until the server receives the client name, then the client is moved in the MainLobby (and I think I am going to get rid of this Room because client sends the name just after it connects)
- in the MainLobby the clients can create GameRooms
- the GameRoom handles clock sync, actual race game data, etc.
Here is the question: how do I call each room's OnTick method?
a) one thread, one loop parsing all rooms and calling their OnTick
b) one thread for each room
c) one thread, one loop parsing all rooms BUT the OnTick calls the OnMessageReceived using ThreadPool
d) on the ReceiveCallback from the client class call OnDataReceived using ThreadPool
Also if anyone thinks there is room for improvement please tell me. Some of this stuff isn't coded yet(only 2 days of coding).
EDIT: A game room should normally hold 4-8 players. And I want my server to be able to handle 30 game rooms simultaneous.
EDIT2: Added d)