fix empty server detection and add option to manage existing instances

This commit is contained in:
Robin Appelman 2021-08-09 16:35:59 +02:00
commit 86adb69a95
4 changed files with 13 additions and 1 deletions

View file

@ -72,6 +72,8 @@ pub struct ServerConfig {
#[serde(default = "server_default_tv_name")]
pub tv_name: String,
pub ssh_key: Option<String>,
#[serde(default)]
pub manage_existing: bool,
}
fn server_default_image() -> String {

View file

@ -130,7 +130,15 @@ async fn run_loop(
start_schedule: Schedule,
stop_schedule: Schedule,
) {
let mut active_server: Option<Server> = None;
let mut active_server = if config.server.manage_existing {
cloud
.list()
.await
.map(|servers| servers.into_iter().next())
.unwrap_or_default()
} else {
None
};
loop {
let next_start = start_schedule.upcoming(Utc).next().unwrap();

View file

@ -14,6 +14,7 @@ impl Rcon {
let player_lines = status
.lines()
.filter(|line| line.starts_with('#'))
.filter(|line| !line.contains("# userid"))
.filter(|line| !line.contains(" BOT "));
Ok(player_lines.count())
}