mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
274 lines
9 KiB
Rust
274 lines
9 KiB
Rust
use json;
|
|
use json::{array, object, JsonValue};
|
|
use crate::router::global;
|
|
use crate::encryption;
|
|
use actix_web::{HttpResponse, HttpRequest};
|
|
use crate::router::userdata;
|
|
|
|
pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
|
|
|
let key = global::get_login(req.headers());
|
|
let mut user = userdata::get_acc(&key);
|
|
|
|
for (i, data) in user["deck_list"].members().enumerate() {
|
|
if data["slot"].to_string() == body["slot"].to_string() {
|
|
user["deck_list"][i] = body["main_card_ids"].clone();
|
|
break;
|
|
}
|
|
}
|
|
userdata::save_acc(&key, user.clone());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": {
|
|
"deck": {
|
|
"slot": body["slot"].clone(),
|
|
"leader_role": 0,
|
|
"main_card_ids": body["main_card_ids"].clone()
|
|
},
|
|
"clear_mission_ids": []
|
|
}
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
pub fn user(req: HttpRequest) -> HttpResponse {
|
|
|
|
let key = global::get_login(req.headers());
|
|
let user = userdata::get_acc(&key);
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": user
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
pub fn user_post(req: HttpRequest, body: String) -> HttpResponse {
|
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
|
|
|
let key = global::get_login(req.headers());
|
|
let mut user = userdata::get_acc(&key);
|
|
let user_2 = userdata::get_acc_home(&key);
|
|
|
|
if !body["name"].is_null() {
|
|
user["user"]["name"] = body["name"].clone();
|
|
}
|
|
if !body["friend_request_disabled"].is_null() {
|
|
user["user"]["friend_request_disabled"] = body["friend_request_disabled"].clone();
|
|
}
|
|
if !body["profile_settings"].is_null() {
|
|
user["user"]["profile_settings"] = body["profile_settings"].clone();
|
|
}
|
|
|
|
|
|
userdata::save_acc(&key, user.clone());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": {
|
|
"user": user["user"].clone(),
|
|
"clear_mission_ids": user_2["clear_mission_ids"].clone()
|
|
}
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
fn uid_to_code(uid: String) -> String {
|
|
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
|
|
return uid
|
|
.replace("1", "A")
|
|
.replace("2", "G")
|
|
.replace("3", "W")
|
|
.replace("4", "Q")
|
|
.replace("5", "Y")
|
|
.replace("6", "6")
|
|
.replace("7", "I")
|
|
.replace("8", "P")
|
|
.replace("9", "U")
|
|
.replace("0", "M")
|
|
+ "7";
|
|
}
|
|
fn code_to_uid(code: String) -> String {
|
|
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
|
|
return code
|
|
.replace("7", "")
|
|
.replace("A", "1")
|
|
.replace("G", "2")
|
|
.replace("W", "3")
|
|
.replace("Q", "4")
|
|
.replace("Y", "5")
|
|
.replace("6", "6")
|
|
.replace("I", "7")
|
|
.replace("P", "8")
|
|
.replace("U", "9")
|
|
.replace("M", "0");
|
|
}
|
|
|
|
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());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": {
|
|
"migrationCode": code
|
|
}
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
pub fn register_password(req: HttpRequest, body: String) -> HttpResponse {
|
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
|
let key = global::get_login(req.headers());
|
|
|
|
let user = userdata::get_acc(&key);
|
|
let code = uid_to_code(user["user"]["id"].to_string());
|
|
|
|
userdata::save_acc_transfer(&code, &body["pass"].to_string());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": []
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
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);
|
|
|
|
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
|
|
|
|
if user["success"].as_bool().unwrap() == false || uid == 0 {
|
|
let resp = object!{
|
|
"code": 2,
|
|
"server_time": global::timestamp(),
|
|
"message": ""
|
|
};
|
|
return global::send(resp);
|
|
}
|
|
|
|
let data_user = userdata::get_acc(&user["login_token"].to_string());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": {
|
|
"user_id": uid,
|
|
"uuid": format!("ecd0d830-{}-25ec5f34f7f8", user["login_token"].to_string()),
|
|
"charge": data_user["gem"]["charge"].clone(),
|
|
"free": data_user["gem"]["free"].clone()
|
|
}
|
|
};
|
|
global::send(resp)
|
|
}
|
|
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);
|
|
|
|
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
|
|
|
|
if user["success"].as_bool().unwrap() == false || uid == 0 {
|
|
let resp = object!{
|
|
"code": 2,
|
|
"server_time": global::timestamp(),
|
|
"message": ""
|
|
};
|
|
return global::send(resp);
|
|
}
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": {
|
|
"twxuid": format!("ecd0d830-{}-25ec5f34f7f8", user["login_token"].to_string())
|
|
}
|
|
};
|
|
global::send(resp)
|
|
}
|
|
pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
|
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
|
|
|
//UYWMGAMIMQQUPG67
|
|
let user = userdata::get_name_and_rank(body["user_id"].to_string().parse::<i64>().unwrap());
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": user
|
|
};
|
|
global::send(resp)
|
|
}
|
|
|
|
|
|
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
|
|
|
let key = global::get_login(req.headers());
|
|
let mut user = userdata::get_acc(&key);
|
|
let mut user2 = userdata::get_acc_home(&key);
|
|
let ur = user["card_list"][user["card_list"].len() - 1]["master_card_id"].clone();
|
|
|
|
let id = ur.as_i32().unwrap(); //todo
|
|
user["user"]["favorite_master_card_id"] = id.into();
|
|
user["user"]["guest_smile_master_card_id"] = id.into();
|
|
user["user"]["guest_cool_master_card_id"] = id.into();
|
|
user["user"]["guest_pure_master_card_id"] = id.into();
|
|
user2["home"]["preset_setting"][0]["illust_master_card_id"] = id.into();
|
|
user["gem"]["free"] = (3000).into();
|
|
user["gem"]["total"] = (3000).into();
|
|
|
|
let id = body["master_character_id"].to_string();
|
|
let userr = &id[id.len() - 2..].parse::<i32>().unwrap();
|
|
|
|
let cardstoreward: JsonValue;
|
|
let mut masterid = 3000000;
|
|
if id.starts_with("1") {
|
|
cardstoreward = array![10010001, 10020001, 10030001, 10040001, 10050001, 10060001, 10070001, 10080001, 10090001]; //muse
|
|
} else if id.starts_with("2") {
|
|
cardstoreward = array![20010001, 20020001, 20030001, 20040001, 20050001, 20060001, 20070001, 20080001, 20090001]; //aqours
|
|
masterid += 9; //muse
|
|
} else if id.starts_with("3") {
|
|
cardstoreward = array![30010001, 30020001, 30030001, 30040001, 30050001, 30060001, 30070001, 30080001, 30090001, 30100001, 30110001]; //nijigasaki
|
|
masterid += 9 + 9; //aqours
|
|
} else if id.starts_with("4") {
|
|
cardstoreward = array![40010001, 40020001, 40030001, 40040001, 40050001, 40060001, 40070001, 40080001, 40090001]; //liella
|
|
masterid += 9 + 9 + 12; //nijigasaki
|
|
} else {
|
|
return global::error_resp();
|
|
}
|
|
masterid += userr;
|
|
|
|
user["user"]["master_title_ids"][0] = masterid.into();
|
|
|
|
// User is rewarded with all base cards in the team they chose. This makes up their new deck_list
|
|
|
|
for (i, data) in cardstoreward.members().enumerate() {
|
|
global::give_character(data.to_string(), &mut user);
|
|
if i < 10 {
|
|
user["deck_list"][0]["main_card_ids"][i] = data.clone();
|
|
}
|
|
}
|
|
//todo - should the chosen character be in the team twice?
|
|
user["deck_list"][0]["main_card_ids"][4] = ur;
|
|
|
|
userdata::save_acc(&key, user.clone());
|
|
userdata::save_acc_home(&key, user2);
|
|
|
|
let resp = object!{
|
|
"code": 0,
|
|
"server_time": global::timestamp(),
|
|
"data": user["user"].clone()
|
|
};
|
|
global::send(resp)
|
|
}
|