Skip to content

API Reference

The current Swamp wire protocol version is 1.

Returns information about the server like the name but no sensitive information.

{
"description": "A simple server",
"name": "Swamp",
"rooms": 2,
"players": 5,
"maxPlayersPerRoom": 10,
"maxConcurrentPlayers": 100,
"maxRooms": 20,
"protocols": [1]
}

maxPlayersPerRoom limits one room, maxConcurrentPlayers limits participating players across all rooms, and maxRooms limits active rooms. A server-wide value of 0 means unlimited. The protocols field lists the protocol versions the server supports.

Connect to the websocket to receive real-time updates.

The client must specify its protocol version using the Sec-WebSocket-Protocol header during the upgrade handshake. The subprotocol format is swamp-<version> (e.g. swamp-1).

If the server does not support the requested version, it responds with HTTP 400 Bad Request and a JSON body:

{
"error": "unsupported_protocol",
"supported": ["swamp-1"]
}

Clients should fetch /info first to discover supported protocol versions before connecting.

When authentication is enabled, the client must send the Authenticate command immediately after the WebSocket opens. Until the server returns Authenticated, all other commands are blocked. An invalid token, a per-user connection-limit violation, an early non-auth command, or an authentication timeout closes the connection.

This protocol-level exchange is the recommended authentication mechanism. It works identically in native applications and browsers, unlike custom WebSocket handshake headers. Use wss in production.

Sender (2 Bytes)Message (Bytes)

If we change a room or request a room info.

Flags (1 Byte)Max Players (2 Bytes)Your ID (2 Bytes)Room ID (Bytes)

See Room Flags for more information.

If you join the server.

No payload.

The connection is authenticated and may use the remaining Swamp commands. No payload.

Authentication failed and the server will close the connection. No payload.

If you are kicked from a room.

Reason (Byte)Message (String)
ReasonDescription
0x00Room closed
0x01Kicked from room
0x02Banned from room
0x03Host left
0xFFUnknown error

If you want to join a room but it fails.

Reason (Byte)
ReasonDescription
0x00Room does not exist
0x01Room is full
0x02Banned from room
0x03Application mismatch
0x04Server is full
0xFFUnknown error

If you create a room but it fails.

Reason (Byte)
ReasonDescription
0x00Server limit reached
0x01In room already
0x02Flags unsupported
0x03Not authorized
0xFFUnknown error

Dark Room Event Notification that a player has joined the room.

Player ID (2 Bytes)

Dark Room Event Notification that a player has left the room.

Player ID (2 Bytes)

Dark Room Event (toggleable), but returns empty error if not permitted List of players currently in the room.

…
Length (2 Bytes)Player ID (2 Bytes)…

Must be the first command when authentication is required.

Access token (UTF-8)
Player ID (2 Bytes)Message (Bytes)

Send a message to the receiver. There are some special player ids:

  • 0 - Send to all players
  • 1 - Send to the host
Room ID (Bytes)

No payload.

Flags (1 Byte)Max Players (2 Bytes, optional)

If Max Players is not set or set to 0, the server will use the default value.

Host only

Player ID (2 Bytes)Message (String)

No payload.

Allows you to restrict the supported rooms. This is useful if you want to prevent users from joining rooms created by other applications (e.g. different games). When set, you can only join rooms created by users with the same application identifier.

Application ID (Bytes)

Send an empty byte array to remove the application restriction.

FlagDescription
0x01Dark Room (Restrict some events to only be seen by the host)
0x02Toggle Player Visibility (On dark rooms, players can see each other, on normal rooms, they can’t)
0x04Switch Host on Host Leave (If the host leaves, the host will be changed instead of closing the room)