mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 23:22:08 +00:00
fix(multiplayer): harden reconnect lifecycle fencing
This commit is contained in:
@@ -438,8 +438,9 @@ func _reserve_join_authorisation(token: String, peer_id: int) -> int:
|
||||
var now := Time.get_unix_time_from_system()
|
||||
var history: Dictionary = _join_history.get(token, {})
|
||||
var lost_at := float(history.get("lost_at", 0.0))
|
||||
if lost_at > 0.0 and now - lost_at > RECONNECT_GRACE_SECONDS:
|
||||
return -1
|
||||
if lost_at > 0.0:
|
||||
if now < lost_at or now - lost_at > RECONNECT_GRACE_SECONDS:
|
||||
return -1
|
||||
var generation := int(history.get("generation", 0)) + 1
|
||||
_join_history[token] = {"generation": generation, "lost_at": 0.0}
|
||||
_active_join_peers[token] = peer_id
|
||||
|
||||
@@ -131,6 +131,8 @@ func test_allocated_join_authorisation_is_allowlisted_and_bound_to_server() -> v
|
||||
match_net._remove_player(43)
|
||||
match_net._join_history[token]["lost_at"] = Time.get_unix_time_from_system() - MatchNet.RECONNECT_GRACE_SECONDS - 1.0
|
||||
assert_eq(match_net._reserve_join_authorisation(token, 44), -1, "reclaim after the grace window is fenced")
|
||||
match_net._join_history[token]["lost_at"] = Time.get_unix_time_from_system() + 60.0
|
||||
assert_eq(match_net._reserve_join_authorisation(token, 44), -1, "clock-reversed reclaim is fenced")
|
||||
var malformed_context := {"match_id": 123, "server_id": "server-1", "protocol": "1", "protocol_version": 1}
|
||||
assert_true(not match_net.configure_join_authorisations([token], malformed_context), "numeric context identity is rejected")
|
||||
malformed_context = {"match_id": "match-1", "server_id": "server-1", "protocol": "1", "protocol_version": 1.5}
|
||||
|
||||
Reference in New Issue
Block a user