diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/net/mod.rs | 1 | ||||
-rw-r--r-- | core/src/net/request/mod.rs | 6 | ||||
-rw-r--r-- | core/src/net/response/mod.rs | 8 | ||||
-rw-r--r-- | core/src/net/server_status/mod.rs | 9 | ||||
-rw-r--r-- | core/src/net/session_token/mod.rs | 13 |
5 files changed, 31 insertions, 6 deletions
diff --git a/core/src/net/mod.rs b/core/src/net/mod.rs index f1d7f0d..39916c9 100644 --- a/core/src/net/mod.rs +++ b/core/src/net/mod.rs @@ -3,6 +3,7 @@ use crate::use_mod; use_mod!(pub request); use_mod!(pub response); +use_mod!(pub server_status); use_mod!(pub session_token); // HIP 37279, a.k.a. Procyon. diff --git a/core/src/net/request/mod.rs b/core/src/net/request/mod.rs index ed803ac..40114d9 100644 --- a/core/src/net/request/mod.rs +++ b/core/src/net/request/mod.rs @@ -6,7 +6,9 @@ use bzipper::{Deserialise, FixedString, Serialise}; #[derive(Debug, Deserialise, Serialise)] pub enum Request { - PlayerJoin { username: FixedString<0x10> }, + Ping, - PlayerQuit { token: SessionToken }, + Join { username: FixedString<0x10> }, + + Quit { token: SessionToken }, } diff --git a/core/src/net/response/mod.rs b/core/src/net/response/mod.rs index 9c9a4cb..86e7db9 100644 --- a/core/src/net/response/mod.rs +++ b/core/src/net/response/mod.rs @@ -1,12 +1,14 @@ // Copyright 2022-2024 Gabriel Bjørnager Jensen. -use crate::net::{Request, SessionToken}; +use crate::net::{ServerStatus, SessionToken}; use bzipper::{Deserialise, FixedString, Serialise}; #[derive(Debug, Deserialise, Serialise)] pub enum Response { - PlayerJoinAccepted { token: SessionToken }, + JoinAccepted { token: SessionToken }, - RequestDenied { request: Request, reason: FixedString<0x20> }, + JoinDenied { reason: FixedString<0x20> }, + + ServerStatus(ServerStatus), } diff --git a/core/src/net/server_status/mod.rs b/core/src/net/server_status/mod.rs new file mode 100644 index 0000000..e74e4dc --- /dev/null +++ b/core/src/net/server_status/mod.rs @@ -0,0 +1,9 @@ +// Copyright 2022-2024 Gabriel Bjørnager Jensen. + +use bzipper::{Deserialise, Serialise}; + +#[derive(Debug, Deserialise, Serialise)] +pub struct ServerStatus { + pub player_count: u32, + pub max_player_count: u32, +} diff --git a/core/src/net/session_token/mod.rs b/core/src/net/session_token/mod.rs index cb3ab8c..0c839af 100644 --- a/core/src/net/session_token/mod.rs +++ b/core/src/net/session_token/mod.rs @@ -1,10 +1,21 @@ // Copyright 2022-2024 Gabriel Bjørnager Jensen. use bzipper::{Deserialise, Serialise}; +use std::fmt::{Debug, Display, Formatter}; -#[derive(Debug, Deserialise, Serialise)] +#[derive(Clone, Copy, Eq, Deserialise, PartialEq, Serialise)] #[repr(align(0x10))] pub struct SessionToken { pub time: u64, pub key: u64, } + +impl Debug for SessionToken { + #[inline(always)] + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { write!(f, "{self}") } +} + +impl Display for SessionToken { + #[inline(always)] + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { write!(f, "{:016X}:{:016X}", self.time, self.key) } +} |