From a524629d88c27ad1fa146be40e0a2b3ea12430a3 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Thu, 17 Oct 2024 23:38:50 -0500 Subject: [PATCH] Add server-admin features - Added ability to "hide" server (by disabling the webui entirely, it will act exactly like the official server) - Added ability to define the maximum timestamp that the server can return. This can be helpful if the server admin never wants to go past EOS --- docker/start.sh | 6 +++++- src/main.rs | 8 +++++++- src/router.rs | 29 +++++++++++++++++++++-------- src/router/global.rs | 5 +++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/docker/start.sh b/docker/start.sh index e53880d..c6421c0 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -7,4 +7,8 @@ npps4="${NPPS4_ADDRESS:-http://127.0.0.1:51376}" https=$([ "$HTTPS" = "true" ] && echo "--https" || echo "") -/root/ew/ew --path $directory --port $port --npps4 $npps4 $https --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" +hidden=$([ "$HIDDEN" = "true" ] && echo "--hidden" || echo "") + +maxTime="${MAXTIME:-0}" + +/root/ew/ew --path $directory --port $port --npps4 $npps4 $hidden $https --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" --max-time $maxTime diff --git a/src/main.rs b/src/main.rs index a70c185..9ec85ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,13 @@ pub struct Args { japan_ios: String, #[arg(long, default_value = "", help = "Link to asset server.")] - assets_url: String + assets_url: String, + + #[arg(long, default_value_t = 0, help = "Max time returned by the server, in the JSON \"timestamp\" key.")] + max_time: u64, + + #[arg(long, default_value_t = false, help = "Disable webui, act completely like the original server")] + hidden: bool } #[actix_web::main] diff --git a/src/router.rs b/src/router.rs index 7ea70bd..03a8337 100644 --- a/src/router.rs +++ b/src/router.rs @@ -31,7 +31,8 @@ pub mod event_ranking; use actix_web::{ HttpResponse, HttpRequest, - http::header::HeaderValue + http::header::HeaderValue, + http::header::HeaderMap }; use json::{JsonValue, object}; use crate::encryption; @@ -44,9 +45,21 @@ fn unhandled(req: HttpRequest, body: String) -> Option { None } +fn not_found(headers: &HeaderMap) -> HttpResponse { + let rv = object!{ + "code": 4, + "server_time": global::timestamp(), + "message": "" + }; + return global::send(rv, 0, &headers) +} + async fn api_req(req: HttpRequest, body: String) -> HttpResponse { let headers = req.headers().clone(); - if !req.path().starts_with("/api") && !req.path().starts_with("/v1.0") { + let args = crate::get_args(); + if args.hidden && (req.path().starts_with("/api/webui/") || !(req.path().starts_with("/api") || req.path().starts_with("/v1.0"))) { + return not_found(&headers); + } else if !req.path().starts_with("/api") && !req.path().starts_with("/v1.0") { return webui::main(req); } let blank_header = HeaderValue::from_static(""); @@ -146,15 +159,19 @@ async fn api_req(req: HttpRequest, body: String) -> HttpResponse { global::send(rv, uid, &headers) } else { let rv = object!{ - "code": 2,//Idontnermemrmemremremermrme + "code": 4,//Idontnermemrmemremremermrme <-- I think I was not okay when I put this note because I dont remmebr doing it "server_time": global::timestamp(), - "data": "" + "message": "" }; global::send(rv, uid, &headers) } } pub async fn request(req: HttpRequest, body: String) -> HttpResponse { + let args = crate::get_args(); + if args.hidden && req.path().starts_with("/api/webui/") { + return not_found(&req.headers()); + } if req.method() == "POST" { match req.path() { "/v1.0/auth/initialize" => gree::initialize(req, body), @@ -189,7 +206,3 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse { } } } - - - - diff --git a/src/router/global.rs b/src/router/global.rs index 73706f1..ec2a9bf 100644 --- a/src/router/global.rs +++ b/src/router/global.rs @@ -116,6 +116,11 @@ pub fn send(mut data: JsonValue, uid: i64, headers: &HeaderMap) -> HttpResponse //println!("{}", json::stringify(data.clone())); set_time(&mut data, uid); + let args = crate::get_args(); + if args.max_time > 10 && args.max_time < data["server_time"].as_u64().unwrap_or(0) { + data["server_time"] = args.max_time.into(); + } + if !data["data"]["item_list"].is_empty() || !data["data"]["updated_value_list"]["item_list"].is_empty() { items::check_for_region(&mut data, headers); }