mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
generalise errors based on zests suggestion
This commit is contained in:
parent
e2b83883f3
commit
b41508f025
@ -7,6 +7,7 @@ pub enum Error {
|
||||
ServerTimeout,
|
||||
ServerShutdown,
|
||||
TooManyPlayers,
|
||||
InvalidAlias,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -41,7 +41,13 @@ pub enum ServerMsg {
|
||||
key: Vec2<i32>,
|
||||
chunk: Box<TerrainChunk>,
|
||||
},
|
||||
TooManyPlayers,
|
||||
Error(ServerError),
|
||||
Disconnect,
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ServerError {
|
||||
TooManyPlayers,
|
||||
InvalidAlias,
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user