mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
fix(multiplayer): reconcile authoritative initial connections
This commit is contained in:
@@ -6,6 +6,7 @@ extends Node
|
||||
# controlled termination. Direct/community servers do not start this node.
|
||||
|
||||
signal drain_requested
|
||||
signal initial_connect_ready
|
||||
|
||||
var _listener := TCPServer.new()
|
||||
var _peers: Array = []
|
||||
@@ -87,6 +88,18 @@ func _respond(peer: StreamPeerTCP, request: String) -> void:
|
||||
drain_requested.emit()
|
||||
status = 202
|
||||
reason = "Accepted"
|
||||
elif method == "POST" and path == "/initial-connect-ready":
|
||||
var supplied := ""
|
||||
for line in lines:
|
||||
if line.begins_with("Authorization: Bearer "):
|
||||
supplied = line.substr("Authorization: Bearer ".length())
|
||||
if _drain_token.is_empty() or not _constant_time_equal(supplied, _drain_token):
|
||||
status = 401
|
||||
reason = "Unauthorized"
|
||||
else:
|
||||
initial_connect_ready.emit()
|
||||
status = 202
|
||||
reason = "Accepted"
|
||||
else:
|
||||
status = 405 if method in ["GET", "POST"] else 400
|
||||
reason = "Method Not Allowed" if status == 405 else "Bad Request"
|
||||
|
||||
Reference in New Issue
Block a user