Add endpoint to set server time

This commit is contained in:
Ethan O'Brien 2024-05-04 18:11:20 -05:00
parent 05aecd02c6
commit 42bdc28d0f
24 changed files with 169 additions and 106 deletions

View file

@ -27,7 +27,7 @@ fn unhandled(req: HttpRequest, body: String) -> HttpResponse {
"server_time": router::global::timestamp(),
"data": ""
};
router::global::send(resp)
router::global::send(resp, req)
}
async fn request(req: HttpRequest, body: String) -> HttpResponse {
@ -94,6 +94,7 @@ async fn request(req: HttpRequest, body: String) -> HttpResponse {
"/api/webui/login" => router::webui::login(req, body),
"/api/webui/startLoginbonus" => router::webui::start_loginbonus(req, body),
"/api/webui/import" => router::webui::import(req, body),
"/api/webui/set_time" => router::webui::set_time(req, body),
"/api/user/getregisteredplatformlist" => router::user::getregisteredplatformlist(req, body),
"/api/user/sif/migrate" => router::user::sif_migrate(req, body),
"/api/user/ss/migrate" => router::user::sifas_migrate(req, body),

View file

@ -54,7 +54,7 @@ pub fn reinforce(req: HttpRequest, body: String) -> HttpResponse {
clear_mission_ids: []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn skill_reinforce(req: HttpRequest, body: String) -> HttpResponse {
@ -76,7 +76,7 @@ pub fn skill_reinforce(req: HttpRequest, body: String) -> HttpResponse {
clear_mission_ids: []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn evolve(req: HttpRequest, body: String) -> HttpResponse {
@ -98,5 +98,5 @@ pub fn evolve(req: HttpRequest, body: String) -> HttpResponse {
clear_mission_ids: []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -31,25 +31,25 @@ pub fn home(req: HttpRequest, body: String) -> HttpResponse {
"master_chat_attachment_ids": []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn start(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn start(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {"select_talk_id_list":[],"get_item_list":[],"is_read":0}
};
global::send(resp)
global::send(resp, req)
}
pub fn end(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn end(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}

View file

@ -215,16 +215,16 @@ fn get_clearrate_json() -> JsonValue {
}
}
pub fn clearrate(_req: HttpRequest) -> HttpResponse {
pub fn clearrate(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": get_clearrate_json()
};
global::send(resp)
global::send(resp, req)
}
pub fn ranking(_req: HttpRequest, body: String) -> HttpResponse {
pub fn ranking(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let live = body["master_live_id"].as_i64().unwrap();
@ -253,5 +253,5 @@ pub fn ranking(_req: HttpRequest, body: String) -> HttpResponse {
"ranking_list": rank
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -4,7 +4,7 @@ use actix_web::{HttpResponse, HttpRequest};
use crate::router::global;
use crate::encryption;
pub fn error(_req: HttpRequest, body: String) -> HttpResponse {
pub fn error(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
println!("client error: {}", body["code"]);
@ -14,5 +14,5 @@ pub fn error(_req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"message": ""
};
global::send(resp)
global::send(resp, req)
}

View file

@ -16,7 +16,7 @@ pub fn event(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": event["event_data"].clone()
};
global::send(resp)
global::send(resp, req)
}
fn switch_music(event: &mut JsonValue, music_id: i32, target_score: i64, index: i32) {
@ -60,7 +60,7 @@ pub fn star_event(req: HttpRequest, body: String) -> HttpResponse {
reward_list: []
}
};
global::send(resp)
global::send(resp, req)
}
//todo - randomize
@ -75,5 +75,5 @@ pub fn change_target_music(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": event["event_data"]["star_event"].clone()
};
global::send(resp)
global::send(resp, req)
}

View file

@ -24,13 +24,13 @@ lazy_static! {
};
}
pub fn exchange(_req: HttpRequest) -> HttpResponse {
pub fn exchange(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {"exchange_list":[]}
};
global::send(resp)
global::send(resp, req)
}
pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
@ -66,5 +66,5 @@ pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -32,7 +32,7 @@ pub fn friend(req: HttpRequest, body: String) -> HttpResponse {
"friend_list": rv
}
};
global::send(resp)
global::send(resp, req)
}
pub fn ids(req: HttpRequest) -> HttpResponse {
@ -44,7 +44,7 @@ pub fn ids(req: HttpRequest) -> HttpResponse {
"server_time": global::timestamp(),
"data": friends
};
global::send(resp)
global::send(resp, req)
}
pub fn recommend(req: HttpRequest, body: String) -> HttpResponse {
@ -74,7 +74,7 @@ pub fn recommend(req: HttpRequest, body: String) -> HttpResponse {
friend_list: rv
}
};
global::send(resp)
global::send(resp, req)
}
pub fn search(req: HttpRequest, body: String) -> HttpResponse {
@ -90,7 +90,7 @@ pub fn search(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
global::send(resp, req)
}
pub fn request(req: HttpRequest, body: String) -> HttpResponse {
@ -113,7 +113,7 @@ pub fn request(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn approve(req: HttpRequest, body: String) -> HttpResponse {
@ -139,7 +139,7 @@ pub fn approve(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn cancel(req: HttpRequest, body: String) -> HttpResponse {
@ -161,7 +161,7 @@ pub fn cancel(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn delete(req: HttpRequest, body: String) -> HttpResponse {
@ -183,5 +183,5 @@ pub fn delete(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}

View file

@ -1,7 +1,8 @@
use json::{array, object, JsonValue};
use actix_web::{
HttpResponse,
http::header::{HeaderValue, HeaderMap}
http::header::{HeaderValue, HeaderMap},
HttpRequest
};
use std::time::{SystemTime, UNIX_EPOCH};
use base64::{Engine as _, engine::general_purpose};
@ -79,9 +80,27 @@ pub fn timestamp_since_midnight() -> u64 {
rv
}
pub fn send(mut data: JsonValue) -> HttpResponse {
//println!("{}", json::stringify(data.clone()));
fn set_time(data: &mut JsonValue, req: HttpRequest) {
data["server_time"] = 1711741114.into();
let blank_header = HeaderValue::from_static("");
let uid = headers.get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("").parse<i64>().unwrap_or(0);
if uid == 0 {
return;
}
let server_data = userdata::get_server_data(get_login_token(uid));
if server_data["timestamp"].as_i64().is_ok() {
if server_data["timestamp"].as_i64().unwrap() == 0 {
data["server_time"] = global::timestamp().into();
return;
}
data["server_time"] = server_data["timestamp"].clone();
}
}
pub fn send(mut data: JsonValue, req: HttpRequest) -> HttpResponse {
//println!("{}", json::stringify(data.clone()));
set_time(&data, req)
let encrypted = encryption::encrypt_packet(&json::stringify(data)).unwrap();
let resp = encrypted.into_bytes();
@ -89,8 +108,8 @@ pub fn send(mut data: JsonValue) -> HttpResponse {
HttpResponse::Ok().body(resp)
}
pub fn error_resp() -> HttpResponse {
send(object!{})
pub fn error_resp(req: HttpRequest) -> HttpResponse {
send(object!{}, req)
}
pub fn start_login_bonus(id: i64, bonus: &mut JsonValue) -> bool {

View file

@ -22,7 +22,7 @@ pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
fn check_gifts(user: &mut JsonValue) {
@ -49,7 +49,7 @@ pub fn gift_get(req: HttpRequest) -> HttpResponse {
"gift_list": user["home"]["gift_list"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn preset_get(req: HttpRequest) -> HttpResponse {
@ -65,7 +65,7 @@ pub fn preset_get(req: HttpRequest) -> HttpResponse {
"card_list": user["card_list"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn home(req: HttpRequest) -> HttpResponse {
@ -80,5 +80,5 @@ pub fn home(req: HttpRequest) -> HttpResponse {
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
global::send(resp, req)
}

View file

@ -7,7 +7,7 @@ use crate::router::{global, userdata, items};
use crate::encryption;
use crate::router::clear_rate::live_completed;
pub fn retire(_req: HttpRequest, body: String) -> HttpResponse {
pub fn retire(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
live_completed(body["master_live_id"].as_i64().unwrap(), body["level"].as_i32().unwrap(), true, 0, 0);
let resp = object!{
@ -19,7 +19,7 @@ pub fn retire(_req: HttpRequest, body: String) -> HttpResponse {
"event_point_list": []
}
};
global::send(resp)
global::send(resp, req)
}
fn random_number(lowest: usize, highest: usize) -> usize {
@ -162,10 +162,10 @@ pub fn guest(req: HttpRequest, body: String) -> HttpResponse {
"guest_list": guest_list
}
};
global::send(resp)
global::send(resp, req)
}
pub fn mission(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn mission(req: HttpRequest, _body: String) -> HttpResponse {
//todo
let resp = object!{
"code": 0,
@ -176,25 +176,25 @@ pub fn mission(_req: HttpRequest, _body: String) -> HttpResponse {
"clear_count_ranking": ""
}
};
global::send(resp)
global::send(resp, req)
}
pub fn start(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn start(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn event_start(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn event_start(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn continuee(req: HttpRequest, body: String) -> HttpResponse {
@ -210,7 +210,7 @@ pub fn continuee(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"gem": user["gem"].clone()
};
global::send(resp)
global::send(resp, req)
}
pub fn update_live_data(user: &mut JsonValue, data: &JsonValue, add: bool) -> JsonValue {
@ -435,7 +435,7 @@ fn live_end(req: &HttpRequest, body: &String) -> JsonValue {
pub fn end(req: HttpRequest, body: String) -> HttpResponse {
let resp = live_end(&req, &body);
global::send(resp)
global::send(resp, req)
}
pub fn event_end(req: HttpRequest, body: String) -> HttpResponse {
@ -484,7 +484,7 @@ pub fn event_end(req: HttpRequest, body: String) -> HttpResponse {
userdata::save_acc_event(&key, event);
global::send(resp)
global::send(resp, req)
}
pub fn skip(req: HttpRequest, body: String) -> HttpResponse {
@ -540,5 +540,5 @@ pub fn skip(req: HttpRequest, body: String) -> HttpResponse {
"event_ranking_data": []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -17,7 +17,7 @@ pub fn dummy(req: HttpRequest, body: String) -> HttpResponse {
"user_id": user["user"]["id"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
lazy_static! {
@ -105,7 +105,7 @@ pub fn bonus(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": user["clear_mission_ids"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn bonus_event(req: HttpRequest, body: String) -> HttpResponse {
@ -131,5 +131,5 @@ pub fn bonus_event(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": user["clear_mission_ids"].clone()
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -61,7 +61,7 @@ lazy_static! {
};
}
pub fn tutorial(_req: HttpRequest, body: String) -> HttpResponse {
pub fn tutorial(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let id = body["master_character_id"].to_string();
@ -92,7 +92,7 @@ pub fn tutorial(_req: HttpRequest, body: String) -> HttpResponse {
"item_list": []
}
};
global::send(resp)
global::send(resp, req)
}
fn get_card_master_id(lottery_id: String, lottery_number: String) -> Option<i64> {
@ -136,7 +136,7 @@ fn get_random_cards(id: i64, count: usize) -> JsonValue {
rv
}
pub fn lottery(_req: HttpRequest) -> HttpResponse {
pub fn lottery(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -144,7 +144,7 @@ pub fn lottery(_req: HttpRequest) -> HttpResponse {
"lottery_list": []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
@ -243,5 +243,5 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
"draw_count_list": []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -15,7 +15,7 @@ pub fn mission(req: HttpRequest) -> HttpResponse {
"mission_list": missions
}
};
global::send(resp)
global::send(resp, req)
}
pub fn clear(req: HttpRequest, body: String) -> HttpResponse {
@ -42,10 +42,10 @@ pub fn clear(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": body["master_mission_ids"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn receive(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn receive(req: HttpRequest, _body: String) -> HttpResponse {
//let key = global::get_login(req.headers(), &body);
//let missions = userdata::get_acc_missions(&key);
//let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
@ -59,5 +59,5 @@ pub fn receive(_req: HttpRequest, _body: String) -> HttpResponse {
"reward_list": []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -4,7 +4,7 @@ use actix_web::{HttpResponse, HttpRequest};
use crate::router::global;
//todo
pub fn reward(_req: HttpRequest) -> HttpResponse {
pub fn reward(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
@ -13,14 +13,14 @@ pub fn reward(_req: HttpRequest) -> HttpResponse {
"reward_list": []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn reward_post(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn reward_post(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}

View file

@ -3,7 +3,7 @@ use actix_web::{HttpResponse, HttpRequest};
use crate::router::global;
pub fn purchase(_req: HttpRequest) -> HttpResponse {
pub fn purchase(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -35,5 +35,5 @@ pub fn purchase(_req: HttpRequest) -> HttpResponse {
]
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -4,7 +4,7 @@ use actix_web::{HttpResponse, HttpRequest};
use crate::router::{global, userdata, items};
use crate::encryption;
pub fn events(_req: HttpRequest) -> HttpResponse {
pub fn events(req: HttpRequest) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -12,7 +12,7 @@ pub fn events(_req: HttpRequest) -> HttpResponse {
"serial_code_list": []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
@ -37,7 +37,7 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
"result_code": 3
}
};
return global::send(resp);
return global::send(resp, req);
}
userdata::save_acc_home(&key, user.clone());
@ -53,5 +53,5 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
"excluded_gift_list": []
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -31,7 +31,7 @@ pub fn shop(req: HttpRequest) -> HttpResponse {
"shop_list": user["shop_list"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn buy(req: HttpRequest, body: String) -> HttpResponse {
@ -60,5 +60,5 @@ pub fn buy(req: HttpRequest, body: String) -> HttpResponse {
}
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -39,7 +39,7 @@ pub fn asset_hash(req: HttpRequest, body: String) -> HttpResponse {
"asset_hash": get_asset_hash(&req, &body)
}
};
global::send(resp)
global::send(resp, req)
}
pub fn start(req: HttpRequest, body: String) -> HttpResponse {
@ -61,5 +61,5 @@ pub fn start(req: HttpRequest, body: String) -> HttpResponse {
"token": hex::encode("Hello") //what is this?
}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -3,11 +3,11 @@ use actix_web::{HttpResponse, HttpRequest};
use crate::router::global;
pub fn read(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn read(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {"gift_list":[],"updated_value_list":{"master_chat_room_ids":[3001001,3101001],"master_chat_chapter_ids":[300100101,310100101]},"reward_list":[{"type":16,"value":3001001,"level":0,"amount":1},{"type":16,"value":3101001,"level":0,"amount":1},{"type":17,"value":300100101,"level":0,"amount":1},{"type":17,"value":310100101,"level":0,"amount":1}],"clear_mission_ids":[]}
};
global::send(resp)
global::send(resp, req)
}

View file

@ -20,5 +20,5 @@ pub fn tutorial(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}

View file

@ -30,7 +30,7 @@ pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": []
}
};
global::send(resp)
global::send(resp, req)
}
pub fn user(req: HttpRequest) -> HttpResponse {
@ -44,7 +44,7 @@ pub fn user(req: HttpRequest) -> HttpResponse {
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
global::send(resp, req)
}
lazy_static! {
@ -116,7 +116,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
"reward_list": rewards
}
};
global::send(resp)
global::send(resp, req)
}
pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
@ -171,7 +171,7 @@ pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
"clear_mission_ids": user_2["clear_mission_ids"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn announcement(req: HttpRequest) -> HttpResponse {
@ -190,7 +190,7 @@ pub fn announcement(req: HttpRequest) -> HttpResponse {
new_announcement_flag: 0
}
};
global::send(resp)
global::send(resp, req)
}
pub fn uid_to_code(uid: String) -> String {
@ -224,7 +224,7 @@ pub fn code_to_uid(code: String) -> String {
.replace("M", "0");
}
pub fn get_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
pub fn get_migration_code(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let code = uid_to_code(body["user_id"].to_string());
@ -236,7 +236,7 @@ pub fn get_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
"migrationCode": code
}
};
global::send(resp)
global::send(resp, req)
}
pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
@ -253,10 +253,10 @@ pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": []
};
global::send(resp)
global::send(resp, req)
}
pub fn verify_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
pub fn verify_migration_code(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let uid = code_to_uid(body["migrationCode"].to_string()).parse::<i64>().unwrap_or(0);
@ -269,7 +269,7 @@ pub fn verify_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"message": ""
};
return global::send(resp);
return global::send(resp, req);
}
let data_user = userdata::get_acc(&user["login_token"].to_string());
@ -284,9 +284,9 @@ pub fn verify_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
"free": data_user["gem"]["free"].clone()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn request_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
pub fn request_migration_code(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let uid = code_to_uid(body["migrationCode"].to_string()).parse::<i64>().unwrap_or(0);
@ -299,7 +299,7 @@ pub fn request_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"message": ""
};
return global::send(resp);
return global::send(resp, req);
}
let resp = object!{
@ -309,9 +309,9 @@ pub fn request_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
"twxuid": user["login_token"].to_string()
}
};
global::send(resp)
global::send(resp, req)
}
pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
pub fn migration(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let user = userdata::get_name_and_rank(body["user_id"].to_string().parse::<i64>().unwrap());
@ -321,7 +321,7 @@ pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
global::send(resp, req)
}
pub fn detail(req: HttpRequest, body: String) -> HttpResponse {
@ -342,7 +342,7 @@ pub fn detail(req: HttpRequest, body: String) -> HttpResponse {
user_detail_list: user_detail_list
}
};
global::send(resp)
global::send(resp, req)
}
pub fn sif(req: HttpRequest) -> HttpResponse {
@ -356,10 +356,10 @@ pub fn sif(req: HttpRequest) -> HttpResponse {
cards: cards
}
};
global::send(resp)
global::send(resp, req)
}
pub fn sifas_migrate(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn sifas_migrate(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -370,10 +370,10 @@ pub fn sifas_migrate(_req: HttpRequest, _body: String) -> HttpResponse {
"lock_remain_time": null
}
};
global::send(resp)
global::send(resp, req)
}
pub fn sif_migrate(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn sif_migrate(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -381,10 +381,10 @@ pub fn sif_migrate(_req: HttpRequest, _body: String) -> HttpResponse {
"sif_migrate_status": 38
}
};
global::send(resp)
global::send(resp, req)
}
pub fn getregisteredplatformlist(_req: HttpRequest, _body: String) -> HttpResponse {
pub fn getregisteredplatformlist(req: HttpRequest, _body: String) -> HttpResponse {
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -394,7 +394,7 @@ pub fn getregisteredplatformlist(_req: HttpRequest, _body: String) -> HttpRespon
"twitter": 0
}
};
global::send(resp)
global::send(resp, req)
}
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
@ -431,7 +431,7 @@ pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
cardstoreward = array![40010001, 40020001, 40030001, 40040001, 40050001, 40060001, 40070001, 40080001, 40090001]; //liella
masterid += 9 + 9 + 12; //nijigasaki
} else {
return global::error_resp();
return global::error_resp(req);
}
masterid += userr;
@ -456,5 +456,5 @@ pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
"server_time": global::timestamp(),
"data": user["user"].clone()
};
global::send(resp)
global::send(resp, req)
}

View file

@ -181,6 +181,9 @@ pub fn get_acc_sif(auth_key: &str) -> JsonValue {
pub fn get_acc_friends(auth_key: &str) -> JsonValue {
get_data(auth_key, "friends")
}
pub fn get_server_data(auth_key: &str) -> JsonValue {
get_data(auth_key, "server_data")
}
pub fn get_acc_event(auth_key: &str) -> JsonValue {
let event = get_data(auth_key, "event");
if event.is_empty() {
@ -220,6 +223,9 @@ pub fn save_acc_event(auth_key: &str, data: JsonValue) {
pub fn save_acc_eventlogin(auth_key: &str, data: JsonValue) {
save_data(auth_key, "eventloginbonus", data);
}
pub fn save_server_data(auth_key: &str, data: JsonValue) {
save_data(auth_key, "server_data", data);
}
fn generate_salt() -> Vec<u8> {
let mut rng = rand::thread_rng();
@ -516,6 +522,30 @@ pub fn webui_start_loginbonus(bonus_id: i64, token: &str) -> JsonValue {
};
}
pub fn set_server_time(time: i64, token: &str) -> JsonValue {
if time > global::timestamp() {
return object!{
result: "ERR",
message: "Timestamp is in the future"
};
}
let login_token = webui_login_token(token);
if login_token.is_none() {
return object!{
result: "ERR",
message: "Failed to validate token"
};
}
let login_token = login_token.unwrap();
let mut server_data = get_server_data(&login_token);
server_data["server_time"] = time.into();
save_server_data(&login_token, server_data);
return object!{
result: "OK"
};
}
pub fn webui_logout(token: &str) {
DATABASE.lock_and_exec("DELETE FROM webui WHERE token=?1", params!(token));
}

View file

@ -101,6 +101,19 @@ pub fn start_loginbonus(req: HttpRequest, body: String) -> HttpResponse {
.body(json::stringify(resp))
}
pub fn set_time(req: HttpRequest, body: String) -> HttpResponse {
let token = get_login_token(&req);
if token.is_none() {
return error("Not logged in");
}
let body = json::parse(&body).unwrap();
let resp = userdata::set_server_time(body["timestamp"].as_i64().unwrap(), &token.unwrap());
HttpResponse::Ok()
.insert_header(ContentType::json())
.body(json::stringify(resp))
}
pub fn logout(req: HttpRequest) -> HttpResponse {
let token = get_login_token(&req);
if !token.is_none() {