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

@ -9,6 +9,7 @@ name = "Spire" # server name. optional, defaults to "Spire"
tv_name = "SpireTV" # stv name. optional, defaults to "SpireTV" tv_name = "SpireTV" # stv name. optional, defaults to "SpireTV"
image = "spiretf/docker-spire-server" # docker image for the tf2 server. optional, defaults to "spiretf/docker-spire-server" image = "spiretf/docker-spire-server" # docker image for the tf2 server. optional, defaults to "spiretf/docker-spire-server"
ssh_key = "ssh-rsa AAAA..." # ssh key to add to the server. optional ssh_key = "ssh-rsa AAAA..." # ssh key to add to the server. optional
manage_existing = false # whether to detect and manage server that are already running, optional, disabled by default
[vultr] [vultr]
api_key = "xxx" api_key = "xxx"

View file

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

View file

@ -130,7 +130,15 @@ async fn run_loop(
start_schedule: Schedule, start_schedule: Schedule,
stop_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 { loop {
let next_start = start_schedule.upcoming(Utc).next().unwrap(); let next_start = start_schedule.upcoming(Utc).next().unwrap();

View file

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