From a063de2eb5f6b98658ec2f0b8789eea4d97b206a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Jun 2024 14:06:44 -0400 Subject: [PATCH] Separate the login and world gates --- src/bin/kawari-admin.rs | 17 ++++++++++++----- src/bin/kawari-frontier.rs | 27 +++++++++++++++++++++++---- src/config.rs | 8 ++++++-- templates/admin.html | 6 ++++-- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/bin/kawari-admin.rs b/src/bin/kawari-admin.rs index 00fd381..3301565 100644 --- a/src/bin/kawari-admin.rs +++ b/src/bin/kawari-admin.rs @@ -24,13 +24,14 @@ async fn root() -> Html { let environment = setup_default_environment(); let template = environment.get_template("admin.html").unwrap(); - Html(template.render(context! { gate_open => config.gate_open }).unwrap()) + Html(template.render(context! { worlds_open => config.worlds_open, login_open => config.login_open }).unwrap()) } #[derive(Deserialize, Debug)] #[allow(dead_code)] struct Input { - gate_open: Option, + worlds_open: Option, + login_open: Option, } async fn apply(Form(input): Form) -> Redirect { @@ -38,10 +39,16 @@ async fn apply(Form(input): Form) -> Redirect { let mut config = get_config(); - if let Some(gate_open) = input.gate_open { - config.gate_open = gate_open == "on"; + if let Some(gate_open) = input.worlds_open { + config.worlds_open = gate_open == "on"; } else { - config.gate_open = false; + config.worlds_open = false; + } + + if let Some(gate_open) = input.login_open { + config.login_open = gate_open == "on"; + } else { + config.login_open = false; } serde_json::to_writer( diff --git a/src/bin/kawari-frontier.rs b/src/bin/kawari-frontier.rs index d79f445..121f0cf 100644 --- a/src/bin/kawari-frontier.rs +++ b/src/bin/kawari-frontier.rs @@ -12,7 +12,7 @@ struct GateStatus { status: i32, } -async fn get_gate_status() -> Json { +async fn get_login_status() -> Json { tracing::info!("Requesting gate status..."); let mut is_open = 0; @@ -21,7 +21,26 @@ async fn get_gate_status() -> Json { if let Ok(data) = std::fs::read_to_string("config.json") { let config: Config = serde_json::from_str(&data).expect("Failed to parse"); - if config.gate_open { + if config.login_open { + is_open = 1; + } + } + + Json(GateStatus { + status: is_open + }) +} + +async fn get_world_status() -> Json { + tracing::info!("Requesting gate status..."); + + let mut is_open = 0; + + // read config + if let Ok(data) = std::fs::read_to_string("config.json") { + let config: Config = serde_json::from_str(&data).expect("Failed to parse"); + + if config.worlds_open { is_open = 1; } } @@ -76,8 +95,8 @@ async fn main() { tracing_subscriber::fmt::init(); let app = Router::new() - .route("/worldStatus/gate_status.json", get(get_gate_status)) - .route("/worldStatus/login_status.json", get(get_gate_status)) + .route("/worldStatus/gate_status.json", get(get_world_status)) + .route("/worldStatus/login_status.json", get(get_login_status)) .route("/news/headline.json", get(get_headline)); let addr = SocketAddr::from(([127, 0, 0, 1], 5857)); diff --git a/src/config.rs b/src/config.rs index f89e815..131d5da 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,10 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub struct Config { #[serde(default)] - pub gate_open: bool, + pub worlds_open: bool, + + #[serde(default)] + pub login_open: bool, #[serde(default = "default_supported_platforms")] pub supported_platforms: Vec, @@ -12,7 +15,8 @@ pub struct Config { impl Default for Config { fn default() -> Self { Self { - gate_open: false, + worlds_open: false, + login_open: false, supported_platforms: default_supported_platforms() } } diff --git a/templates/admin.html b/templates/admin.html index e074d5a..da509cc 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -1,5 +1,7 @@ -

Gate open:{{ gate_open }}

+

Gate open:{{ worlds_open }}

+

Gate open:{{ login_open }}

- + +
\ No newline at end of file