This commit is contained in:
griffi-gh 2023-02-10 22:11:18 +01:00
parent 0256c954f4
commit 209dc15f81
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" } kubi-logging = { path = "../kubi-logging" }
log = "*" log = "*"
shipyard = "0.6" 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 shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut};
use kubi_udp::server::{Server, ServerConfig}; use kubi_udp::server::{Server, ServerConfig};
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; 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)] #[derive(Unique)]
#[repr(transparent)] #[repr(transparent)]
@ -10,7 +14,8 @@ pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
fn bind_server( fn bind_server(
storages: AllStoragesView, 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( let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
"0.0.0.0:1234".parse().unwrap(), "0.0.0.0:1234".parse().unwrap(),
ServerConfig::default() ServerConfig::default()
@ -44,6 +49,7 @@ fn main() {
world.add_workload(initialize); world.add_workload(initialize);
world.add_workload(update); world.add_workload(update);
world.run_workload(initialize).unwrap(); world.run_workload(initialize).unwrap();
log::info!("The server is now running");
loop { loop {
world.run_workload(update).unwrap(); world.run_workload(update).unwrap();
thread::sleep(Duration::from_millis(16)); thread::sleep(Duration::from_millis(16));