mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement card leveling endpoints
This commit is contained in:
parent
30be2de0e9
commit
5a2482d028
4 changed files with 135 additions and 0 deletions
12
src/main.rs
12
src/main.rs
|
@ -204,6 +204,15 @@ async fn announcement(req: HttpRequest) -> HttpResponse { router::web::announcem
|
||||||
#[get("/api/home/announcement")]
|
#[get("/api/home/announcement")]
|
||||||
async fn announcement_api(req: HttpRequest) -> HttpResponse { router::user::announcement(req) }
|
async fn announcement_api(req: HttpRequest) -> HttpResponse { router::user::announcement(req) }
|
||||||
|
|
||||||
|
#[post("/api/card/reinforce")]
|
||||||
|
async fn card_reinforce(req: HttpRequest, body: String) -> HttpResponse { router::card::reinforce(req, body) }
|
||||||
|
|
||||||
|
#[post("/api/card/skill/reinforce")]
|
||||||
|
async fn card_skill_reinforce(req: HttpRequest, body: String) -> HttpResponse { router::card::skill_reinforce(req, body) }
|
||||||
|
|
||||||
|
#[post("/api/card/evolve")]
|
||||||
|
async fn card_evolve(req: HttpRequest, body: String) -> HttpResponse { router::card::evolve(req, body) }
|
||||||
|
|
||||||
async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
|
async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
if body != String::new() {
|
if body != String::new() {
|
||||||
println!("{}", encryption::decrypt_packet(&body).unwrap());
|
println!("{}", encryption::decrypt_packet(&body).unwrap());
|
||||||
|
@ -221,6 +230,9 @@ async fn main() -> std::io::Result<()> {
|
||||||
println!("Request: {}", req.path());
|
println!("Request: {}", req.path());
|
||||||
srv.call(req)
|
srv.call(req)
|
||||||
})
|
})
|
||||||
|
.service(card_evolve)
|
||||||
|
.service(card_skill_reinforce)
|
||||||
|
.service(card_reinforce)
|
||||||
.service(announcement_api)
|
.service(announcement_api)
|
||||||
.service(announcement)
|
.service(announcement)
|
||||||
.service(sif_album)
|
.service(sif_album)
|
||||||
|
|
|
@ -18,3 +18,4 @@ pub mod debug;
|
||||||
pub mod gree;
|
pub mod gree;
|
||||||
pub mod serial_code;
|
pub mod serial_code;
|
||||||
pub mod web;
|
pub mod web;
|
||||||
|
pub mod card;
|
||||||
|
|
107
src/router/card.rs
Normal file
107
src/router/card.rs
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
use json::{object, array, JsonValue};
|
||||||
|
use crate::router::global;
|
||||||
|
use crate::encryption;
|
||||||
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
|
use crate::router::userdata;
|
||||||
|
|
||||||
|
fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_multiplier: i64, evolve: bool) -> JsonValue {
|
||||||
|
for (i, data) in user["card_list"].members().enumerate() {
|
||||||
|
if data["id"].to_string() == body["id"].to_string() {
|
||||||
|
let materials = &body["material_item_list"];
|
||||||
|
let mut card = data.clone();
|
||||||
|
let mut money: i64 = 0;
|
||||||
|
|
||||||
|
for (_j, data2) in materials.members().enumerate() {
|
||||||
|
for (_k, data3) in user["item_list"].members_mut().enumerate() {
|
||||||
|
if data3["master_item_id"].to_string() == data2["master_item_id"].to_string() {
|
||||||
|
data3["amount"] = (data3["amount"].as_i64().unwrap() - data2["amount"].as_i64().unwrap()).into();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let item = global::get_item_info(data2["master_item_id"].as_i64().unwrap());
|
||||||
|
if evolve {
|
||||||
|
card["evolve"] = array![{type: 2,count: 1}];
|
||||||
|
money = money_multiplier;
|
||||||
|
} else {
|
||||||
|
card[exp_id] = (card[exp_id].as_i64().unwrap() + (item["effectValue"].as_i64().unwrap() * data2["amount"].as_i64().unwrap())).into();
|
||||||
|
money += item["effectValue"].as_i64().unwrap() * data2["amount"].as_i64().unwrap() * money_multiplier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user["card_list"][i] = card.clone();
|
||||||
|
for (_i, data) in user["point_list"].members_mut().enumerate() {
|
||||||
|
if data["type"].as_i32().unwrap() == 1 {
|
||||||
|
data["amount"] = (data["amount"].as_i64().unwrap() - money).into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object!{};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reinforce(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
let card = do_reinforce(&mut user, &body, "exp", 1, false);
|
||||||
|
|
||||||
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
let resp = object!{
|
||||||
|
"code": 0,
|
||||||
|
"server_time": global::timestamp(),
|
||||||
|
"data": {
|
||||||
|
card: card,
|
||||||
|
item_list: user["item_list"].clone(),
|
||||||
|
point_list: user["point_list"].clone(),
|
||||||
|
clear_mission_ids: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global::send(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn skill_reinforce(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
let card = do_reinforce(&mut user, &body, "skill_exp", 10, false);
|
||||||
|
|
||||||
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
let resp = object!{
|
||||||
|
"code": 0,
|
||||||
|
"server_time": global::timestamp(),
|
||||||
|
"data": {
|
||||||
|
card: card,
|
||||||
|
item_list: user["item_list"].clone(),
|
||||||
|
point_list: user["point_list"].clone(),
|
||||||
|
clear_mission_ids: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global::send(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn evolve(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
|
let card = do_reinforce(&mut user, &body, "", 30000, true);
|
||||||
|
|
||||||
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
let resp = object!{
|
||||||
|
"code": 0,
|
||||||
|
"server_time": global::timestamp(),
|
||||||
|
"data": {
|
||||||
|
card: card,
|
||||||
|
item_list: user["item_list"].clone(),
|
||||||
|
point_list: user["point_list"].clone(),
|
||||||
|
clear_mission_ids: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global::send(resp)
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ use crate::router::gree;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
pub const ASSET_VERSION: &str = "13177023d4b7ad41ff52af4cefba5c55";
|
pub const ASSET_VERSION: &str = "13177023d4b7ad41ff52af4cefba5c55";
|
||||||
pub const ASSET_HASH_ANDROID: &str = "017ec1bcafbeea6a7714f0034b15bd0f";
|
pub const ASSET_HASH_ANDROID: &str = "017ec1bcafbeea6a7714f0034b15bd0f";
|
||||||
|
@ -17,6 +18,20 @@ pub const ASSET_VERSION_JP: &str = "4c921d2443335e574a82e04ec9ea243c";
|
||||||
pub const ASSET_HASH_ANDROID_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c";
|
pub const ASSET_HASH_ANDROID_JP: &str = "67f8f261c16b3cca63e520a25aad6c1c";
|
||||||
pub const ASSET_HASH_IOS_JP: &str = "b8975be8300013a168d061d3fdcd4a16";
|
pub const ASSET_HASH_IOS_JP: &str = "b8975be8300013a168d061d3fdcd4a16";
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref ITEM_INFO: JsonValue = {
|
||||||
|
let mut info = object!{};
|
||||||
|
let items = json::parse(include_str!("json/item.json")).unwrap();
|
||||||
|
for (_i, data) in items.members().enumerate() {
|
||||||
|
info[data["id"].to_string()] = data.clone();
|
||||||
|
}
|
||||||
|
info
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_item_info(id: i64) -> JsonValue {
|
||||||
|
ITEM_INFO[id.to_string()].clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn get_uuid(input: &str) -> Option<String> {
|
fn get_uuid(input: &str) -> Option<String> {
|
||||||
let key = "sk1bdzb310n0s9tl";
|
let key = "sk1bdzb310n0s9tl";
|
||||||
|
|
Loading…
Add table
Reference in a new issue