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:
parent
261acafab0
commit
b71d0d1013
@ -1,4 +1,14 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use rust_rcon::{Connection, Error as RconError};
|
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.
|
/// An RCON client.
|
||||||
pub struct Rcon {
|
pub struct Rcon {
|
||||||
@ -19,7 +29,17 @@ impl Rcon {
|
|||||||
|
|
||||||
/// Send command over RCON.
|
/// Send command over RCON.
|
||||||
pub async fn cmd(&mut self, cmd: &str) -> Result<String, RconError> {
|
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);
|
debug!(target: "lazymc::rcon", "Sending RCON: {}", cmd);
|
||||||
self.con.cmd(cmd).await
|
self.con.cmd(cmd).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close connection.
|
||||||
|
pub async fn close(self) {
|
||||||
|
// Minecraft quirk
|
||||||
|
time::sleep(QUIRK_RCON_GRACE_TIME).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,6 +443,9 @@ async fn stop_server_rcon(config: &Config, server: &Server) -> bool {
|
|||||||
// TODO: set before stop command, revert state on failure
|
// TODO: set before stop command, revert state on failure
|
||||||
server.update_state(State::Stopping, config);
|
server.update_state(State::Stopping, config);
|
||||||
|
|
||||||
|
// Gracefully close connection
|
||||||
|
rcon.close().await;
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user