Receiving duplicate messages from Nakama Socket on receiving client

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.
definitions:
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.

Hi @Mahdad-Baghani! :wave:

I see what you’re trying to do. What debugging steps have you taken so far - have you logged messages flowing through the match handler to check each one is only being processed once?

What client library do you use? On the receiving side is it possible you have more than one match data handler registered? If so each one will be called for every incoming message, so it’s possible it would appear as duplicate messages.

1 Like

Thanks for the direction. That was all my fault. I actually did log the outgoing and incoming message and it was the situation I explained earlier. However, what I didn’t realize was that I once subscribe to the OnReceiveMatchState and again when the player starts searching for match without noticing.
Thanks for the time.