mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
add configurable max player count
This commit is contained in:
parent
bbb024224d
commit
b6c8bdc223
@ -6,6 +6,7 @@ pub enum Error {
|
|||||||
ServerWentMad,
|
ServerWentMad,
|
||||||
ServerTimeout,
|
ServerTimeout,
|
||||||
ServerShutdown,
|
ServerShutdown,
|
||||||
|
TooManyPlayers,
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ impl Client {
|
|||||||
.ok_or(Error::ServerWentMad)?;
|
.ok_or(Error::ServerWentMad)?;
|
||||||
(state, entity, server_info)
|
(state, entity, server_info)
|
||||||
}
|
}
|
||||||
|
Some(ServerMsg::TooManyPlayers) => return Err(Error::TooManyPlayers),
|
||||||
_ => return Err(Error::ServerWentMad),
|
_ => return Err(Error::ServerWentMad),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -362,6 +363,7 @@ impl Client {
|
|||||||
for msg in new_msgs {
|
for msg in new_msgs {
|
||||||
match msg {
|
match msg {
|
||||||
ServerMsg::InitialSync { .. } => return Err(Error::ServerWentMad),
|
ServerMsg::InitialSync { .. } => return Err(Error::ServerWentMad),
|
||||||
|
ServerMsg::TooManyPlayers => return Err(Error::ServerWentMad),
|
||||||
ServerMsg::Shutdown => return Err(Error::ServerShutdown),
|
ServerMsg::Shutdown => return Err(Error::ServerShutdown),
|
||||||
ServerMsg::Ping => self.postbox.send_message(ClientMsg::Pong),
|
ServerMsg::Ping => self.postbox.send_message(ClientMsg::Pong),
|
||||||
ServerMsg::Pong => {
|
ServerMsg::Pong => {
|
||||||
|
@ -41,6 +41,7 @@ pub enum ServerMsg {
|
|||||||
key: Vec2<i32>,
|
key: Vec2<i32>,
|
||||||
chunk: Box<TerrainChunk>,
|
chunk: Box<TerrainChunk>,
|
||||||
},
|
},
|
||||||
|
TooManyPlayers,
|
||||||
Disconnect,
|
Disconnect,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,10 @@ impl Clients {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&mut self) -> usize {
|
||||||
|
self.clients.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, entity: EcsEntity, client: Client) {
|
pub fn add(&mut self, entity: EcsEntity, client: Client) {
|
||||||
self.clients.insert(entity, client);
|
self.clients.insert(entity, client);
|
||||||
}
|
}
|
||||||
|
@ -357,16 +357,21 @@ impl Server {
|
|||||||
last_ping: self.state.get_time(),
|
last_ping: self.state.get_time(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the state of the current world (all of the components that Sphynx tracks).
|
// TODO: Figure out if this if/else if correct
|
||||||
client.notify(ServerMsg::InitialSync {
|
if self.server_settings.max_players <= self.clients.len() {
|
||||||
ecs_state: self.state.ecs().gen_state_package(),
|
client.notify(ServerMsg::TooManyPlayers);
|
||||||
entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail.
|
} else {
|
||||||
server_info: self.server_info.clone(),
|
// Return the state of the current world (all of the components that Sphynx tracks).
|
||||||
});
|
client.notify(ServerMsg::InitialSync {
|
||||||
|
ecs_state: self.state.ecs().gen_state_package(),
|
||||||
|
entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail.
|
||||||
|
server_info: self.server_info.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
frontend_events.push(Event::ClientConnected { entity });
|
||||||
|
}
|
||||||
|
|
||||||
self.clients.add(entity, client);
|
self.clients.add(entity, client);
|
||||||
|
|
||||||
frontend_events.push(Event::ClientConnected { entity });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(frontend_events)
|
Ok(frontend_events)
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::{fs, io::prelude::*, net::SocketAddr, path::PathBuf};
|
use std::{fs, io::prelude::*, net::SocketAddr, path::PathBuf};
|
||||||
|
|
||||||
/// `ControlSettings` contains keybindings.
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ServerSettings {
|
pub struct ServerSettings {
|
||||||
pub address: SocketAddr,
|
pub address: SocketAddr,
|
||||||
//pub max_players: u64,
|
pub max_players: usize,
|
||||||
pub world_seed: u32,
|
pub world_seed: u32,
|
||||||
//pub pvp_enabled: bool,
|
//pub pvp_enabled: bool,
|
||||||
pub server_name: String,
|
pub server_name: String,
|
||||||
@ -21,6 +20,7 @@ impl Default for ServerSettings {
|
|||||||
world_seed: 1337,
|
world_seed: 1337,
|
||||||
server_name: "Server name".to_owned(),
|
server_name: "Server name".to_owned(),
|
||||||
server_description: "This is the best Veloren server.".to_owned(),
|
server_description: "This is the best Veloren server.".to_owned(),
|
||||||
|
max_players: 16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ pub enum Error {
|
|||||||
// Parsing/host name resolution successful but could not connect.
|
// Parsing/host name resolution successful but could not connect.
|
||||||
ConnectionFailed(ClientError),
|
ConnectionFailed(ClientError),
|
||||||
ClientCrashed,
|
ClientCrashed,
|
||||||
|
ServerIsFull,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to asynchronously parse the server address, resolve host names,
|
// Used to asynchronously parse the server address, resolve host names,
|
||||||
@ -76,6 +77,10 @@ impl ClientInit {
|
|||||||
ClientError::Network(_) => {
|
ClientError::Network(_) => {
|
||||||
last_err = Some(Error::ConnectionFailed(err))
|
last_err = Some(Error::ConnectionFailed(err))
|
||||||
}
|
}
|
||||||
|
ClientError::TooManyPlayers => {
|
||||||
|
last_err = Some(Error::ServerIsFull);
|
||||||
|
break;
|
||||||
|
}
|
||||||
// TODO: Handle errors?
|
// TODO: Handle errors?
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"Unexpected non-network error when creating client: {:?}",
|
"Unexpected non-network error when creating client: {:?}",
|
||||||
|
@ -64,6 +64,7 @@ impl PlayState for MainMenuState {
|
|||||||
self.main_menu_ui.login_error(
|
self.main_menu_ui.login_error(
|
||||||
match err {
|
match err {
|
||||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||||
|
InitError::ServerIsFull => "Server is Full!",
|
||||||
InitError::ConnectionFailed(_) => "Connection failed",
|
InitError::ConnectionFailed(_) => "Connection failed",
|
||||||
InitError::ClientCrashed => "Client crashed",
|
InitError::ClientCrashed => "Client crashed",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user