Implement needed handlers to get to the initial download

`/api/start`
`/api/dummy/login`
`/apt/user`
`/api/purchase`
This commit is contained in:
Ethan O'Brien
2024-02-23 13:28:44 -06:00
parent f48ae94c0e
commit 9ce5f9bd42
12 changed files with 740 additions and 1 deletions

View File

@ -2,7 +2,8 @@ use json;
use json::object;
use crate::router::global;
use crate::encryption;
use actix_web::{HttpResponse, HttpRequest};
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
use crate::router::userdata;
pub fn asset_hash(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
@ -18,3 +19,29 @@ pub fn asset_hash(_req: HttpRequest, body: String) -> HttpResponse {
};
global::send(resp)
}
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 {
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 uid = req.headers().get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
let mut user = userdata::get_acc(key, uid);
user["user"]["last_login_time"] = global::timestamp().into();
user["stamina"]["last_updated_time"] = global::timestamp().into();
userdata::save_acc(key, uid, user);
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
"asset_hash": global::ASSET_HASH,
"token": hex::encode("Hello") //what is this?
}
};
global::send(resp)
}