mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix: retry queue creation idempotently
This commit is contained in:
@@ -17,6 +17,7 @@ var ranked_profile: RankedProfileState
|
||||
|
||||
var _request: HTTPRequest
|
||||
var _operation := ""
|
||||
var _last_queue_create: Dictionary = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -45,12 +46,31 @@ func queue_create(ticket_id: String, playlist: String, client_build: String, pro
|
||||
return ERR_INVALID_PARAMETER
|
||||
if not state.begin_queue(ticket_id, playlist):
|
||||
return ERR_INVALID_PARAMETER
|
||||
var err := _start_request("queue_create", HTTPClient.METHOD_POST, "/v1/queue", {"ticket_id": ticket_id, "playlist": playlist, "client_build": client_build, "protocol_version": protocol_version}, _idempotency_key("queue"))
|
||||
var key := _idempotency_key("queue")
|
||||
_last_queue_create = {"ticket_id": ticket_id, "playlist": playlist, "client_build": client_build, "protocol_version": protocol_version, "key": key}
|
||||
var err := _start_request("queue_create", HTTPClient.METHOD_POST, "/v1/queue", {"ticket_id": ticket_id, "playlist": playlist, "client_build": client_build, "protocol_version": protocol_version}, key)
|
||||
if err != OK:
|
||||
state.fail("Could not start matchmaking: %s" % error_string(err))
|
||||
return err
|
||||
|
||||
|
||||
func retry_queue_create() -> Error:
|
||||
if _last_queue_create.is_empty() or not _last_queue_create.has("ticket_id"):
|
||||
return ERR_INVALID_DATA
|
||||
var ticket_id := String(_last_queue_create["ticket_id"])
|
||||
var playlist := String(_last_queue_create["playlist"])
|
||||
if not state.begin_queue(ticket_id, playlist):
|
||||
return ERR_INVALID_PARAMETER
|
||||
var err := _start_request("queue_create", HTTPClient.METHOD_POST, "/v1/queue", {"ticket_id": ticket_id, "playlist": playlist, "client_build": String(_last_queue_create["client_build"]), "protocol_version": int(_last_queue_create["protocol_version"])}, String(_last_queue_create["key"]))
|
||||
if err != OK:
|
||||
state.fail("Could not retry matchmaking: %s" % error_string(err))
|
||||
return err
|
||||
|
||||
|
||||
func can_retry_queue_create() -> bool:
|
||||
return not _last_queue_create.is_empty() and state.phase == MatchmakingState.FAILED and String(_last_queue_create.get("ticket_id", "")) == state.ticket_id
|
||||
|
||||
|
||||
func recover_queue(ticket_id: String) -> Error:
|
||||
if ticket_id.is_empty():
|
||||
return ERR_INVALID_PARAMETER
|
||||
|
||||
Reference in New Issue
Block a user