aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/network.rs
blob: 2ce3a419f0909e95eb4e5280e38980c1cb90e5c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::protocol::*;
use crate::shared::*;
use bevy::prelude::*;
use lightyear::client::config::*;
use lightyear::client::plugin::ClientPlugin;
use lightyear::client::plugin::PluginConfig;
use lightyear::prelude::client::Authentication;
use lightyear::prelude::client::NetConfig;
use lightyear::prelude::*;
use lightyear::transport::LOCAL_SOCKET;
use std::net::SocketAddr;

pub struct NetworkPlugin {
    pub server_addr: Option<SocketAddr>,
    pub client_id: u64,
    pub transport: TransportConfig,
}

impl Plugin for NetworkPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(ClientPlugin::new(PluginConfig::new(
            ClientConfig {
                net: NetConfig::Netcode {
                    config: Default::default(),
                    auth: Authentication::Manual {
                        server_addr: self.server_addr.unwrap_or(LOCAL_SOCKET),
                        client_id: self.client_id,
                        private_key: KEY,
                        protocol_id: PROTOCOL_ID,
                    },
                    io: IoConfig::from_transport(self.transport.clone()),
                },
                ..Default::default()
            },
            protocol(),
        )));
    }
}