diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/src/app/mod.rs | 10 | ||||
-rw-r--r-- | server/src/app/run.rs | 9 | ||||
-rw-r--r-- | server/src/main.rs | 5 | ||||
-rw-r--r-- | server/src/server/mod.rs | 15 | ||||
-rw-r--r-- | server/src/server/run.rs | 26 |
6 files changed, 45 insertions, 22 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index 8ff78a2..30d6e61 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -11,5 +11,7 @@ repository.workspace = true [dependencies] bowshock = { path = "../core" } +bzipper = "0.6.0" + [lints] workspace = true diff --git a/server/src/app/mod.rs b/server/src/app/mod.rs deleted file mode 100644 index 0ec083c..0000000 --- a/server/src/app/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2022-2024 Gabriel Bjørnager Jensen. - -mod run; - -pub struct App; - -impl App { - #[must_use] - pub fn new() -> Self { Self } -} diff --git a/server/src/app/run.rs b/server/src/app/run.rs deleted file mode 100644 index f04e42f..0000000 --- a/server/src/app/run.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2022-2024 Gabriel Bjørnager Jensen. - -use crate::App; - -impl App { - pub fn run(self) -> Result<(), i32> { - Ok(()) - } -} diff --git a/server/src/main.rs b/server/src/main.rs index 33f011d..5bd8b28 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,7 +1,6 @@ // Copyright 2022-2024 Gabriel Bjørnager Jensen. use bowshock::use_mod; +use_mod!(pub server); -use_mod!(pub app); - -fn main() -> Result<(), i32> { App::new().run() } +fn main() -> Result<(), i32> { Server::new().run() } diff --git a/server/src/server/mod.rs b/server/src/server/mod.rs new file mode 100644 index 0000000..69b0842 --- /dev/null +++ b/server/src/server/mod.rs @@ -0,0 +1,15 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +mod run; + +pub struct Server; + +impl Server { + #[must_use] + pub fn new() -> Self { Self } +} + +impl Default for Server { + #[inline(always)] + fn default() -> Self { Self::new() } +} diff --git a/server/src/server/run.rs b/server/src/server/run.rs new file mode 100644 index 0000000..55d81ee --- /dev/null +++ b/server/src/server/run.rs @@ -0,0 +1,26 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::Server; + +use bowshock::net::{DEFAULT_SERVER_PORT, Request}; +use bzipper::Buffer; +use std::net::UdpSocket; + +impl Server { + pub fn run(self) -> Result<(), i32> { + let server_addr = format!("127.0.0.1:{DEFAULT_SERVER_PORT}"); + let socket = UdpSocket::bind(&server_addr).unwrap(); + + let mut buf = Buffer::<Request>::new(); + + eprintln!("listening at {server_addr}..."); + + loop { + let (len, client_addr) = socket.recv_from(&mut buf).unwrap(); + assert_eq!(len, buf.len()); + + let request = buf.read().unwrap(); + eprintln!("got request {request:?} from {client_addr}"); + } + } +} |