Hi there. I created a minimal authoritative backend with support for matchmaking.
It works fine, but recently I realized that I get duplicate messages on the receiver client. Basically what I do (since the game is PvP) is to store each matchmaked user as the other’s opponent with the help of a Go map (the link to the specific line) , and then use that in dispatcher to send a message coming from one user to its opponent(the link to the specific line). Now Imagine user A is local and damages B on its client, and B(which is remote on this client) registers one damage. DamageEvent is sent via Nakama socket. Local user B receives 2 damage Events on its client and reduces his hitpoint twice. Remote players cannot deal damage to local players and all damage events should come from network; for example, on B’s client, user A never damages B, even though he plays the animation. Moreover, debugging shows that both registered damage events are coming from socket. What point I’m missing?
update: let me explain more since I think the information I’m providing is misleading.
User: a player who sends/receives to/from the socket to Nakama server and runs local and remote player on an instance of the game on its client
local player: the player with input and abilities enabled
remote player: the network representation of a local player without input or abilities (no ability to deal damage, jump, etc. just simply updating positions and animations with the information sent by its local on the other User)
I am using a flow in which each damaged player tries to inform itself of the other client. It’s a PvP game and we have 2 players. Imagine on User A’s client, local player damages the remote player. The remote player has to send an event to its local player on the User B’s game instance. User A is the one who sends this event since he owns the end of the socket, so Nakama messge sender would be User A, and inside the message, I state that it is meant for local player on User B.
but what actually happen is this: local player on User A damages remote on A. remote on A queues a damage event. User A sends this event to Nakama backend. Nakama backend picks up on that message, reads its sender and when it see A sent it, decides to dispatch it to B. But on the User B side, I recieve 2 event, and local player on User B reduces twice the hitpoint it actually should have reduces.