mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-13 19:08:41 -06:00
29 lines
895 B
Rust
29 lines
895 B
Rust
|
use shipyard::{AllStoragesView, Unique, UniqueView, UniqueViewMut};
|
||
|
use kubi_udp::server::{Server, ServerConfig};
|
||
|
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
||
|
use crate::config::ConfigTable;
|
||
|
|
||
|
#[derive(Unique)]
|
||
|
#[repr(transparent)]
|
||
|
pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
|
||
|
|
||
|
pub fn bind_server(
|
||
|
storages: AllStoragesView,
|
||
|
) {
|
||
|
log::info!("Creating server...");
|
||
|
let config = storages.borrow::<UniqueView<ConfigTable>>().unwrap();
|
||
|
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
||
|
config.server.address,
|
||
|
ServerConfig { max_clients: config.server.max_clients }
|
||
|
).unwrap();
|
||
|
storages.add_unique(UdpServer(server));
|
||
|
}
|
||
|
|
||
|
pub fn update_server(
|
||
|
mut server: UniqueViewMut<UdpServer>
|
||
|
) {
|
||
|
if let Err(error) = server.0.update() {
|
||
|
log::error!("Server error: {error:?}")
|
||
|
}
|
||
|
}
|