#transport-layer #transport #multiplayer-game #networking #client-server #game-networking #gamedev

renet_steam

steam transport for the renet crate: Server/Client network library for multiplayer games

3 releases (1 stable)

new 1.0.0 Dec 24, 2024
0.0.2 Jul 20, 2024
0.0.1 Feb 22, 2024

#2081 in Network programming

Download history 17/week @ 2024-09-16 14/week @ 2024-09-23 16/week @ 2024-09-30 6/week @ 2024-12-09 154/week @ 2024-12-23

160 downloads per month
Used in 2 crates (via bevy_renet)

MIT/Apache

140KB
2.5K SLoC

Renet Steam

Latest version Documentation MIT Apache

Transport layer for the renet crate using the steamworks-rs.

Usage

This crate adds SteamServerTransport and SteamClientTransport to replace the default transport layer that comes with renet:

Server

// Setup steam client
let (steam_client, single) = Client::init_app(480).unwrap();
steam_client.networking_utils().init_relay_network_access();

// Create renet server
let connection_config = ConnectionConfig::default();
let mut server: RenetServer = RenetServer::new(connection_config);

// Create steam transport
let access_permission = AccessPermission::Public;
let steam_transport_config = SteamServerConfig {
    max_clients: 10,
    access_permission,
};
let mut steam_transport = SteamServerTransport::new(&steam_client, steam_transport_config).unwrap();

// Your gameplay loop
loop {
    let delta_time = Duration::from_millis(16);

    single.run_callbacks(); // Update steam callbacks
   
    server.update(delta_time);
    steam_transport.update(&mut server);

    // Handle connect/disconnect events
    while let Some(event) = server.get_event() {
        match event {
            ServerEvent::ClientConnected { client_id } => {
                println!("Client {} connected.", client_id)
            }
            ServerEvent::ClientDisconnected { client_id, reason } => {
                println!("Client {} disconnected: {}", client_id, reason);
            }
        }
    }

    // Code for sending/receiving messages can go here
    // Check the examples/demos 

    steam_transport.send_packets(&mut server);
    thread::sleep(delta_time);
}

Client

// Setup steam client
let (steam_client, single) = Client::init_app(480).unwrap();
steam_client.networking_utils().init_relay_network_access();

// Create renet client
let connection_config = ConnectionConfig::default();
let mut client = RenetClient::new(connection_config);

// Create steam transport
let server_steam_id = SteamId::from_raw(0); // Here goes the steam id of the host
let mut steam_transport = SteamClientTransport::new(&steam_client, &server_steam_id).unwrap();

// Your gameplay loop
loop {
    let delta_time = Duration::from_millis(16);

    single.run_callbacks(); // Update steam callbacks
    client.update(delta_time);
    steam_transport.update(&mut client);

    // Code for sending/receiving messages can go here
    // Check the examples/demos 

    steam_transport.send_packets(&mut client).unwrap();
    thread::sleep(delta_time);
}

Example

You can try the steam echo example with (steam needs to be running in the background):

  • server: cargo run --example echo server
  • client: cargo run --example echo client [HOST_STEAM_ID]

The HOST_STEAM_ID is printed in the console when the server starts.

You can also run the echo example using steam lobbies. Only steam users connected to the lobby will be able to connect to the server. In the echo example, they will first try connect to the steam lobby and later to the renet server:

  • server: cargo run --example echo server lobby
  • client: cargo run --example echo client [HOST_STEAM_ID] [LOBBY_ID]

The LOBBY_ID is printed in the console when the server starts.

Dependencies

~18MB
~175K SLoC