Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I know that synchronization is a huge topic, so I have minimized the problem to this example case.

Let's say, Alice and Bob are playing a P2P game, fighting against each other. If Alice hits Bob, how should I do the network component to make Bob's HP decrease?

I can think of two approaches:

  1. Alice perform a Bob.HP--, then send Bob's reduced HP to Bob.
  2. Alice send a "I just hit Bob" signal to Bob. Bob checks it, and reduce its own HP, then send his new HP to everyone including Alice.

I think the second approach is better because I don't think a player in a P2P game should be able to modify other players' private fields. Otherwise cheating would be too easy, right?

My philosophy is that in a P2P game especially, a player's attributes and all attributes of its belonging objects should only be updated by the player himself. However, I can't prove that this is right. Could someone give me some evidence? Thanks :)

Unfortunately, without a (trusted, independent) 3rd party, stopping the other party from cheating is impossible. The design of your game may limit the extent of cheating; however, in any situation where either party can be (and is equally likely to be) hostile, you need somebody they both will trust. –  Clockwork-Muse Sep 6 '12 at 20:46

1 Answer 1

It's not good practice to directly alter other players' properties, so I would recommend your second option.

Though I would also recommend adding checks to make sure that peers don't spam "I hit you" messages without actually having hit the player.

To limit cheating as much as possible without a server, the only messages you should be sending should be player input. Then both clients simulate the gameplay locally, and come to the same solution. So if you're making a fighting game, player A says, "I'm starting my kick" and 6 frames later player B thinks, "welp I got hit by the kick now" instead of player A potentially sending "I hit you for 1 billion damage" 20 times every frame. –  TheMaster42 Sep 6 '12 at 23:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.