Add delay between RCON commands, hopefully improve reliablity

The Minecraft RCON implementation is very broken/brittle. With this we
hope to improve reliablity.
This commit is contained in:
timvisee 2021-11-15 13:21:12 +01:00
parent 261acafab0
commit b71d0d1013
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
2 changed files with 23 additions and 0 deletions

View File

@ -1,4 +1,14 @@
use std::time::Duration;
use rust_rcon::{Connection, Error as RconError};
use tokio::time;
/// Minecraft RCON quirk.
///
/// Wait this time between RCON operations.
/// The Minecraft RCON implementation is very broken and brittle, this is used in the hopes to
/// improve reliability.
const QUIRK_RCON_GRACE_TIME: Duration = Duration::from_millis(200);
/// An RCON client.
pub struct Rcon {
@ -19,7 +29,17 @@ impl Rcon {
/// Send command over RCON.
pub async fn cmd(&mut self, cmd: &str) -> Result<String, RconError> {
// Minecraft quirk
time::sleep(QUIRK_RCON_GRACE_TIME).await;
// Actually send RCON command
debug!(target: "lazymc::rcon", "Sending RCON: {}", cmd);
self.con.cmd(cmd).await
}
/// Close connection.
pub async fn close(self) {
// Minecraft quirk
time::sleep(QUIRK_RCON_GRACE_TIME).await;
}
}

View File

@ -443,6 +443,9 @@ async fn stop_server_rcon(config: &Config, server: &Server) -> bool {
// TODO: set before stop command, revert state on failure
server.update_state(State::Stopping, config);
// Gracefully close connection
rcon.close().await;
true
}