Skip to content

banished-net ​

Un-Banished multiplayer networking: the protocol between a game and the relay (banished-relay), 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).

ItemWhat it is
ToRelayA game to the relay: Host a room (with a code or a new one), Join one, Send data to one player or to every other player
FromRelayThe relay to a game: Hosted, Joined (with the player number), PeerJoined, PeerLeft, Data (with the sender), Error
encode, decodeOne value as one WebSocket binary message (postcard)
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, banished::gameplay::lockstep::Message) travel inside Send and Data.

rust,ignore
use banished_net::{Connection, FromRelay, ToRelay};

let mut relay = Connection::connect("ws://127.0.0.1:7780");
relay.send(ToRelay::Host { room: None });
for message in relay.poll() {
    if let FromRelay::Hosted { room } = message {
        println!("tell the others: {room}");
    }
}

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