feat: consume assignment matchmaking events

This commit is contained in:
Josh Creek
2026-08-31 23:15:42 +01:00
parent fe246bf54e
commit 3533e8ae6c
3 changed files with 33 additions and 2 deletions
+20 -1
View File
@@ -30,6 +30,7 @@ var _websocket: WebSocketPeer
var _websocket_status := "DISCONNECTED"
var _websocket_retry_seconds := 0.0
var _websocket_backoff := 1.0
var _pending_assignment_match_id := ""
func _ready() -> void:
@@ -67,6 +68,10 @@ func _process(_delta: float) -> void:
_websocket_retry_seconds = _websocket_backoff
_websocket_backoff = minf(_websocket_backoff * 2.0, 30.0)
connect_event_stream()
if not _pending_assignment_match_id.is_empty() and _operation.is_empty() and not player_id.is_empty():
var match_id := _pending_assignment_match_id
_pending_assignment_match_id = ""
fetch_assignment(match_id)
func configure(url: String, token: String) -> bool:
@@ -324,6 +329,12 @@ func _handle_websocket_packet(packet: PackedByteArray) -> void:
var proposal_update := event.duplicate(true)
proposal_update["proposal_id"] = String(event["resource_id"])
state.apply_proposal_update(proposal_update)
elif event_name == "assignment_changed":
state.mark_assignment_ready()
_pending_assignment_match_id = String(event["match_id"])
elif event_name == "error":
state.set_notice("Control-plane error: %s" % String(event["code"]))
_on_resync_required(String(event["resource_id"]))
func _valid_websocket_event(event: Dictionary) -> bool:
@@ -336,7 +347,15 @@ func _valid_websocket_event(event: Dictionary) -> bool:
if not event.has("occurred_at") or not event["occurred_at"] is String or String(event["occurred_at"]).is_empty():
return false
var event_name := String(event["event"])
return event_name in ["state_changed", "proposal_changed", "assignment_changed", "error"]
if event_name == "assignment_changed":
return event.has("match_id") and event["match_id"] is String and not String(event["match_id"]).is_empty() and event.has("server_id") and event["server_id"] is String and not String(event["server_id"]).is_empty()
if event_name == "error":
return event.has("code") and String(event["code"]) in ["REVISION_GAP", "NOT_AUTHORISED", "INVALID_STATE", "RATE_LIMITED"]
if event_name == "state_changed":
return event.has("state") and String(event["state"]) in ["QUEUED", "PROPOSED", "ACCEPTED", "ALLOCATING", "PROCESS_READY", "ASSIGNMENT_READY", "ASSIGNED", "CONNECTING", "LIVE", "RESULT_PENDING", "COMPLETED", "CANCELLED", "EXPIRED", "FAILED"]
if event_name == "proposal_changed":
return event.has("state") and String(event["state"]) in ["OPEN", "ACCEPTED", "DECLINED", "EXPIRED", "CANCELLED"]
return false
func _on_resync_required(resource_id: String) -> void: