mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 08:42:20 +08:00
Cleanup asset bundle / hash parser
This commit is contained in:
@@ -12,52 +12,78 @@ use crate::router::{userdata, items};
|
|||||||
use crate::database::gree;
|
use crate::database::gree;
|
||||||
use crate::runtime::get_easter_mode;
|
use crate::runtime::get_easter_mode;
|
||||||
|
|
||||||
pub const ASSET_VERSION_GL: &str = "5260ff15dff8ba0c00ad91400f515f55";
|
struct AssetHashes {
|
||||||
pub const ASSET_HASH_ANDROID_GL: &str = "d210b28037885f3ef56b8f8aa45ac95b";
|
version: &'static str,
|
||||||
pub const ASSET_HASH_IOS_GL: &str = "dd7175e4bcdab476f38c33c7f34b5e4d";
|
android: &'static str,
|
||||||
|
ios: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
pub const ASSET_VERSION_JP: &str = "4c921d2443335e574a82e04ec9ea243c";
|
static ASSET_TABLE: &[(&str, AssetHashes)] = &[
|
||||||
pub const ASSET_HASH_ANDROID_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c";
|
("JP", AssetHashes {
|
||||||
pub const ASSET_HASH_IOS_JP: &str = "b8975be8300013a168d061d3fdcd4a16";
|
version: "4c921d2443335e574a82e04ec9ea243c",
|
||||||
|
android: "67f8f261c16b3cca63e520a25aad6c1c",
|
||||||
|
ios: "b8975be8300013a168d061d3fdcd4a16",
|
||||||
|
}),
|
||||||
|
("GL", AssetHashes {
|
||||||
|
version: "5260ff15dff8ba0c00ad91400f515f55",
|
||||||
|
android: "d210b28037885f3ef56b8f8aa45ac95b",
|
||||||
|
ios: "dd7175e4bcdab476f38c33c7f34b5e4d",
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
pub const ASSET_HASH_ANDROID_EASTER_GL: &str = "da7ae831381c3f29337caa9891db7e6a";
|
static EASTER_HASHES: &[(&str, &str)] = &[
|
||||||
pub const ASSET_HASH_ANDROID_EASTER_JP: &str = "eac0cad61c82bf2e31fc596555747d11";
|
("JP", "eac0cad61c82bf2e31fc596555747d11"),
|
||||||
|
("GL", "da7ae831381c3f29337caa9891db7e6a"),
|
||||||
|
];
|
||||||
|
|
||||||
pub fn get_asset_hash(asset_version: String, android: bool) -> String {
|
pub fn get_player_region(asset_version: &str) -> Option<String> {
|
||||||
|
ASSET_TABLE
|
||||||
|
.iter()
|
||||||
|
.find(|(_, h)| h.version == asset_version)
|
||||||
|
.map(|(region, _)| region.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_platform(header: &str) -> &str {
|
||||||
|
let platform = header.split_whitespace().next().unwrap_or("").to_lowercase();
|
||||||
|
match platform.as_str() {
|
||||||
|
"android" => "Android",
|
||||||
|
"ios" => "iOS",
|
||||||
|
"windows" => "Windows",
|
||||||
|
_ => "Android",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_asset_hash(asset_version: &str, platform: &str) -> Option<String> {
|
||||||
let args = crate::get_args();
|
let args = crate::get_args();
|
||||||
if android {
|
let easter = get_easter_mode();
|
||||||
if asset_version == ASSET_VERSION_JP {
|
|
||||||
if args.jp_android_asset_hash != String::new() {
|
let (region, hashes) = ASSET_TABLE
|
||||||
&args.jp_android_asset_hash
|
.iter()
|
||||||
} else if get_easter_mode() {
|
.find(|(_, h)| h.version == asset_version)?;
|
||||||
ASSET_HASH_ANDROID_EASTER_JP
|
|
||||||
|
let (android_override, ios_override) = match *region {
|
||||||
|
"JP" => (&args.jp_android_asset_hash, &args.jp_ios_asset_hash),
|
||||||
|
"GL" => (&args.en_android_asset_hash, &args.en_ios_asset_hash),
|
||||||
|
_ => (&String::new(), &String::new()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let hash = match platform {
|
||||||
|
"Android" => {
|
||||||
|
if !android_override.is_empty() {
|
||||||
|
android_override.as_str()
|
||||||
|
} else if easter {
|
||||||
|
EASTER_HASHES.iter().find(|(r, _)| r == region).map(|(_, h)| *h).unwrap_or(hashes.android)
|
||||||
} else {
|
} else {
|
||||||
ASSET_HASH_ANDROID_JP
|
hashes.android
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if args.en_android_asset_hash != String::new() {
|
|
||||||
&args.en_android_asset_hash
|
|
||||||
} else if get_easter_mode() {
|
|
||||||
ASSET_HASH_ANDROID_EASTER_GL
|
|
||||||
} else {
|
|
||||||
ASSET_HASH_ANDROID_GL
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
"iOS" => {
|
||||||
if asset_version == ASSET_VERSION_JP {
|
if !ios_override.is_empty() { ios_override.as_str() } else { hashes.ios }
|
||||||
if args.jp_ios_asset_hash != String::new() {
|
|
||||||
&args.jp_ios_asset_hash
|
|
||||||
} else {
|
|
||||||
ASSET_HASH_IOS_JP
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if args.en_ios_asset_hash != String::new() {
|
|
||||||
&args.en_ios_asset_hash
|
|
||||||
} else {
|
|
||||||
ASSET_HASH_IOS_GL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.to_string()
|
_ => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(hash.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_token() -> String {
|
pub fn create_token() -> String {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub fn remove_paid_gems(user: &mut JsonValue, amount: i64) {
|
|||||||
pub fn get_region(headers: &HeaderMap) -> bool {
|
pub fn get_region(headers: &HeaderMap) -> bool {
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
let asset_version = headers.get("aoharu-asset-version").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let asset_version = headers.get("aoharu-asset-version").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
asset_version == global::ASSET_VERSION_JP
|
global::get_player_region(asset_version).unwrap_or(String::from("JP")) == "JP"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_region(user: &mut JsonValue, headers: &HeaderMap) {
|
pub fn check_for_region(user: &mut JsonValue, headers: &HeaderMap) {
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
use jzon::{JsonValue, object};
|
use jzon::{JsonValue, object};
|
||||||
use actix_web::{HttpRequest, http::header::HeaderValue};
|
use actix_web::HttpRequest;
|
||||||
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::{userdata, global};
|
use crate::router::{userdata, global};
|
||||||
|
|
||||||
fn get_asset_hash(req: &HttpRequest, body: &JsonValue) -> String {
|
fn get_asset_hash(req: &HttpRequest, body: &JsonValue) -> String {
|
||||||
if body["asset_version"] != global::ASSET_VERSION_GL && body["asset_version"] != global::ASSET_VERSION_JP {
|
if global::get_player_region(&body["asset_version"].to_string()).is_none() {
|
||||||
println!("Warning! Asset version is not what was expected. (Did the app update?)");
|
println!("Warning! Asset version is not what was expected. (Did the app update?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
let blank_header = HeaderValue::from_static("");
|
let platform = req.headers()
|
||||||
let platform = req.headers().get("aoharu-platform").unwrap_or(&blank_header).to_str().unwrap_or("");
|
.get("aoharu-platform")
|
||||||
let android = !platform.to_lowercase().contains("iphone");
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(global::parse_platform)
|
||||||
global::get_asset_hash(body["asset_version"].to_string(), android)
|
.unwrap_or("Android");
|
||||||
|
|
||||||
|
println!("Login on platform: {}", platform);
|
||||||
|
|
||||||
|
global::get_asset_hash(&body["asset_version"].to_string(), platform).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn asset_hash(req: HttpRequest, body: String) -> Option<JsonValue> {
|
pub fn asset_hash(req: HttpRequest, body: String) -> Option<JsonValue> {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ static SPART_FILES: Dir<'_> = include_dir!("assets/iOS/");
|
|||||||
static SPART_FILES: Dir<'_> = include_dir!("assets/Android/");
|
static SPART_FILES: Dir<'_> = include_dir!("assets/Android/");
|
||||||
|
|
||||||
fn handle_assets(req: HttpRequest) -> HttpResponse {
|
fn handle_assets(req: HttpRequest) -> HttpResponse {
|
||||||
let platform = req.match_info().get("platform").unwrap_or("Android").parse().unwrap_or(String::from("Android"));
|
|
||||||
#[cfg(feature = "library")]
|
#[cfg(feature = "library")]
|
||||||
{
|
{
|
||||||
let lang: String = req.match_info().get("lang").unwrap_or("JP").parse().unwrap_or(String::from("JP"));
|
let lang: String = req.match_info().get("lang").unwrap_or("JP").parse().unwrap_or(String::from("JP"));
|
||||||
|
|||||||
Reference in New Issue
Block a user