Skip to content

Instantly share code, notes, and snippets.

@dom96
Created July 11, 2021 23:05
Show Gist options
  • Save dom96/26c574ec1491ba98181de6c532fa52fc to your computer and use it in GitHub Desktop.
Save dom96/26c574ec1491ba98181de6c532fa52fc to your computer and use it in GitHub Desktop.
let headers = req.headers.get()
# Set up AsyncSocket for use with asyncdispatch.
req.forget() # Remove from HttpBeast event loop.
asyncdispatch.register(req.client.AsyncFD)
let socket = newAsyncSocket(req.client.AsyncFD)
# Handshake with client.
let (client, error) =
await verifyWebsocketRequest(socket, headers, "stardust")
if error.len != 0:
game.logs.initialError.labels("negotiation").inc()
warn("WS negotiation failed: " & error)
req.send("Websocket negotiation failed: " & error, Http400)
socket.close()
else:
let success = await addPlayer(game, client)
if not success:
game.logs.initialError.labels("addPlayer").inc()
info("Dropping connection due to unsuccessful `addPlayer`")
await client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment