From f75c0a19e039f64bbf8b4455b7072e7b1ec7ca32 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:12:10 -0500 Subject: [PATCH] Properly handle jp asset version/hash --- src/router/global.rs | 6 +++++- src/router/start.rs | 29 ++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/router/global.rs b/src/router/global.rs index 7258c0d..58594a7 100644 --- a/src/router/global.rs +++ b/src/router/global.rs @@ -1,7 +1,8 @@ use json::{object, JsonValue}; use crate::encryption; use actix_web::{ - HttpResponse + HttpResponse, + http::header::{HeaderValue, HeaderMap} }; use std::time::{SystemTime, UNIX_EPOCH}; @@ -9,6 +10,9 @@ use std::time::{SystemTime, UNIX_EPOCH}; pub const ASSET_VERSION: &str = "13177023d4b7ad41ff52af4cefba5c55"; pub const ASSET_HASH: &str = "9fbfeda43a5cbf744ef23c06c22170aa"; +pub const ASSET_VERSION_JP: &str = "4c921d2443335e574a82e04ec9ea243c"; +pub const ASSET_HASH_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c"; + pub fn get_login(headers: &HeaderMap) -> String { let blank_header = HeaderValue::from_static(""); let key = headers.get("f19c72ba").unwrap_or(&blank_header).to_str().unwrap_or(""); diff --git a/src/router/start.rs b/src/router/start.rs index b158697..0c02de0 100644 --- a/src/router/start.rs +++ b/src/router/start.rs @@ -2,19 +2,25 @@ use json; use json::object; use crate::router::global; use crate::encryption; -use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue}; +use actix_web::{HttpResponse, HttpRequest}; use crate::router::userdata; pub fn asset_hash(_req: HttpRequest, body: String) -> HttpResponse { let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); - if body["asset_version"].to_string() != global::ASSET_VERSION { + if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP { println!("Warning! Asset version is not what was expected. (Did the app update?)"); } + let hash = if body["asset_version"].to_string() == global::ASSET_VERSION_JP { + global::ASSET_HASH_JP + } else { + global::ASSET_HASH + }; + let resp = object!{ "code": 0, "server_time": global::timestamp(), "data": { - "asset_hash": global::ASSET_HASH + "asset_hash": hash } }; global::send(resp) @@ -22,23 +28,28 @@ pub fn asset_hash(_req: HttpRequest, body: String) -> HttpResponse { pub fn start(req: HttpRequest, body: String) -> HttpResponse { let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); - if body["asset_version"].to_string() != global::ASSET_VERSION { + if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP { println!("Warning! Asset version is not what was expected. (Did the app update?)"); } - let blank_header = HeaderValue::from_static(""); - let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or(""); - let mut user = userdata::get_acc(key); + let key = global::get_login(req.headers()); + let mut user = userdata::get_acc(&key); user["user"]["last_login_time"] = global::timestamp().into(); user["stamina"]["last_updated_time"] = global::timestamp().into(); - userdata::save_acc(key, user); + let hash = if body["asset_version"].to_string() == global::ASSET_VERSION_JP { + global::ASSET_HASH_JP + } else { + global::ASSET_HASH + }; + + userdata::save_acc(&key, user); let resp = object!{ "code": 0, "server_time": global::timestamp(), "data": { - "asset_hash": global::ASSET_HASH, + "asset_hash": hash, "token": hex::encode("Hello") //what is this? } };