Skip to content

Commit c5fa735

Browse files
committed
[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).
1 parent 4359c28 commit c5fa735

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

modules/multiplayer/scene_multiplayer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,24 @@ void SceneMultiplayer::_process_sys(int p_from, const uint8_t *p_packet, int p_p
321321
multiplayer_peer->set_transfer_mode(p_mode);
322322
multiplayer_peer->set_transfer_channel(p_channel);
323323
if (peer > 0) {
324+
// Single destination.
324325
multiplayer_peer->set_target_peer(peer);
325326
_send(data.ptr(), relay_buffer->get_position());
326327
} else {
328+
// Multiple destinations.
327329
for (const int &P : connected_peers) {
328330
// Not to sender, nor excluded.
329-
if (P == p_from || (peer < 0 && P != -peer)) {
331+
if (P == p_from || P == -peer) {
330332
continue;
331333
}
332334
multiplayer_peer->set_target_peer(P);
333335
_send(data.ptr(), relay_buffer->get_position());
334336
}
335-
}
336-
if (peer == 0 || peer == -1) {
337-
should_process = true;
338-
peer = p_from; // Process as the source.
337+
if (peer != -1) {
338+
// The server is one of the targets, process the packet with sender as source.
339+
should_process = true;
340+
peer = p_from;
341+
}
339342
}
340343
} else {
341344
ERR_FAIL_COND(p_from != 1); // Bug.

0 commit comments

Comments
 (0)