diff options
-rw-r--r-- | CHANGELOG.md | 24 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | bowshock-small.svg | 9 | ||||
-rw-r--r-- | bowshock.svg | 45 | ||||
-rw-r--r-- | client/Cargo.toml | 2 | ||||
-rw-r--r-- | client/src/client/mod.rs | 15 | ||||
-rw-r--r-- | client/src/client/run.rs | 20 | ||||
-rw-r--r-- | client/src/main.rs | 6 | ||||
-rw-r--r-- | client/src/server_connection/mod.rs | 50 | ||||
-rw-r--r-- | core/Cargo.toml | 2 | ||||
-rw-r--r-- | core/src/lib.rs | 4 | ||||
-rw-r--r-- | core/src/net/mod.rs | 9 | ||||
-rw-r--r-- | core/src/net/request/mod.rs | 12 | ||||
-rw-r--r-- | core/src/net/response/mod.rs | 12 | ||||
-rw-r--r-- | core/src/net/session_token/mod.rs | 10 | ||||
-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 |
21 files changed, 245 insertions, 43 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index eb21dfb..878709c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,30 @@ This is the changelog of Bowshock. See `"README.md"` for more information. +## 0.13.0-1 + +* Update logo +* Update lints +* Bump dependency versions + +### Core + +* Add `net` module +* Add `net::Request` and `net::Response` types +* Add `net::SessionToken` type +* Add `net::DEFAULT_SERVER_PORT` constant + +### Client + +* Add `ServerConnection` type +* Add `Client` type +* Depend on `bzipper` + +### Server + +* Rename `App` to `Server` +* Depend on `bzipper` + ## 0.13.0-0 * Rewrite in Rust @@ -64,6 +64,7 @@ iter_on_empty_collections = "warn" iter_on_single_items = "warn" iter_with_drain = "warn" iter_without_into_iter = "deny" +large_enum_variant = "allow" macro_use_imports = "warn" manual_assert = "warn" manual_c_str_literals = "warn" diff --git a/bowshock-small.svg b/bowshock-small.svg deleted file mode 100644 index e7b1a69..0000000 --- a/bowshock-small.svg +++ /dev/null @@ -1,9 +0,0 @@ -<!-- Copyright 2023 Gabriel Bjørnager Jensen. --> -<svg height="96" width="96" xmlns="http://www.w3.org/2000/svg"> - <!-- background --> - <circle cx="48" cy="54" fill="#B61833" r="36" /> - <circle cx="48" cy="42" fill="#B61833" r="36" /> - <!-- circles --> - <circle cx="48" cy="54" fill="none" r="24" stroke="#FFEEE0" stroke-width="12" /> - <circle cx="48" cy="42" fill="none" r="24" stroke="#0F0F0F" stroke-width="12" /> -</svg> diff --git a/bowshock.svg b/bowshock.svg index f4cef4b..83dca4d 100644 --- a/bowshock.svg +++ b/bowshock.svg @@ -1,10 +1,37 @@ -<!-- Copyright 2023 Gabriel Bjørnager Jensen. --> -<svg height="120" width="120" xmlns="http://www.w3.org/2000/svg"> - <!-- background --> - <rect fill="#FFEEE0" height="120" width="120" x="0" y="0" /> - <!-- outline --> - <circle cx="60" cy="60" fill="#B61833" r="48" /> - <!-- rings --> - <circle cx="60" cy="66" fill="none" r="24" stroke="#FFEEE0" stroke-width="12" /> - <circle cx="60" cy="54" fill="none" r="24" stroke="#0F0F0F" stroke-width="12" /> +<!-- Copyright 2023-2024 Gabriel Bjørnager Jensen. --> + +<svg height="112" width="112" xmlns="http://www.w3.org/2000/svg"> + <!-- + Image description: + Two intertwined circles, the upper black and go- + ing behind the secondary to the left, and the + lower white and going behind the primary to the + right, charged on a red field. + + Red: oklch(50% 0.188300 19.760) + Black: oklch(25% 0 0) + White: oklch(96.875% 0.019500 63.560) + --> + + <clipPath id="primaryClip"> + <rect height="100%" width="50%" x="0" y="0" /> + </clipPath> + + <mask id="secondary"> + <circle cx="56" cy="64" fill="none" r="24" stroke="white" stroke-width="16" /> + + <!-- Fix seams: --> + <circle cx="56" cy="56" fill="none" r="24" stroke="white" stroke-width="1" /> + </mask> + + <mask id="primary"> + <circle cx="56" cy="48" fill="none" r="24" stroke="white" stroke-width="16" /> + + <circle clip-path="url(#primaryClip)" cx="56" cy="64" fill="none" r="24" stroke="black" stroke-width="16" /> + </mask> + + <rect fill="#B61833" height="100%" width="100%" x="0" y="0" /> + + <rect fill="#fff2e8" height="100%" mask="url(#secondary)" width="100%" x="0" y="0" /> + <rect fill="#222222" height="100%" mask="url(#primary)" width="100%" x="0" y="0" /> </svg> diff --git a/client/Cargo.toml b/client/Cargo.toml index 1c8e411..9791b14 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,5 +11,7 @@ repository.workspace = true [dependencies] bowshock = { path = "../core" } +bzipper = { version = "0.6.0", features = ["alloc"]} + [lints] workspace = true diff --git a/client/src/client/mod.rs b/client/src/client/mod.rs new file mode 100644 index 0000000..5694b6a --- /dev/null +++ b/client/src/client/mod.rs @@ -0,0 +1,15 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +mod run; + +pub struct Client; + +impl Client { + #[must_use] + pub fn new() -> Self { Self } +} + +impl Default for Client { + #[inline(always)] + fn default() -> Self { Self::new() } +} diff --git a/client/src/client/run.rs b/client/src/client/run.rs new file mode 100644 index 0000000..d955cea --- /dev/null +++ b/client/src/client/run.rs @@ -0,0 +1,20 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::{Client, ServerConnection}; + +use bowshock::net::{DEFAULT_SERVER_PORT, Request}; +use bzipper::FixedString; + +impl Client { + pub fn run(self) -> Result<(), i32> { + let server_addr = format!("127.0.0.1:{DEFAULT_SERVER_PORT}"); + eprintln!("connecting to server at {server_addr}"); + + let mut connection = ServerConnection::new(server_addr); + + let join_request = Request::PlayerJoin { username: FixedString::try_from("delta").unwrap() }; + connection.send_request(&join_request); + + Ok(()) + } +} diff --git a/client/src/main.rs b/client/src/main.rs index 2235f75..93ce825 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,3 +1,7 @@ // Copyright 2022-2024 Gabriel Bjørnager Jensen. -fn main() { } +use bowshock::use_mod; +use_mod!(pub client); +use_mod!(pub server_connection); + +fn main() -> Result<(), i32> { Client::new().run() } diff --git a/client/src/server_connection/mod.rs b/client/src/server_connection/mod.rs new file mode 100644 index 0000000..c69f3da --- /dev/null +++ b/client/src/server_connection/mod.rs @@ -0,0 +1,50 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use bowshock::net::{Request, Response}; +use bzipper::Buffer; +use std::net::{SocketAddr, ToSocketAddrs, UdpSocket}; + +pub struct ServerConnection { + socket: UdpSocket, + + request_buf: Buffer<Request>, + response_buf: Buffer<Response>, + + #[expect(unused)] + addr: SocketAddr, +} + +impl ServerConnection { + #[must_use] + pub fn new<A: ToSocketAddrs>(addr: A) -> Self { + let addr = addr + .to_socket_addrs() + .unwrap() + .next() + .unwrap(); + + let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); + socket.connect(addr).unwrap(); + + Self { + socket, + + request_buf: Buffer::new(), + response_buf: Buffer::new(), + + addr, + } + } + + pub fn send_request(&mut self, request: &Request) { + self.request_buf.write(request).unwrap(); + self.socket.send(&self.request_buf).unwrap(); + } + + pub fn recieve_response(&mut self) -> Response { + let len = self.socket.recv(&mut self.response_buf).unwrap(); + assert_eq!(len, self.response_buf.len()); + + self.response_buf.read().unwrap() + } +} diff --git a/core/Cargo.toml b/core/Cargo.toml index c55e42b..d835350 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -9,7 +9,7 @@ homepage.workspace = true repository.workspace = true [dependencies] -bzipper = "0.5.2" +bzipper = "0.6.0" [lints] workspace = true diff --git a/core/src/lib.rs b/core/src/lib.rs index 343623c..24c65a0 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -4,6 +4,8 @@ macro_rules! use_mod { ($vis:vis $name:ident) => { mod $name; - use $name::*; + $vis use $name::*; }; } + +pub mod net; diff --git a/core/src/net/mod.rs b/core/src/net/mod.rs new file mode 100644 index 0000000..f1d7f0d --- /dev/null +++ b/core/src/net/mod.rs @@ -0,0 +1,9 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::use_mod; +use_mod!(pub request); +use_mod!(pub response); +use_mod!(pub session_token); + +// HIP 37279, a.k.a. Procyon. +pub const DEFAULT_SERVER_PORT: u16 = 37279; diff --git a/core/src/net/request/mod.rs b/core/src/net/request/mod.rs new file mode 100644 index 0000000..ed803ac --- /dev/null +++ b/core/src/net/request/mod.rs @@ -0,0 +1,12 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::net::SessionToken; + +use bzipper::{Deserialise, FixedString, Serialise}; + +#[derive(Debug, Deserialise, Serialise)] +pub enum Request { + PlayerJoin { username: FixedString<0x10> }, + + PlayerQuit { token: SessionToken }, +} diff --git a/core/src/net/response/mod.rs b/core/src/net/response/mod.rs new file mode 100644 index 0000000..9c9a4cb --- /dev/null +++ b/core/src/net/response/mod.rs @@ -0,0 +1,12 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use crate::net::{Request, SessionToken}; + +use bzipper::{Deserialise, FixedString, Serialise}; + +#[derive(Debug, Deserialise, Serialise)] +pub enum Response { + PlayerJoinAccepted { token: SessionToken }, + + RequestDenied { request: Request, reason: FixedString<0x20> }, +} diff --git a/core/src/net/session_token/mod.rs b/core/src/net/session_token/mod.rs new file mode 100644 index 0000000..cb3ab8c --- /dev/null +++ b/core/src/net/session_token/mod.rs @@ -0,0 +1,10 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use bzipper::{Deserialise, Serialise}; + +#[derive(Debug, Deserialise, Serialise)] +#[repr(align(0x10))] +pub struct SessionToken { + pub time: u64, + pub key: u64, +} 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}"); + } + } +} |