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
This commit is contained in:
parent
38d395d9a6
commit
a524629d88
@ -7,4 +7,8 @@ npps4="${NPPS4_ADDRESS:-http://127.0.0.1:51376}"
|
|||||||
|
|
||||||
https=$([ "$HTTPS" = "true" ] && echo "--https" || echo "")
|
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
|
||||||
|
@ -58,7 +58,13 @@ pub struct Args {
|
|||||||
japan_ios: String,
|
japan_ios: String,
|
||||||
|
|
||||||
#[arg(long, default_value = "", help = "Link to asset server.")]
|
#[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]
|
#[actix_web::main]
|
||||||
|
@ -31,7 +31,8 @@ pub mod event_ranking;
|
|||||||
use actix_web::{
|
use actix_web::{
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
http::header::HeaderValue
|
http::header::HeaderValue,
|
||||||
|
http::header::HeaderMap
|
||||||
};
|
};
|
||||||
use json::{JsonValue, object};
|
use json::{JsonValue, object};
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
@ -44,9 +45,21 @@ fn unhandled(req: HttpRequest, body: String) -> Option<JsonValue> {
|
|||||||
None
|
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 {
|
async fn api_req(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let headers = req.headers().clone();
|
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);
|
return webui::main(req);
|
||||||
}
|
}
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
@ -146,15 +159,19 @@ async fn api_req(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
global::send(rv, uid, &headers)
|
global::send(rv, uid, &headers)
|
||||||
} else {
|
} else {
|
||||||
let rv = object!{
|
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(),
|
"server_time": global::timestamp(),
|
||||||
"data": ""
|
"message": ""
|
||||||
};
|
};
|
||||||
global::send(rv, uid, &headers)
|
global::send(rv, uid, &headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
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" {
|
if req.method() == "POST" {
|
||||||
match req.path() {
|
match req.path() {
|
||||||
"/v1.0/auth/initialize" => gree::initialize(req, body),
|
"/v1.0/auth/initialize" => gree::initialize(req, body),
|
||||||
@ -189,7 +206,3 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,6 +116,11 @@ pub fn send(mut data: JsonValue, uid: i64, headers: &HeaderMap) -> HttpResponse
|
|||||||
//println!("{}", json::stringify(data.clone()));
|
//println!("{}", json::stringify(data.clone()));
|
||||||
set_time(&mut data, uid);
|
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() {
|
if !data["data"]["item_list"].is_empty() || !data["data"]["updated_value_list"]["item_list"].is_empty() {
|
||||||
items::check_for_region(&mut data, headers);
|
items::check_for_region(&mut data, headers);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user