mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
46 lines
2.1 KiB
GDScript
46 lines
2.1 KiB
GDScript
class_name AssignmentState
|
|
extends RefCounted
|
|
|
|
# Verified assignment-ready manifest returned by the control plane. The join
|
|
# authorisation is retained in memory only and is never written to the restart
|
|
# snapshot; transport installation belongs to the explicit ENet/Steam layer.
|
|
|
|
var available := false
|
|
var match_id := ""
|
|
var server_id := ""
|
|
var slot := -1
|
|
var expires_at := ""
|
|
var protocol_version := 0
|
|
var transport := ""
|
|
var join_authorisation := ""
|
|
var error_message := ""
|
|
|
|
|
|
func apply(payload: Dictionary) -> bool:
|
|
for key in ["match_id", "server_id", "player_id", "slot", "expires_at", "protocol_version", "transport", "join_authorisation"]:
|
|
if not payload.has(key):
|
|
return _reject("Assignment response is missing " + key)
|
|
if not payload["match_id"] is String or not payload["server_id"] is String or not payload["player_id"] is String or not payload["slot"] is int or not payload["expires_at"] is String or not payload["protocol_version"] is int or not payload["transport"] is String or not payload["join_authorisation"] is String:
|
|
return _reject("Assignment response contains invalid types")
|
|
var next_match_id := String(payload["match_id"])
|
|
var next_server_id := String(payload["server_id"])
|
|
var next_transport := String(payload["transport"])
|
|
if next_match_id.is_empty() or next_server_id.is_empty() or String(payload["player_id"]).is_empty() or int(payload["slot"]) < 0 or int(payload["slot"]) > 5 or int(payload["protocol_version"]) < 1 or (next_transport != "enet" and next_transport != "steam_sdr") or String(payload["expires_at"]).is_empty() or String(payload["join_authorisation"]).is_empty():
|
|
return _reject("Assignment response contains invalid values")
|
|
match_id = next_match_id
|
|
server_id = next_server_id
|
|
slot = int(payload["slot"])
|
|
expires_at = String(payload["expires_at"])
|
|
protocol_version = int(payload["protocol_version"])
|
|
transport = next_transport
|
|
join_authorisation = String(payload["join_authorisation"])
|
|
available = true
|
|
error_message = ""
|
|
return true
|
|
|
|
|
|
func _reject(reason: String) -> bool:
|
|
available = false
|
|
error_message = reason
|
|
return false
|