Skip to content

Commit 531c72f

Browse files
committed
[MP] Avoid error spam in relay protocol when clients disconnect
When multiple clients are connected, and the server is using the relay sub-protocol, it might happen that a client disconnects while a packet sent to it from another peer is still in transit. In that case, when the packet reaches the server for relaying, it used to generate an error (as the destination client did no longer exists). This commit changes check to suppress the error message while still skipping the packet.
1 parent 3978628 commit 531c72f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/multiplayer/scene_multiplayer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ void SceneMultiplayer::_process_sys(int p_from, const uint8_t *p_packet, int p_p
307307
int len = p_packet_len - SYS_CMD_SIZE;
308308
bool should_process = false;
309309
if (get_unique_id() == 1) { // I am the server.
310-
// Direct messages to server should not go through relay.
311-
ERR_FAIL_COND(peer > 0 && !connected_peers.has(peer));
310+
// The requested target might have disconnected while the packet was in transit.
311+
if (unlikely(peer > 0 && !connected_peers.has(peer))) {
312+
return;
313+
}
312314
// Send relay packet.
313315
relay_buffer->seek(0);
314316
relay_buffer->put_u8(NETWORK_COMMAND_SYS);

0 commit comments

Comments
 (0)