This commit is contained in:
griffi-gh 2023-02-10 22:11:18 +01:00
parent 6b65497263
commit 5307ba0c9f
3 changed files with 14 additions and 2 deletions

4
Server.toml Normal file
View file

@ -0,0 +1,4 @@
[server]
address = "0.0.0.0"
port = 1234
max_clients = 254

View file

@ -9,3 +9,5 @@ kubi-udp = { path = "../kubi-udp" }
kubi-logging = { path = "../kubi-logging" }
log = "*"
shipyard = "0.6"
serde = "1.0"
toml = "0.7"

View file

@ -1,7 +1,11 @@
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};
use std::{thread, time::Duration, net::SocketAddr};
#[derive(Unique)]
#[repr(transparent)]
pub struct ServerAddr(SocketAddr);
#[derive(Unique)]
#[repr(transparent)]
@ -10,7 +14,8 @@ pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
fn bind_server(
storages: AllStoragesView,
) {
log::info!("Binding server");
log::info!("Creating server...");
let addr = storages.borrow::<UniqueView<SocketAddr>>().expect("No server addr found");
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
"0.0.0.0:1234".parse().unwrap(),
ServerConfig::default()
@ -44,6 +49,7 @@ fn main() {
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));