Module bones_framework::networking::online
source · Expand description
§Matchmaking
For online matchmaking, we use a centralized matchmaking server to connect peers to each-other and to forward the peers’ network traffic. All connections utilize UDP and the QUIC protocol.
The matchmaking server is implemented in the bones_matchmaker crate. It binds to a single UDP port and listens for client connections. QUIC’s multiplexing capabilities allow the server to handle any number of clients on this single port.
Once a match starts, client traffic is proxied through the matchmaking server. While not true peer-to-peer networking, clients logically send messages to each other, with the server acting as an intermediary.
Pros of this approach:
- Reduced connections per peer (one connection to the matchmaker only)
- Client IP addresses are hidden from each other
- Easier to bypass firewalls and NATs
- Simplified connection process
Cons:
- Increased server bandwidth usage
- Additional network hop between peers, potentially increasing latency
This design doesn’t preclude future support for true peer-to-peer connections or LAN games without a matchmaker.
§Matchmaking Protocol
§Initial Connection
- The client connects to the matchmaking server.
- The client sends a
RequestMatchmakingmessage over a reliable channel. - This message contains
MatchInfowith:- The desired number of players
- A
game_idto identify the game match_data(arbitrary bytes for game mode, parameters, etc.)player_idx_assignmentto specify how player ids should be assigned (ie. randomly assign a side for a pvp match)
Players must specify identical MatchInfo to be matched together. The match_data ensures players are connected for the same game mode and version.
§Waiting for Players
- The server responds with an
Acceptedmessage. - While waiting, the server may send
MatchmakingUpdatemessages with the current player count. - When the desired number of players is reached, the server sends a
Successmessage containing:- A
random_seedfor deterministic random number generation - The client’s
player_idx - The total
player_count - A list of
player_idswith their network addresses
- A
§In the Match
Once all players have received the Success message, the matchmaker enters proxy mode:
- Clients send
SendProxyMessages to the server, specifying a target client (or all clients) and the message data. - The server forwards these as
RecvProxyMessages to the target client(s), including the sender’s player index.
The matchmaker supports both reliable and unreliable message forwarding, allowing the game to implement its preferred synchronization protocol.
Structs§
- A unique identifier for a lobby
- Information about a lobby
- Information about a lobby for the lobby list
- Information about a match that is being requested
- Internal struct used to keep track of the connection with the matchmaker
- Struct that holds a channel which exchange messages with the matchmaking server.
Enums§
- Online matchmaker request
- Online matchmaker response
- Choose how player_idx should be assigned to each player who joins a match/lobby.
Constants§
- ALPN used for the matchmaking protocol.
- The number of bytes to use for read_to_end()
Statics§
- Online matchmaker channel
Type Aliases§
- A unique identifier for a game