mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'xacrimon/error-handling' into 'master'
Drastically improved error messages in client and server. See merge request veloren/veloren!621
This commit is contained in:
commit
3902b8e364
@ -492,8 +492,12 @@ impl Client {
|
|||||||
frontend_events.push(Event::Chat { chat_type, message })
|
frontend_events.push(Event::Chat { chat_type, message })
|
||||||
}
|
}
|
||||||
ServerMsg::SetPlayerEntity(uid) => {
|
ServerMsg::SetPlayerEntity(uid) => {
|
||||||
self.entity = self.state.ecs().entity_from_uid(uid).unwrap()
|
if let Some(entity) = self.state.ecs().entity_from_uid(uid) {
|
||||||
} // TODO: Don't unwrap here!
|
self.entity = entity;
|
||||||
|
} else {
|
||||||
|
return Err(Error::Other("Failed to find entity from uid.".to_owned()));
|
||||||
|
}
|
||||||
|
}
|
||||||
ServerMsg::EcsSync(sync_package) => {
|
ServerMsg::EcsSync(sync_package) => {
|
||||||
self.state.ecs_mut().sync_with_package(sync_package)
|
self.state.ecs_mut().sync_with_package(sync_package)
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,11 @@ fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action
|
|||||||
let header_message: String = format!("{} online players: \n", count);
|
let header_message: String = format!("{} online players: \n", count);
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
let mut player_iter = players.join();
|
let mut player_iter = players.join();
|
||||||
let first = player_iter.next().unwrap().alias.to_owned();
|
let first = player_iter
|
||||||
|
.next()
|
||||||
|
.expect("Player iterator returned none.")
|
||||||
|
.alias
|
||||||
|
.to_owned();
|
||||||
let player_list = player_iter.fold(first, |mut s, p| {
|
let player_list = player_iter.fold(first, |mut s, p| {
|
||||||
s += ",\n";
|
s += ",\n";
|
||||||
s += &p.alias;
|
s += &p.alias;
|
||||||
|
@ -126,7 +126,8 @@ impl Server {
|
|||||||
git_hash: common::util::GIT_HASH.to_string(),
|
git_hash: common::util::GIT_HASH.to_string(),
|
||||||
git_date: common::util::GIT_DATE.to_string(),
|
git_date: common::util::GIT_DATE.to_string(),
|
||||||
},
|
},
|
||||||
metrics: ServerMetrics::new(settings.metrics_address),
|
metrics: ServerMetrics::new(settings.metrics_address)
|
||||||
|
.expect("Failed to initialize server metrics submodule."),
|
||||||
accounts: AuthProvider::new(),
|
accounts: AuthProvider::new(),
|
||||||
server_settings: settings.clone(),
|
server_settings: settings.clone(),
|
||||||
};
|
};
|
||||||
@ -245,7 +246,7 @@ impl Server {
|
|||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Player>()
|
.read_storage::<comp::Player>()
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.unwrap()
|
.expect("Failed to fetch entity.")
|
||||||
.alias,
|
.alias,
|
||||||
) {
|
) {
|
||||||
state.write_component(entity, comp::Admin);
|
state.write_component(entity, comp::Admin);
|
||||||
@ -303,7 +304,7 @@ impl Server {
|
|||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Pos>()
|
.read_storage::<comp::Pos>()
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.unwrap()
|
.expect("Failed to fetch entity")
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
// TODO: Player height
|
// TODO: Player height
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use log::info;
|
use log::info;
|
||||||
use prometheus::{Encoder, Gauge, IntGauge, IntGaugeVec, Opts, Registry, TextEncoder};
|
use prometheus::{Encoder, Gauge, IntGauge, IntGaugeVec, Opts, Registry, TextEncoder};
|
||||||
use rouille::{router, Server};
|
use rouille::{router, Server};
|
||||||
|
use std::error::Error;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
@ -28,66 +29,65 @@ pub struct ServerMetrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ServerMetrics {
|
impl ServerMetrics {
|
||||||
pub fn new(addr: SocketAddr) -> Self {
|
pub fn new(addr: SocketAddr) -> Result<Self, Box<dyn Error>> {
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"player_online",
|
"player_online",
|
||||||
"shows the number of clients connected to the server",
|
"shows the number of clients connected to the server",
|
||||||
);
|
);
|
||||||
let player_online = IntGauge::with_opts(opts).unwrap();
|
let player_online = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"entity_count",
|
"entity_count",
|
||||||
"number of all entities currently active on the server",
|
"number of all entities currently active on the server",
|
||||||
);
|
);
|
||||||
let entity_count = IntGauge::with_opts(opts).unwrap();
|
let entity_count = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new("veloren_build_info", "Build information")
|
let opts = Opts::new("veloren_build_info", "Build information")
|
||||||
.const_label("hash", &common::util::GIT_HASH)
|
.const_label("hash", &common::util::GIT_HASH)
|
||||||
.const_label("version", "");
|
.const_label("version", "");
|
||||||
let build_info = IntGauge::with_opts(opts).unwrap();
|
let build_info = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"veloren_start_time",
|
"veloren_start_time",
|
||||||
"start time of the server in seconds since EPOCH",
|
"start time of the server in seconds since EPOCH",
|
||||||
);
|
);
|
||||||
let start_time = IntGauge::with_opts(opts).unwrap();
|
let start_time = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new("time_of_day", "ingame time in ingame-seconds");
|
let opts = Opts::new("time_of_day", "ingame time in ingame-seconds");
|
||||||
let time_of_day = Gauge::with_opts(opts).unwrap();
|
let time_of_day = Gauge::with_opts(opts)?;
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"light_count",
|
"light_count",
|
||||||
"number of all lights currently active on the server",
|
"number of all lights currently active on the server",
|
||||||
);
|
);
|
||||||
let light_count = IntGauge::with_opts(opts).unwrap();
|
let light_count = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"chonks_count",
|
"chonks_count",
|
||||||
"number of all chonks currently active on the server",
|
"number of all chonks currently active on the server",
|
||||||
);
|
);
|
||||||
let chonks_count = IntGauge::with_opts(opts).unwrap();
|
let chonks_count = IntGauge::with_opts(opts)?;
|
||||||
let opts = Opts::new(
|
let opts = Opts::new(
|
||||||
"chunks_count",
|
"chunks_count",
|
||||||
"number of all chunks currently active on the server",
|
"number of all chunks currently active on the server",
|
||||||
);
|
);
|
||||||
let chunks_count = IntGauge::with_opts(opts).unwrap();
|
let chunks_count = IntGauge::with_opts(opts)?;
|
||||||
let vec = IntGaugeVec::new(
|
let vec = IntGaugeVec::new(
|
||||||
Opts::new("tick_time", "time in ns requiered for a tick of the server"),
|
Opts::new("tick_time", "time in ns requiered for a tick of the server"),
|
||||||
&["period"],
|
&["period"],
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
let tick_time = IntGaugeVec::from(vec);
|
let tick_time = IntGaugeVec::from(vec);
|
||||||
|
|
||||||
let since_the_epoch = SystemTime::now()
|
let since_the_epoch = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("Time went backwards");
|
.expect("Time went backwards");
|
||||||
start_time.set(since_the_epoch.as_secs().try_into().unwrap());
|
start_time.set(since_the_epoch.as_secs().try_into()?);
|
||||||
|
|
||||||
let registry = Registry::new();
|
let registry = Registry::new();
|
||||||
//registry.register(Box::new(chonks_count.clone())).unwrap();
|
//registry.register(Box::new(chonks_count.clone())).unwrap();
|
||||||
registry.register(Box::new(player_online.clone())).unwrap();
|
registry.register(Box::new(player_online.clone()))?;
|
||||||
registry.register(Box::new(entity_count.clone())).unwrap();
|
registry.register(Box::new(entity_count.clone()))?;
|
||||||
registry.register(Box::new(build_info.clone())).unwrap();
|
registry.register(Box::new(build_info.clone()))?;
|
||||||
registry.register(Box::new(start_time.clone())).unwrap();
|
registry.register(Box::new(start_time.clone()))?;
|
||||||
registry.register(Box::new(time_of_day.clone())).unwrap();
|
registry.register(Box::new(time_of_day.clone()))?;
|
||||||
//registry.register(Box::new(light_count.clone())).unwrap();
|
//registry.register(Box::new(light_count.clone())).unwrap();
|
||||||
registry.register(Box::new(chonks_count.clone())).unwrap();
|
registry.register(Box::new(chonks_count.clone()))?;
|
||||||
registry.register(Box::new(chunks_count.clone())).unwrap();
|
registry.register(Box::new(chunks_count.clone()))?;
|
||||||
registry.register(Box::new(tick_time.clone())).unwrap();
|
registry.register(Box::new(tick_time.clone()))?;
|
||||||
|
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let running2 = running.clone();
|
let running2 = running.clone();
|
||||||
@ -100,8 +100,8 @@ impl ServerMetrics {
|
|||||||
let encoder = TextEncoder::new();
|
let encoder = TextEncoder::new();
|
||||||
let mut buffer = vec![];
|
let mut buffer = vec![];
|
||||||
let mf = registry.gather();
|
let mf = registry.gather();
|
||||||
encoder.encode(&mf, &mut buffer).unwrap();
|
encoder.encode(&mf, &mut buffer).expect("Failed to encoder metrics text.");
|
||||||
rouille::Response::text(String::from_utf8(buffer).unwrap())
|
rouille::Response::text(String::from_utf8(buffer).expect("Failed to parse bytes as a string."))
|
||||||
},
|
},
|
||||||
_ => rouille::Response::empty_404()
|
_ => rouille::Response::empty_404()
|
||||||
)
|
)
|
||||||
@ -115,7 +115,7 @@ impl ServerMetrics {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
chonks_count,
|
chonks_count,
|
||||||
chunks_count,
|
chunks_count,
|
||||||
player_online,
|
player_online,
|
||||||
@ -128,7 +128,7 @@ impl ServerMetrics {
|
|||||||
running,
|
running,
|
||||||
handle,
|
handle,
|
||||||
every_100th: 0,
|
every_100th: 0,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_100th_tick(&mut self) -> bool {
|
pub fn is_100th_tick(&mut self) -> bool {
|
||||||
@ -147,7 +147,7 @@ impl Drop for ServerMetrics {
|
|||||||
self.running.store(false, Ordering::Relaxed);
|
self.running.store(false, Ordering::Relaxed);
|
||||||
let handle = self.handle.take();
|
let handle = self.handle.take();
|
||||||
handle
|
handle
|
||||||
.unwrap()
|
.expect("ServerMetrics worker handle does not exist.")
|
||||||
.join()
|
.join()
|
||||||
.expect("Error shutting down prometheus metric exporter");
|
.expect("Error shutting down prometheus metric exporter");
|
||||||
}
|
}
|
||||||
|
@ -27,23 +27,26 @@ impl Default for ServerSettings {
|
|||||||
server_description: "This is the best Veloren server.".to_owned(),
|
server_description: "This is the best Veloren server.".to_owned(),
|
||||||
max_players: 100,
|
max_players: 100,
|
||||||
start_time: 9.0 * 3600.0,
|
start_time: 9.0 * 3600.0,
|
||||||
admins: vec![
|
admins: [
|
||||||
"Pfau".to_owned(),
|
"Pfau",
|
||||||
"zesterer".to_owned(),
|
"zesterer",
|
||||||
"xMAC94x".to_owned(),
|
"xMAC94x",
|
||||||
"Timo".to_owned(),
|
"Timo",
|
||||||
"Songtronix".to_owned(),
|
"Songtronix",
|
||||||
"Slipped".to_owned(),
|
"Slipped",
|
||||||
"Sharp".to_owned(),
|
"Sharp",
|
||||||
"Acrimon".to_owned(),
|
"Acrimon",
|
||||||
"imbris".to_owned(),
|
"imbris",
|
||||||
"YuriMomo".to_owned(),
|
"YuriMomo",
|
||||||
"Vechro".to_owned(),
|
"Vechro",
|
||||||
"AngelOnFira".to_owned(),
|
"AngelOnFira",
|
||||||
"Nancok".to_owned(),
|
"Nancok",
|
||||||
"Qutrin".to_owned(),
|
"Qutrin",
|
||||||
"Mckol".to_owned(),
|
"Mckol",
|
||||||
],
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|n| n.to_string())
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,8 +78,11 @@ impl ServerSettings {
|
|||||||
let path = ServerSettings::get_settings_path();
|
let path = ServerSettings::get_settings_path();
|
||||||
let mut config_file = fs::File::create(path)?;
|
let mut config_file = fs::File::create(path)?;
|
||||||
|
|
||||||
let s: &str = &ron::ser::to_string_pretty(self, ron::ser::PrettyConfig::default()).unwrap();
|
let s: &str = &ron::ser::to_string_pretty(self, ron::ser::PrettyConfig::default())
|
||||||
config_file.write_all(s.as_bytes()).unwrap();
|
.expect("Failed serialize settings.");
|
||||||
|
config_file
|
||||||
|
.write_all(s.as_bytes())
|
||||||
|
.expect("Failed to write to config file.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user