mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-08-26 15:02:18 +08:00
59 lines
2.0 KiB
Rust
59 lines
2.0 KiB
Rust
use jzon::{JsonValue, object};
|
|
use actix_web::{web, HttpRequest, Responder};
|
|
|
|
use crate::router::{userdata, global, Body, Session};
|
|
|
|
pub fn routes(cfg: &mut web::ServiceConfig) {
|
|
cfg.route("/start", web::post().to(start));
|
|
cfg.route("/start/assetHash", web::post().to(asset_hash));
|
|
}
|
|
|
|
fn get_asset_hash(req: &HttpRequest, body: &JsonValue) -> Option<String> {
|
|
let platform = req.headers()
|
|
.get("aoharu-platform")
|
|
.and_then(|v| v.to_str().ok())
|
|
.map(global::parse_platform)
|
|
.unwrap_or("Android");
|
|
|
|
println!("Login on platform: {}", platform);
|
|
|
|
let rv = global::get_asset_hash(&body["asset_version"].to_string(), platform);
|
|
if rv.is_none() {
|
|
println!("Unknown asset version {}; telling the client to update.", body["asset_version"]);
|
|
}
|
|
rv
|
|
}
|
|
|
|
async fn asset_hash(req: HttpRequest, Body(body): Body) -> impl Responder {
|
|
match get_asset_hash(&req, &body) {
|
|
Some(hash) => global::api(&req, Some(object!{
|
|
"asset_hash": hash
|
|
})),
|
|
None => global::api_error(&req, global::RESULT_GAME_VERSION_UPDATED),
|
|
}
|
|
}
|
|
|
|
async fn start(req: HttpRequest, Session { key, body }: Session) -> impl Responder {
|
|
let Some(asset_hash) = get_asset_hash(&req, &body) else {
|
|
return global::api_error(&req, global::RESULT_GAME_VERSION_UPDATED);
|
|
};
|
|
|
|
let mut user = userdata::get_acc(&key);
|
|
|
|
println!("Signin from uid: {}", user["user"]["id"].clone());
|
|
|
|
user["user"]["last_login_time"] = global::timestamp().into();
|
|
|
|
userdata::save_acc(&key, user);
|
|
userdata::save_protocol_version(&key, global::client_protocol_version(&req));
|
|
|
|
if !crate::router::card::client_supports_custom_cards(&req) && crate::router::card::account_supports_custom_cards(&key) {
|
|
return global::api_error(&req, global::RESULT_GAME_VERSION_UPDATED); // todo - maybe compatibility layer?
|
|
}
|
|
|
|
global::api(&req, Some(object!{
|
|
"asset_hash": asset_hash,
|
|
"token": hex::encode("Hello") //what is this?
|
|
}))
|
|
}
|