Merge branch 'songtronix/hotfix-crash' into 'master'

fix time overflow crash

See merge request veloren/veloren!422
This commit is contained in:
Joshua Barretto 2019-08-09 09:13:28 +00:00
commit 64f05b9e09

View File

@ -226,14 +226,17 @@ fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
}, },
None => { None => {
let time_in_seconds = server.state.ecs_mut().read_resource::<TimeOfDay>().0; let time_in_seconds = server.state.ecs_mut().read_resource::<TimeOfDay>().0;
let current_time = NaiveTime::from_num_seconds_from_midnight(time_in_seconds as u32, 0);
server.clients.notify( let current_time = NaiveTime::from_num_seconds_from_midnight_opt(
entity, // Wraps around back to 0s if it exceeds 24 hours (24 hours = 86400s)
ServerMsg::private(format!( (time_in_seconds as u64 % 86400) as u32,
"Current time is: {}", 0,
current_time.format("%H:%M").to_string()
)),
); );
let msg = match current_time {
Some(time) => format!("Current time is: {}", time.format("%H:%M").to_string()),
None => String::from("Unknown Time"),
};
server.clients.notify(entity, ServerMsg::private(msg));
return; return;
} }
}; };