fix multiplayer snapshot disconnect race

This commit is contained in:
Josh Creek
2026-08-31 20:05:40 +01:00
parent 8d4a0640e2
commit 835233672f
4 changed files with 32 additions and 3 deletions
+6
View File
@@ -264,6 +264,11 @@ func send_input(bytes: PackedByteArray) -> void:
func send_snapshot(peer_id: int, bytes: PackedByteArray) -> void:
# A server-side disconnect can leave peer_id in get_peers() until the
# current poll batch settles. Do not enter Godot's RPC path for that stale
# target; NetSim repeats this check at fire time for delayed sends.
if not NetworkManager.can_send_to_peer(peer_id):
return
_track_sent(bytes.size())
NetSim.send(func() -> void: _snapshot.rpc_id(peer_id, bytes), peer_id)
@@ -477,6 +482,7 @@ func _disconnect_abusive_peer(peer_id: int, reason: String) -> void:
# which does not carry the peer, the reason or a timestamp into the log
# stream a container actually captures.
ServerLog.warn("peer_kicked", {"peer_id": peer_id, "reason": reason})
NetworkManager.invalidate_peer(peer_id)
_peer_input_state.erase(peer_id)
if multiplayer.multiplayer_peer is ENetMultiplayerPeer:
multiplayer.multiplayer_peer.disconnect_peer(peer_id)