I’m a novice programmer. And I’m currently working on a multiplayer Arcanoid-like (Breakout-like) game. I stated with a non-authoritative networking, but when I started using rigidbodies I understood that physics simulation can be ran only on one computer. So I started digging towards the authoritative networking. I successfully implemented it, but without client side prediction, so there was a significant lag between input and response on client. And I started digging towards client side prediction and I’ve read this two articles: “Networked Physics” by Glenn Fiedler and “Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization” by Bernier, Yahn W (PDF).
And in the latter article i found an interesting info that military simulation systems usually work with peer-to-peer networking because they are a closed system and they trust all of the clients.
And I’ve got an idea. Why can’t we do a mixed system, partly peer-to-peer and partly client server. Thats how I think it should work (for multiplayer FPS):
-
We’ve got a server. It runs all physics simulation and do all the math just like in client-server architecture.
-
We’ve got a client. It calculates movement and weapons-related code directly on the client and it sends to all other clients it’s position and weapons related info. And it sends this info to server. But it also sends to server the client’s input.
-
And server verify the client’s calculation’s about movement and weapons based on client’s input. If client’s position is correct server just sends to all clients “this client is fine”. And the game goes on.
But what if client’s calculations are not ok?
There are two cases:
-
Cheating. Client just walked through the wall or teleported 10 meters, Or it sent to all players on the level message “I just shot you all in the head with a single bullet”. Well it’s easy - we make it just a simple client like in authoritative client-server architecture. It no longer sends it’s position and weapon-related stuff to all clients. It just sends it’s input to server and server sends it’s position to all clients. And now this client that cheated is in inferior position compared to other players. But who cares - he was cheating.
-
Incorrect calculation on client.
Movement:
If there is no cheating on client than this client can be wrong in movement calculation only in one case: if it bumps into another client. Well, what to do in this case? Which client should calculate the physics and which just receive the position? I don’t know. For now I think that both clients that are too close to each other should switch to authoritative client-server architecture like in case of cheating but just for several seconds and not constantly.
Firing the weapons:
If there is no cheating than the only case when one of the clients can be wrong is situation when two players are opening fire on each other. Each sends a bullet. Each hits.
(Technically, if their weapons are not lasers each player should die. Contemporary rifles have muzzle velocity of 900 meters per second, so in 50 ms bullet will be in 45 meters from the muzzle. So both players can fire, and receive bullets and die.)
But as far as I know it’s not how it’s done in multiplayer games. At least one player should stay alive. So we just compare the timestamps on both network messages and we can see who fired first. And for matters of live and death I think clients need confirmation to start showing death animation. And they get this confirmation. From server.
So bottom line is if there is any conflict situation - server rules. And lag increases. But I’m playing CoD2:MW multiplayer now and I should tell that all those above mentioned potential conflict situations are pretty rare.
So what are pros: just one - lag reduced in half.
Cons: More traffic, the code will be more complex.
The basic idea is simple: Most people are honest. Not all are cheaters. So why should we think that all clients are cheaters. We can trust player. But still it’s better to check. Like in Russian proverb “Trust but Verify”.