mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-24 16:17:44 +00:00
Separate the login and world gates
This commit is contained in:
parent
ee6b4f2f7f
commit
a063de2eb5
4 changed files with 45 additions and 13 deletions
|
@ -24,13 +24,14 @@ async fn root() -> Html<String> {
|
|||
|
||||
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<String>,
|
||||
worlds_open: Option<String>,
|
||||
login_open: Option<String>,
|
||||
}
|
||||
|
||||
async fn apply(Form(input): Form<Input>) -> Redirect {
|
||||
|
@ -38,10 +39,16 @@ async fn apply(Form(input): Form<Input>) -> 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(
|
||||
|
|
|
@ -12,7 +12,7 @@ struct GateStatus {
|
|||
status: i32,
|
||||
}
|
||||
|
||||
async fn get_gate_status() -> Json<GateStatus> {
|
||||
async fn get_login_status() -> Json<GateStatus> {
|
||||
tracing::info!("Requesting gate status...");
|
||||
|
||||
let mut is_open = 0;
|
||||
|
@ -21,7 +21,26 @@ async fn get_gate_status() -> Json<GateStatus> {
|
|||
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<GateStatus> {
|
||||
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));
|
||||
|
|
|
@ -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<String>,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<p>Gate open:{{ gate_open }}</p>
|
||||
<p>Gate open:{{ worlds_open }}</p>
|
||||
<p>Gate open:{{ login_open }}</p>
|
||||
<form action='apply' method='post'>
|
||||
<input type='checkbox' id='gate_open' name='gate_open' checked/>
|
||||
<input type='checkbox' id='worlds_open' name='worlds_open' checked/>
|
||||
<input type='checkbox' id='login_open' name='login_open' checked/>
|
||||
<button type='submit'>Apply</button>
|
||||
</form>
|
Loading…
Add table
Reference in a new issue