diff --git a/client/src/error.rs b/client/src/error.rs index 754ed38d0e..2d22c5781e 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -7,6 +7,7 @@ pub enum Error { ServerTimeout, ServerShutdown, TooManyPlayers, + InvalidAlias, Other(String), } diff --git a/client/src/lib.rs b/client/src/lib.rs index febc4c2de7..cd99b590cb 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -9,7 +9,7 @@ pub use specs::Entity as EcsEntity; use common::{ comp, - msg::{ClientMsg, ClientState, ServerInfo, ServerMsg}, + msg::{ClientMsg, ClientState, ServerError, ServerInfo, ServerMsg}, net::PostBox, state::State, terrain::{block::Block, chonk::ChonkMetrics, TerrainChunk, TerrainChunkSize}, @@ -73,7 +73,9 @@ impl Client { .ok_or(Error::ServerWentMad)?; (state, entity, server_info) } - Some(ServerMsg::TooManyPlayers) => return Err(Error::TooManyPlayers), + Some(ServerMsg::Error(ServerError::TooManyPlayers)) => { + return Err(Error::TooManyPlayers) + } _ => return Err(Error::ServerWentMad), }; @@ -362,9 +364,12 @@ impl Client { if new_msgs.len() > 0 { for msg in new_msgs { match msg { - ServerMsg::InitialSync { .. } => return Err(Error::ServerWentMad), - ServerMsg::TooManyPlayers => return Err(Error::ServerWentMad), + ServerMsg::Error(e) => match e { + ServerError::TooManyPlayers => return Err(Error::ServerWentMad), + ServerError::InvalidAlias => return Err(Error::InvalidAlias), + }, ServerMsg::Shutdown => return Err(Error::ServerShutdown), + ServerMsg::InitialSync { .. } => return Err(Error::ServerWentMad), ServerMsg::Ping => self.postbox.send_message(ClientMsg::Pong), ServerMsg::Pong => { self.last_ping_delta = Instant::now() diff --git a/common/src/msg/mod.rs b/common/src/msg/mod.rs index 2cad42a63c..25644b36de 100644 --- a/common/src/msg/mod.rs +++ b/common/src/msg/mod.rs @@ -5,7 +5,7 @@ pub mod server; // Reexports pub use self::client::ClientMsg; pub use self::ecs_packet::{EcsCompPacket, EcsResPacket}; -pub use self::server::{RequestStateError, ServerInfo, ServerMsg}; +pub use self::server::{RequestStateError, ServerError, ServerInfo, ServerMsg}; #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum ClientState { diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index 7f5af07832..f42258fb2e 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -41,7 +41,13 @@ pub enum ServerMsg { key: Vec2, chunk: Box, }, - TooManyPlayers, + Error(ServerError), Disconnect, Shutdown, } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum ServerError { + TooManyPlayers, + InvalidAlias, +} diff --git a/server/src/lib.rs b/server/src/lib.rs index 3d7fc69e58..9cb99c23ea 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -15,7 +15,7 @@ use crate::{ }; use common::{ comp, - msg::{ClientMsg, ClientState, RequestStateError, ServerInfo, ServerMsg}, + msg::{ClientMsg, ClientState, RequestStateError, ServerError, ServerInfo, ServerMsg}, net::PostOffice, state::{State, TerrainChange, Uid}, terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainMap}, @@ -357,9 +357,8 @@ impl Server { last_ping: self.state.get_time(), }; - // TODO: Figure out if this if/else if correct if self.server_settings.max_players <= self.clients.len() { - client.notify(ServerMsg::TooManyPlayers); + client.notify(ServerMsg::Error(ServerError::TooManyPlayers)); } else { // Return the state of the current world (all of the components that Sphynx tracks). client.notify(ServerMsg::InitialSync {