Original Post
I'm currently in the process of designing the network component for my RTS game and therefor thinking about how I'm going to handle everything. But, I'm not really sure on how to approach things, so I figured, I'll let have some people take a look at my design and help me iron out the possible bottlenecks. To start out: I'll use a TCP and an UDP connection for in-game data transmissions. The TCP channel will be used to setup the initial connection, negotiate an UDP port number, start the game and to sychronise the game clock. Once this is done, the game can begin. The idea is this: One client serves as host. The host will be hosting the waiting room and accept new clients and display them in the waiting room. Once everyone has accepted the settings, the host will send a StartGame message to all the clients, followed by a ClockSync. Each client will respond to the ClockSync with a ClockSyncAck and set it's own clock to 0. The host will then determine the latency between the Clocksync send and the ack and send this value back to the client from which the ack came with a ClockAdjust. Each client will adjust the clock after that(No Ack to that). After this, the TCP channel will be closed. As it's an RTS, the game will be a simulation of what happens on the other side. Each client will send updates to the other clients about movement, newly issued orders, firing of bullets and major events like unit/building destruction, unit deployment, etc. Each update will be send along with a clock and the kind of update, for instance: [clock] MoveUnit [playerID]:[UnitID]:[Location] [clock] WeaponFire [playerID]:[UnitID]:[TargetLocation] [clock] BuildingDestroy [playerID]:[BuildingID] If a player's unit was send to move to a location at clock index 1520 and the current index is 1524, the unit will be given the order and immediately have the Update() called with the delta time. Every 5 seconds(or at a different time interval) a heartbeat will be sent over the UDP channel to ensure connectivity. If there hasn't been a heartbeat for 12 seconds(2 missed heartbeats), a client will send a ProbeClient message to the client it can't contact. If there hasn't been a reply to that within 5 seconds(Or a heartbeat for that matter), the client will escalate this to the others and they will decided to either await the client for another 30 seconds(Showing a dialog that the connection has been possibly dropped) or give the chance to kick the missing client and continue their things. Any flaws in my design? Are there things to improve? What would you do differently? And what data type should I use for the clock? Fixed point decimal? int64? float? Toolmaker