Expand description
Un-Banished multiplayer networking: the protocol between a game and the relay, and a WebSocket connection to the relay that works natively and in the browser.
The relay (apps/server) keeps rooms. A game says Hello (the protocol version, its engine,
fingerprints of its game data and mods), then hosts a room and gets its code, or joins one
with the code. The relay numbers the players in the order they come (the host is 0), refuses
a game that differs from the host with the reason, and passes their data on, to one player or
to all the others. It never reads the data: the game’s own messages (its lockstep turns,
digests and saves) travel inside ToRelay::Send and FromRelay::Data. Every WebSocket
message is one value, encoded with postcard. The rules are in rooms; memory runs a
relay in one process for tests.
Not in the original game, which has no multiplayer; see docs/MULTIPLAYER-PLAN.md, step 5.
Modules§
- checks
- The server’s check that the players of a room still play the same game. Every few updates each player sends a digest of its game state. Once every player in the room has sent the digest of an update, they agree, or they differ. When they differ, the game most players have is kept (when as many have one as another, the host’s), and one player who has it sends the others its save.
- memory
- A relay and its connections in one process, for tests: the same rooms as the relay program
(
crate::rooms), and connections that send and poll like a WebSocketConnection. Every message is encoded and decoded on the way, as on a socket. - rooms
- The relay’s rooms, as a state machine with no sockets or threads: a request from a game goes
in, and the messages for each game come out. The relay program (
apps/server), the in-memory transport (crate::memory) and tests use the same rules. - store
- Where a server keeps its rooms’ towns between games, when its settings name a folder: the last save each room’s host sent, by room code. With a kept town, a host who opens the room again goes on from it.
Structs§
- Connection
- A connection to a relay (
ws://host:port). - Hello
- Who a game is: the protocol it speaks, and what its players must share.
- Room
Info - A room in the relay’s list.
Enums§
Constants§
- PROTOCOL
- The protocol version this crate speaks.