mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Address code review points:
- Clarify caffeine fueled comment - Be better at comparing Instant's, and catch the 0 seconds case to say Goodbye to the user - Switch println for 'info!'
This commit is contained in:
parent
b15c107f0b
commit
15c725bfde
@ -77,12 +77,17 @@ fn main() {
|
|||||||
match event {
|
match event {
|
||||||
Event::Chat { message, .. } => println!("{}", message),
|
Event::Chat { message, .. } => println!("{}", message),
|
||||||
Event::Disconnect => {} // TODO
|
Event::Disconnect => {} // TODO
|
||||||
Event::DisconnectionNotification(time) => println!(
|
Event::DisconnectionNotification(time) => {
|
||||||
"{}",
|
let message = match time {
|
||||||
format!("Connection lost. Kicking in {} seconds", time)
|
0 => String::from("Goodbye!"),
|
||||||
),
|
_ => format!("Connection lost. Kicking in {} seconds", time),
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{}", message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up the server after a tick.
|
// Clean up the server after a tick.
|
||||||
client.cleanup();
|
client.cleanup();
|
||||||
|
|
||||||
|
@ -502,17 +502,21 @@ impl Client {
|
|||||||
let mut frontend_events = Vec::new();
|
let mut frontend_events = Vec::new();
|
||||||
|
|
||||||
// Check that we have an valid connection.
|
// Check that we have an valid connection.
|
||||||
// Limit this to the ping time (1s), since that's the max resolution we have
|
// Use the last ping time as a 1s rate limiter, we only notify the user once per second
|
||||||
if Instant::now().duration_since(self.last_server_ping) > Duration::from_secs(1) {
|
if Instant::now().duration_since(self.last_server_ping) > Duration::from_secs(1) {
|
||||||
let duration_since_last_pong = Instant::now().duration_since(self.last_server_pong);
|
let duration_since_last_pong = Instant::now().duration_since(self.last_server_pong);
|
||||||
|
|
||||||
// Dispatch a notification to the HUD warning they will be kicked in {n} seconds
|
// Dispatch a notification to the HUD warning they will be kicked in {n} seconds
|
||||||
if duration_since_last_pong.as_secs_f64() > SERVER_TIMEOUT_GRACE_PERIOD.as_secs_f64() {
|
if duration_since_last_pong.as_secs() >= SERVER_TIMEOUT_GRACE_PERIOD.as_secs() {
|
||||||
|
if let Some(seconds_until_kick) =
|
||||||
|
SERVER_TIMEOUT.checked_sub(duration_since_last_pong)
|
||||||
|
{
|
||||||
frontend_events.push(Event::DisconnectionNotification(
|
frontend_events.push(Event::DisconnectionNotification(
|
||||||
SERVER_TIMEOUT.as_secs() - duration_since_last_pong.as_secs(),
|
seconds_until_kick.as_secs(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let new_msgs = self.postbox.new_messages();
|
let new_msgs = self.postbox.new_messages();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ fn main() {
|
|||||||
// Create server
|
// Create server
|
||||||
let mut server = Server::new(settings).expect("Failed to create server instance!");
|
let mut server = Server::new(settings).expect("Failed to create server instance!");
|
||||||
|
|
||||||
println!("Server is ready to accept connections");
|
info!("Server is ready to accept connections");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let events = server
|
let events = server
|
||||||
|
@ -64,9 +64,14 @@ impl SessionState {
|
|||||||
}
|
}
|
||||||
client::Event::Disconnect => {} // TODO
|
client::Event::Disconnect => {} // TODO
|
||||||
client::Event::DisconnectionNotification(time) => {
|
client::Event::DisconnectionNotification(time) => {
|
||||||
|
let message = match time {
|
||||||
|
0 => String::from("Goodbye!"),
|
||||||
|
_ => format!("Connection lost. Kicking in {} seconds", time),
|
||||||
|
};
|
||||||
|
|
||||||
self.hud.new_message(Chat {
|
self.hud.new_message(Chat {
|
||||||
chat_type: ChatType::Meta,
|
chat_type: ChatType::Meta,
|
||||||
message: format!("Connection lost. Kicking in {} seconds", time),
|
message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user