use shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut}; use kubi_udp::server::{Server, ServerConfig}; use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; use std::{thread, time::Duration, net::SocketAddr}; #[derive(Unique)] #[repr(transparent)] pub struct ServerAddr(SocketAddr); #[derive(Unique)] #[repr(transparent)] pub struct UdpServer(Server); fn bind_server( storages: AllStoragesView, ) { log::info!("Creating server..."); let addr = storages.borrow::>().expect("No server addr found"); let server: Server = Server::bind( "0.0.0.0:1234".parse().unwrap(), ServerConfig::default() ).unwrap(); storages.add_unique(UdpServer(server)); } fn update_server( mut server: UniqueViewMut ) { if let Err(error) = server.0.update() { log::error!("Server error: {error:?}") } } fn initialize() -> Workload { ( bind_server, ).into_workload() } fn update() -> Workload { ( update_server, ).into_workload() } fn main() { kubi_logging::init(); let world = World::new(); world.add_workload(initialize); world.add_workload(update); world.run_workload(initialize).unwrap(); log::info!("The server is now running"); loop { world.run_workload(update).unwrap(); thread::sleep(Duration::from_millis(16)); } }