Skip to content

unbanished-net ​

Un-Banished multiplayer networking: the protocol between a game and the relay (unbanished-server), and a WebSocket connection to the relay that works natively and in the browser. The original Banished has no multiplayer; this is the port's own (see MULTIPLAYER-PLAN.md, step 5).

Protocol version 4. A game's first message is Hello; the relay answers Welcome, or an Error with the reason when the versions differ.

ItemWhat it is
PROTOCOL, HelloThe protocol version, and who a game is: the protocol, its engine version, and fingerprints of its game data, mods (Archive::fingerprints) and rule hooks. Hello::differs says why two games cannot share a room
ToRelayA game to the relay: Hello, ListRooms, Host a room (a code or a new one, and a password or none), Join one (with its password), Leave, Send data to one player or to every other player, Ping, Digest (the game state's digest, for the server's check), Keep (the host's town, for a server that keeps rooms) and Fetch (the room's kept town)
FromRelayThe relay to a game: Welcome, Rooms, Hosted (and whether the server keeps rooms, and this room's kept town), Kept, Joined (with the player number), PeerJoined, PeerLeft, Data (with the sender), Pong, SaveWanted (this game is the one to keep: send the others a save), Error (with the reason)
encode, decodeOne value as one WebSocket binary message (postcard). A cut-off or unknown message decodes to an error
checks::ChecksThe server's check of a room's digests: the players agree, or the game most of them have is kept (the host's on a tie)
rooms::RelayThe relay's rules with no sockets: a request goes in, the messages for each game come out. The relay program and the tests use it
storeWhere a server keeps rooms' towns: Store, FolderStore (a folder of CODE.sav files), MemoryStore, and keepable (which codes may name a file)
memory::MemoryRelayA relay and its connections in one process, for tests
ConnectionA connection to a relay: connect(url), send, poll, state. Natively (feature native) a background thread holds the socket (tungstenite); in the browser it is the page's WebSocket
StateConnecting, open, or closed (with the reason)

The relay never reads the data: the game's own messages (its lockstep turns, digests and saves, unbanished_session::lockstep::Message) travel inside Send and Data.

rust,ignore
use unbanished_net::{Connection, FromRelay, Hello, ToRelay};

let mut relay = Connection::connect("ws://127.0.0.1:7780");
relay.send(ToRelay::Hello(Hello::new("Un-Banished 0.4.0", data, mods)));
relay.send(ToRelay::Host { room: None, password: None });
for message in relay.poll() {
    if let FromRelay::Hosted { room } = message {
        println!("tell the others: {room}");
    }
}

Un-Banished 0.6.0-ab22835 is free software under the MIT or Apache-2.0 licence. It is not affiliated with or endorsed by Shining Rock Software.