A Bevy Plugin for the renet crate. A network crate for Server/Client with cryptographically secure authentication and encypted packets. Designed for fast paced competitive multiplayer games.
Bevy renet is a small layer over the renet
crate, it adds systems to call the update function from the client/server. RenetClient
, RenetServer
, NetcodeClientTransport
and NetcodeServerTransport
need to be added as a resource, so the setup is similar to renet
itself:
```rust let mut app = App::new(); app.add_plugin(RenetServerPlugin);
let server = RenetServer::new(ConnectionConfig::default()); app.insert_resource(server);
// Transport layer setup app.addplugin(NetcodeServerPlugin); let serveraddr = "127.0.0.1:5000".parse().unwrap(); let socket = UdpSocket::bind(serveraddr).unwrap(); const MAXCLIENTS: usize = 64; const GAMEPROTOCOLID: u64 = 0; let serverconfig = ServerConfig::new(MAXCLIENTS, PROTOCOLID, serveraddr, ServerAuthentication::Unsecure); let currenttime = SystemTime::now().durationsince(SystemTime::UNIXEPOCH).unwrap(); let transport = NetcodeServerTransport::new(currenttime, serverconfig, socket).unwrap(); app.insertresource(transport);
app.addsystem(sendmessagesystem); app.addsystem(receivemessagesystem); app.addsystem(handleevents_system);
// Systems
fn sendmessagesystem(mut server: ResMut
fn receivemessagesystem(mut server: ResMut
fn handleeventssystem(mut serverevents: EventReader
```rust let mut app = App::new(); app.add_plugin(RenetClientPlugin);
let client = RenetClient::new(ConnectionConfig::default()); app.insert_resource(client);
// Setup the transport layer app.addplugin(NetcodeClientPlugin); let publicaddr = "127.0.0.1:5000".parse().unwrap(); let socket = UdpSocket::bind(publicaddr).unwrap(); let serverconfig = ServerConfig { maxclients: 64, protocolid: PROTOCOLID, publicaddr, authentication: ServerAuthentication::Unsecure, }; let currenttime = SystemTime::now().durationsince(SystemTime::UNIXEPOCH).unwrap(); let transport = NetcodeServerTransport::new(currenttime, serverconfig, socket).unwrap(); app.insertresource(transport);
app.addsystem(sendmessagesystem); app.addsystem(receivemessagesystem);
// Systems
fn sendmessagesystem(mut client: ResMut
fn receivemessagesystem(mut client: ResMut
You can run the simple
example with:
* Server: cargo run --example simple -- server
* Client: cargo run --example simple -- client
If you want a more complex example you can checkout the demo_bevy sample:
|bevy|bevy_renet| |---|---| |0.10|0.0.8| |0.9|0.0.6| |0.8|0.0.5| |0.7|0.0.4|