mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): validate allocated roster shape
This commit is contained in:
@@ -122,14 +122,23 @@ func configure_join_authorisations(tokens: Array, context: Dictionary, signing_k
|
||||
|
||||
func assigned_player_slots() -> Array:
|
||||
var result: Array = []
|
||||
var seen_identities := {}
|
||||
var seen_slots := {}
|
||||
for token in _allowed_join_authorisations.keys():
|
||||
var claims := _join_claims(String(token))
|
||||
if claims.is_empty():
|
||||
continue
|
||||
return []
|
||||
var identity := str(claims.get("PlayerID", ""))
|
||||
var team := int(claims.get("Team", -1))
|
||||
var slot := int(claims.get("Slot", -1))
|
||||
if identity.is_empty() or team < 0 or team >= TEAM_COUNT or slot < 0 or slot > 5 or slot / 3 != team or seen_identities.has(identity) or seen_slots.has(slot):
|
||||
return []
|
||||
seen_identities[identity] = true
|
||||
seen_slots[slot] = true
|
||||
result.append({
|
||||
"player_identity": str(claims.get("PlayerID", "")),
|
||||
"team": int(claims.get("Team", -1)),
|
||||
"slot": int(claims.get("Slot", -1)),
|
||||
"player_identity": identity,
|
||||
"team": team,
|
||||
"slot": slot,
|
||||
})
|
||||
result.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return int(a["slot"]) < int(b["slot"]))
|
||||
return result
|
||||
|
||||
@@ -78,7 +78,7 @@ func _ready() -> void:
|
||||
"server_id": String(config.get_value("server-id")),
|
||||
"protocol": str(NetCodec.PROTOCOL_VERSION),
|
||||
"protocol_version": NetCodec.PROTOCOL_VERSION,
|
||||
}, signing_key):
|
||||
}, signing_key) or MatchNet.assigned_player_slots().size() != roster_tokens.size():
|
||||
printerr("cosmic-clash-server: refusing to start with invalid join-authorisations-file")
|
||||
get_tree().quit(1)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user