mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(multiplayer): validate proposal expiry
This commit is contained in:
@@ -337,6 +337,17 @@ static func normalize_ticket(payload: Dictionary) -> Dictionary:
|
||||
return result
|
||||
|
||||
|
||||
static func normalize_proposal(payload: Dictionary) -> Dictionary:
|
||||
var result := payload.duplicate(true)
|
||||
if not result.has("expires_at"):
|
||||
return result
|
||||
if not result["expires_at"] is String or not is_valid_rfc3339_timestamp(String(result["expires_at"])):
|
||||
result["expires_at_unix"] = -1
|
||||
else:
|
||||
result["expires_at_unix"] = int(Time.get_unix_time_from_datetime_string(String(result["expires_at"])))
|
||||
return result
|
||||
|
||||
|
||||
func _start_request(operation: String, method: HTTPClient.Method, path: String, payload: Dictionary, idempotency_key: String, expected_revision: int = -1) -> Error:
|
||||
if _request == null or not _operation.is_empty() or not is_valid_base_url(base_url):
|
||||
return ERR_BUSY if not _operation.is_empty() else ERR_UNAUTHORIZED
|
||||
@@ -460,7 +471,7 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
|
||||
if operation.begins_with("queue_"):
|
||||
state.apply_ticket_update(normalize_ticket(payload))
|
||||
elif operation.begins_with("proposal_"):
|
||||
state.apply_proposal_update(payload)
|
||||
state.apply_proposal_update(normalize_proposal(payload))
|
||||
elif operation == "ranked_profile":
|
||||
if not ranked_profile.apply(payload):
|
||||
request_failed.emit(operation, response_code, ranked_profile.error_message)
|
||||
@@ -533,7 +544,7 @@ static func _valid_response_opaque_id(payload: Dictionary, key: String) -> bool:
|
||||
|
||||
|
||||
static func _valid_proposal_response(payload: Dictionary) -> bool:
|
||||
if not _valid_response_opaque_id(payload, "proposal_id") or not payload.has("participants") or not payload["participants"] is Array:
|
||||
if not _valid_response_opaque_id(payload, "proposal_id") or not payload.has("expires_at") or not payload["expires_at"] is String or not is_valid_rfc3339_timestamp(String(payload["expires_at"])) or not payload.has("participants") or not payload["participants"] is Array:
|
||||
return false
|
||||
var participants: Array = payload["participants"]
|
||||
if participants.size() < 2 or participants.size() > 6:
|
||||
|
||||
Reference in New Issue
Block a user