summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/app/mod.rs10
-rw-r--r--server/src/app/run.rs9
-rw-r--r--server/src/main.rs5
-rw-r--r--server/src/server/mod.rs15
-rw-r--r--server/src/server/run.rs26
5 files changed, 43 insertions, 22 deletions
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}");
+ }
+ }
+}