From c5fa7354bb17ce41a292282a14c92eff3e2ba5ab Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 6 Aug 2024 13:15:55 +0200 Subject: [PATCH] [MP] Fix relay protocol routing with negative targets Godot supports sending messages to "all but one peer" by sending a packet with a negative target (the negated ID of the excluded peer). The relay protocol was incorrectly interpreting the values and relaying the message to the wrong peers. This issue only affected "send_bytes" since the other subsystem (RPC and replication) "resolves" the correct IDs client-side (to match visibility information). --- modules/multiplayer/scene_multiplayer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp index 6694376b306..e245101eebd 100644 --- a/modules/multiplayer/scene_multiplayer.cpp +++ b/modules/multiplayer/scene_multiplayer.cpp @@ -321,21 +321,24 @@ void SceneMultiplayer::_process_sys(int p_from, const uint8_t *p_packet, int p_p multiplayer_peer->set_transfer_mode(p_mode); multiplayer_peer->set_transfer_channel(p_channel); if (peer > 0) { + // Single destination. multiplayer_peer->set_target_peer(peer); _send(data.ptr(), relay_buffer->get_position()); } else { + // Multiple destinations. for (const int &P : connected_peers) { // Not to sender, nor excluded. - if (P == p_from || (peer < 0 && P != -peer)) { + if (P == p_from || P == -peer) { continue; } multiplayer_peer->set_target_peer(P); _send(data.ptr(), relay_buffer->get_position()); } - } - if (peer == 0 || peer == -1) { - should_process = true; - peer = p_from; // Process as the source. + if (peer != -1) { + // The server is one of the targets, process the packet with sender as source. + should_process = true; + peer = p_from; + } } } else { ERR_FAIL_COND(p_from != 1); // Bug.