Client/Server communication: How verbose are you?

Started by
1 comment, last by ApochPiQ 11 years, 10 months ago
I'm working on an RTS-style game, using a client/server network model. Clients are only told what they need to know (what affects or is seen by that particular player).

Basic activities have so far been pretty simple. A Unit moves, send a MoveUnit command to the client. Building gets destroyed, send a DestroyBuilding command to the client.

But now I'm starting to get into more complex activities. For example, let's say you have an action you perform at a building, which gathers multiple idle units of different types, sets them to move to the selected building, and then once they all arrive, merge them to create a new super unit. From the player's perspective, they just performed a single command. But on the server, multiple things are happening. Moving units, changing each unit's home building, creating a list of required units and waiting for each one to arrive, then destroying all of them and creating the new super unit.

My first thought was to send each little action as a separate command to the client, as I was doing before with the simple activities. Essentially, treating the client as a puppet and telling it exactly what to do at every step. However, I'm thinking that this will be overkill in terms of network traffic. And, in some cases, I wonder if the client should know more about the bigger picture, in order to better communicate that to the player.

The alternative would be to send a single command regarding the creation of the super unit, communicate the list of units to be used and what building to use, and then let the client figure out the details of navigating units and such. That fixes the bandwidth concerns and lets the client know more about what is going on. But it also makes me wonder if I would be risking the client and server going out of sync if I leave details up to the client. Just "assuming" the client is doing things right.

I know that if the server and client are running the same code for performing this command, then there shouldn't be any issues (in theory) with them making different decisions on how to perform the command. But, because the client isn't really simulating the game, only being told what is going on after the fact, I wonder if there might be issues with it not knowing enough about the game environment to simulate it properly. The client starts moving a unit to the building, but the unit passes over a part of the map that the client hasn't seen. The server knows there is an enemy building in the way, but the client doesn't yet. As soon as the unit gets close, the server tells the client about the building. But now it is up to the client to change the unit path to navigate around it properly. Is it going to make the same decision as the server, with the server knowing everything? What if the client is still navigating those units to the building when the server decides they should have already arrived, and the server starts sending commands to move the super unit, which the client hasn't created yet?

Am I being overly paranoid? Is it best in this sort of situation to treat the client as a puppet and feed it every little step, at the expense of network bandwidth, or are there ways of safely generalizing commands for the client to perform on its own?
Advertisement
for RTS you might want to look into lockstep simulation instead, that way you only have to send inputs (Which keeps traffic low even with thousands of units), the drawback ofcourse is that the client has to know everything (Which makes for example maphacks possible) and that you have to add some delay after each action (most RTS play a short "ackknowledged" animation/sound for this reason) but the alternative (sending updates for each unit) isn't really feasible unless you keep the unitcount low (Which you probably don't want to do with an RTS)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
In my experience, you're best off picking one model and sticking to it consistently.

If your server is authoritative for things like units moving, then it needs to be authoritative more or less uniformly. Allowing clients to do their own thing based on high-level commands is indeed begging for desyncs unless you have taken extreme care to keep everything in lockstep from day one. You might be unpleasantly surprised about how much drift you can get between client and server based on trivial things that you'd never think about, especially if you do any floating-point arithmetic.

Determinism is certainly possible with enough effort, but if you haven't aimed for it from day one (or if you aren't willing to do a huge amount of re-engineering) then it's a pipe dream.

I would suggest compiling some actual numbers for your bandwidth usage. If your list of commands to accomplish the super-unit construction is only 200 bytes, then who cares? If your single Move command is 200 bytes, then you need to do some more fundamental optimization to begin with.

Some context on how much you're actually sending across the wire would be very useful.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement