2023-02-10 13:36:58 -06:00
|
|
|
use shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut};
|
2023-02-10 13:26:03 -06:00
|
|
|
use kubi_udp::server::{Server, ServerConfig};
|
|
|
|
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
|
|
|
|
2023-02-10 13:36:58 -06:00
|
|
|
#[derive(Unique)]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
|
|
|
|
|
|
|
|
fn bind_server(
|
|
|
|
storages: AllStoragesView,
|
|
|
|
) {
|
|
|
|
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
2023-02-10 13:26:03 -06:00
|
|
|
"0.0.0.0:1234".parse().unwrap(),
|
|
|
|
ServerConfig::default()
|
|
|
|
).unwrap();
|
2023-02-10 13:36:58 -06:00
|
|
|
storages.add_unique(UdpServer(server));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update_server(
|
|
|
|
mut server: UniqueViewMut<UdpServer>
|
|
|
|
) {
|
|
|
|
if let Err(error) = server.0.update() {
|
|
|
|
println!("Server error: {error:?}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn initialize() -> Workload {
|
|
|
|
(
|
|
|
|
bind_server,
|
|
|
|
).into_workload()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update() -> Workload {
|
|
|
|
(
|
|
|
|
update_server,
|
|
|
|
).into_workload()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let world = World::new();
|
|
|
|
world.add_workload(initialize);
|
|
|
|
world.add_workload(update);
|
|
|
|
world.run_workload(initialize).unwrap();
|
2023-02-10 13:26:03 -06:00
|
|
|
loop {
|
2023-02-10 13:36:58 -06:00
|
|
|
world.run_workload(update).unwrap();
|
2023-02-10 13:26:03 -06:00
|
|
|
}
|
2023-01-29 18:46:22 -06:00
|
|
|
}
|