mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Move item related functions to their own file
This commit is contained in:
parent
8f5f32a17e
commit
ea84ffdc65
14 changed files with 323 additions and 319 deletions
|
@ -23,3 +23,4 @@ pub mod shop;
|
||||||
pub mod webui;
|
pub mod webui;
|
||||||
pub mod clear_rate;
|
pub mod clear_rate;
|
||||||
pub mod exchange;
|
pub mod exchange;
|
||||||
|
pub mod items;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use json::{object, array, JsonValue};
|
use json::{object, array, JsonValue};
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
|
|
||||||
use crate::router::userdata;
|
use crate::router::{userdata, global, items};
|
||||||
use crate::router::global;
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
|
|
||||||
fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_multiplier: i64, evolve: bool) -> JsonValue {
|
fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_multiplier: i64, evolve: bool) -> JsonValue {
|
||||||
|
@ -13,8 +12,8 @@ fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_mult
|
||||||
let mut money: i64 = 0;
|
let mut money: i64 = 0;
|
||||||
|
|
||||||
for (_j, data2) in materials.members().enumerate() {
|
for (_j, data2) in materials.members().enumerate() {
|
||||||
global::use_item(data2["master_item_id"].as_i64().unwrap(), data2["amount"].as_i64().unwrap(), user);
|
items::use_item(data2["master_item_id"].as_i64().unwrap(), data2["amount"].as_i64().unwrap(), user);
|
||||||
let item = global::get_item_info(data2["master_item_id"].as_i64().unwrap());
|
let item = items::get_item_info(data2["master_item_id"].as_i64().unwrap());
|
||||||
if evolve {
|
if evolve {
|
||||||
card["evolve"] = array![{type: 2,count: 1}];
|
card["evolve"] = array![{type: 2,count: 1}];
|
||||||
money = money_multiplier;
|
money = money_multiplier;
|
||||||
|
|
|
@ -2,8 +2,7 @@ use json::{JsonValue, object};
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::{global, userdata, items};
|
||||||
use crate::router::userdata;
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -42,7 +41,7 @@ pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let item = &EXCHANGE_LIST[body["master_exchange_item_id"].to_string()];
|
let item = &EXCHANGE_LIST[body["master_exchange_item_id"].to_string()];
|
||||||
|
|
||||||
if item["consumeType"].as_i32().unwrap() == 4 {
|
if item["consumeType"].as_i32().unwrap() == 4 {
|
||||||
global::use_item(item["value"].as_i64().unwrap(), item["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap(), &mut user);
|
items::use_item(item["value"].as_i64().unwrap(), item["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap(), &mut user);
|
||||||
} else {
|
} else {
|
||||||
println!("Unknown consume type {}", item["consumeType"]);
|
println!("Unknown consume type {}", item["consumeType"]);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,7 @@ pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let mut gift = EXCHANGE_REWARD[item["masterExchangeItemRewardId"].to_string()].clone();
|
let mut gift = EXCHANGE_REWARD[item["masterExchangeItemRewardId"].to_string()].clone();
|
||||||
gift["reward_type"] = gift["type"].clone();
|
gift["reward_type"] = gift["type"].clone();
|
||||||
gift["amount"] = (gift["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap()).into();
|
gift["amount"] = (gift["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap()).into();
|
||||||
global::give_gift(&gift, &mut user);
|
items::give_gift(&gift, &mut user);
|
||||||
|
|
||||||
userdata::save_acc(&key, user.clone());
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use json::{object, array};
|
use json::{object, array};
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
|
|
||||||
use crate::router::userdata;
|
use crate::router::{userdata, global};
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::global;
|
|
||||||
|
|
||||||
pub fn friend(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn friend(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers(), &body);
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
use json::{object, JsonValue, array};
|
use json::{array, object, JsonValue};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
http::header::{HeaderValue, HeaderMap}
|
http::header::{HeaderValue, HeaderMap}
|
||||||
};
|
};
|
||||||
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 lazy_static::lazy_static;
|
|
||||||
use rand::Rng;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::userdata;
|
use crate::router::{userdata, gree};
|
||||||
use crate::router::gree;
|
|
||||||
|
|
||||||
pub const ASSET_VERSION: &str = "cb87bc1468c8631a262ff65b2960470b";
|
pub const ASSET_VERSION: &str = "cb87bc1468c8631a262ff65b2960470b";
|
||||||
pub const ASSET_HASH_ANDROID: &str = "4715e873031ae4abc3c625e2bd8c935b";
|
pub const ASSET_HASH_ANDROID: &str = "4715e873031ae4abc3c625e2bd8c935b";
|
||||||
|
@ -21,44 +18,10 @@ 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()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_token() -> String {
|
pub fn create_token() -> String {
|
||||||
format!("{}", Uuid::now_v7())
|
format!("{}", Uuid::now_v7())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_gems(user: &mut JsonValue, amount: i64) {
|
|
||||||
let mut amount = amount;
|
|
||||||
let mut free = user["gem"]["free"].as_i64().unwrap();
|
|
||||||
let mut paid = user["gem"]["charge"].as_i64().unwrap();
|
|
||||||
|
|
||||||
free -= amount;
|
|
||||||
if free < 0 {
|
|
||||||
amount = -free;
|
|
||||||
free = 0;
|
|
||||||
}
|
|
||||||
paid -= amount;
|
|
||||||
if paid < 0 {
|
|
||||||
paid = 0;
|
|
||||||
}
|
|
||||||
user["gem"]["free"] = free.into();
|
|
||||||
user["gem"]["charge"] = paid.into();
|
|
||||||
user["gem"]["total"] = (free + paid).into();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_uuid(input: &str) -> Option<String> {
|
fn get_uuid(input: &str) -> Option<String> {
|
||||||
let key = "sk1bdzb310n0s9tl";
|
let key = "sk1bdzb310n0s9tl";
|
||||||
let key_index = match input.find(key) {
|
let key_index = match input.find(key) {
|
||||||
|
@ -98,12 +61,14 @@ pub fn timestamp() -> u64 {
|
||||||
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
||||||
return unix_timestamp.as_secs();
|
return unix_timestamp.as_secs();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timestamp_msec() -> u32 {
|
pub fn timestamp_msec() -> u32 {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
|
|
||||||
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
||||||
return unix_timestamp.subsec_nanos();
|
return unix_timestamp.subsec_nanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timestamp_since_midnight() -> u64 {
|
pub fn timestamp_since_midnight() -> u64 {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
||||||
|
@ -128,122 +93,6 @@ pub fn error_resp() -> HttpResponse {
|
||||||
send(object!{})
|
send(object!{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// true - limit reached
|
|
||||||
// false - all good
|
|
||||||
const GIFT_LIMIT: usize = 100000;
|
|
||||||
const LIMIT_ITEMS: i64 = 200000000;
|
|
||||||
const LIMIT_COINS: i64 = 2000000000;
|
|
||||||
const LIMIT_PRIMOGEMS: i64 = 1000000;
|
|
||||||
|
|
||||||
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
|
||||||
let mut has = false;
|
|
||||||
for (_j, dataa) in user["shop_list"].members_mut().enumerate() {
|
|
||||||
if dataa["master_shop_item_id"].as_i64().unwrap() == master_item_id {
|
|
||||||
has = true;
|
|
||||||
let new_amount = dataa["count"].as_i64().unwrap() + count;
|
|
||||||
if new_amount > LIMIT_ITEMS {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
dataa["count"] = new_amount.into();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
user["shop_list"].push(object!{
|
|
||||||
master_shop_item_id: master_item_id,
|
|
||||||
count: count
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
|
||||||
let mut has = false;
|
|
||||||
for (_j, dataa) in user["item_list"].members_mut().enumerate() {
|
|
||||||
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
|
||||||
has = true;
|
|
||||||
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
|
||||||
if new_amount > LIMIT_ITEMS {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
dataa["amount"] = new_amount.into();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
user["item_list"].push(object!{
|
|
||||||
id: master_item_id,
|
|
||||||
master_item_id: master_item_id,
|
|
||||||
amount: amount,
|
|
||||||
expire_date_time: null
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn give_gift(data: &JsonValue, user: &mut JsonValue) -> bool {
|
|
||||||
if data.is_empty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if data["reward_type"].to_string() == "1" {
|
|
||||||
// basically primogems!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
return !give_primogems(data["amount"].as_i64().unwrap(), user);
|
|
||||||
} else if data["reward_type"].to_string() == "2" {
|
|
||||||
//character
|
|
||||||
give_character(data["value"].to_string(), user);
|
|
||||||
return true;
|
|
||||||
} else if data["reward_type"].to_string() == "3" {
|
|
||||||
return !give_item(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user);
|
|
||||||
} else if data["reward_type"].to_string() == "4" {
|
|
||||||
// basically moraa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
return !give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user);
|
|
||||||
}
|
|
||||||
println!("Redeeming reward not implimented for reward type {}", data["reward_type"].to_string());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
|
||||||
give_gift(&object!{
|
|
||||||
reward_type: ty_pe,
|
|
||||||
amount: amount,
|
|
||||||
value: id
|
|
||||||
}, user)
|
|
||||||
}
|
|
||||||
pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
|
||||||
let mut has = false;
|
|
||||||
for (_j, dataa) in user["point_list"].members_mut().enumerate() {
|
|
||||||
if dataa["type"].as_i64().unwrap() == master_item_id {
|
|
||||||
has = true;
|
|
||||||
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
|
||||||
if new_amount > LIMIT_COINS {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
dataa["amount"] = new_amount.into();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
user["point_list"].push(object!{
|
|
||||||
type: master_item_id,
|
|
||||||
amount: amount
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn use_item(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
|
||||||
for (_j, dataa) in user["item_list"].members_mut().enumerate() {
|
|
||||||
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
|
||||||
if dataa["amount"].as_i64().unwrap() >= amount {
|
|
||||||
dataa["amount"] = (dataa["amount"].as_i64().unwrap() - amount).into();
|
|
||||||
} else {
|
|
||||||
dataa["amount"] = (0).into();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start_login_bonus(id: i64, bonus: &mut JsonValue) -> bool {
|
pub fn start_login_bonus(id: i64, bonus: &mut JsonValue) -> bool {
|
||||||
if crate::router::login::get_login_bonus_info(id).is_empty() {
|
if crate::router::login::get_login_bonus_info(id).is_empty() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -261,123 +110,6 @@ pub fn start_login_bonus(id: i64, bonus: &mut JsonValue) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn give_primogems(amount: i64, user: &mut JsonValue) -> bool {
|
|
||||||
let new_amount = user["gem"]["free"].as_i64().unwrap() + amount;
|
|
||||||
if new_amount > LIMIT_PRIMOGEMS {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
user["gem"]["free"] = new_amount.into();
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gift_item(item: &JsonValue, reason: &str, user: &mut JsonValue) -> JsonValue {
|
|
||||||
let to_push = object!{
|
|
||||||
id: item["id"].clone(),
|
|
||||||
reward_type: item["type"].clone(),
|
|
||||||
is_receive: 0,
|
|
||||||
reason_text: reason,
|
|
||||||
value: item["value"].clone(),
|
|
||||||
level: item["level"].clone(),
|
|
||||||
amount: item["amount"].clone(),
|
|
||||||
created_date_time: timestamp(),
|
|
||||||
expire_date_time: timestamp() + (5 * (24 * 60 * 60)),
|
|
||||||
received_date_time: 0
|
|
||||||
};
|
|
||||||
if user["home"]["gift_list"].len() >= GIFT_LIMIT {
|
|
||||||
return to_push;
|
|
||||||
}
|
|
||||||
user["home"]["gift_list"].push(to_push.clone()).unwrap();
|
|
||||||
return to_push;
|
|
||||||
}
|
|
||||||
fn random_number(lowest: usize, highest: usize) -> usize {
|
|
||||||
if lowest == highest {
|
|
||||||
return lowest;
|
|
||||||
}
|
|
||||||
assert!(lowest < highest);
|
|
||||||
|
|
||||||
rand::thread_rng().gen_range(lowest..highest + 1)
|
|
||||||
}
|
|
||||||
pub fn gift_item_basic(id: i32, value: i64, ty_pe: i32, reason: &str, user: &mut JsonValue) -> JsonValue {
|
|
||||||
gift_item(&object!{
|
|
||||||
id: random_number(0, timestamp_msec() as usize),
|
|
||||||
type: ty_pe,
|
|
||||||
level: 0,
|
|
||||||
amount: value,
|
|
||||||
value: id
|
|
||||||
}, reason, user)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) {
|
|
||||||
let max = get_user_rank_data(user["user"]["exp"].as_i64().unwrap())["maxLp"].as_u64().unwrap();
|
|
||||||
|
|
||||||
let speed = 285; //4 mins, 45 sec
|
|
||||||
let since_last = timestamp() - user["stamina"]["last_updated_time"].as_u64().unwrap();
|
|
||||||
|
|
||||||
let diff = since_last % speed;
|
|
||||||
let restored = (since_last - diff) / speed;
|
|
||||||
user["stamina"]["last_updated_time"] = (timestamp() - diff).into();
|
|
||||||
|
|
||||||
let mut stamina = user["stamina"]["stamina"].as_u64().unwrap();
|
|
||||||
if stamina < max {
|
|
||||||
stamina += restored;
|
|
||||||
if stamina > max {
|
|
||||||
stamina = max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if remove {
|
|
||||||
stamina -= change_amount;
|
|
||||||
} else {
|
|
||||||
stamina += change_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
user["stamina"]["stamina"] = stamina.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
// true - added
|
|
||||||
// false - already has
|
|
||||||
pub fn give_character(id: String, user: &mut JsonValue) -> bool {
|
|
||||||
for (_i, data) in user["card_list"].members().enumerate() {
|
|
||||||
if data["master_card_id"].to_string() == id || data["id"].to_string() == id {
|
|
||||||
give_item(19100001, 50, user);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let to_push = object!{
|
|
||||||
"id": id.parse::<i32>().unwrap(),
|
|
||||||
"master_card_id": id.parse::<i32>().unwrap(),
|
|
||||||
"exp": 0,
|
|
||||||
"skill_exp": 0,
|
|
||||||
"evolve": [],
|
|
||||||
"created_date_time": timestamp()
|
|
||||||
};
|
|
||||||
user["card_list"].push(to_push.clone()).unwrap();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_user_rank_data(exp: i64) -> JsonValue {
|
|
||||||
let ranks = json::parse(include_str!("userdata/user_rank.json")).unwrap();
|
|
||||||
|
|
||||||
for (i, rank) in ranks.members().enumerate() {
|
|
||||||
if exp < rank["exp"].as_i64().unwrap() {
|
|
||||||
return ranks[i - 1].clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ranks[ranks.len() - 1].clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn give_exp(amount: i32, user: &mut JsonValue) {
|
|
||||||
let current_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
|
||||||
user["user"]["exp"] = (user["user"]["exp"].as_i32().unwrap() + amount).into();
|
|
||||||
let new_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
|
||||||
if current_rank["rank"].to_string() != new_rank["rank"].to_string() {
|
|
||||||
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i64().unwrap() + new_rank["maxLp"].as_i64().unwrap()).into();
|
|
||||||
user["stamina"]["last_updated_time"] = timestamp().into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_card(id: i64, user: &JsonValue) -> JsonValue {
|
pub fn get_card(id: i64, user: &JsonValue) -> JsonValue {
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
return object!{};
|
return object!{};
|
||||||
|
@ -390,6 +122,7 @@ pub fn get_card(id: i64, user: &JsonValue) -> JsonValue {
|
||||||
}
|
}
|
||||||
return object!{};
|
return object!{};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cards(arr: JsonValue, user: &JsonValue) -> JsonValue {
|
fn get_cards(arr: JsonValue, user: &JsonValue) -> JsonValue {
|
||||||
let mut rv = array![];
|
let mut rv = array![];
|
||||||
for (_i, data) in arr.members().enumerate() {
|
for (_i, data) in arr.members().enumerate() {
|
||||||
|
@ -401,6 +134,7 @@ fn get_cards(arr: JsonValue, user: &JsonValue) -> JsonValue {
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_clear_count(user: &JsonValue, level: i32) -> i64 {
|
fn get_clear_count(user: &JsonValue, level: i32) -> i64 {
|
||||||
let mut rv = 0;
|
let mut rv = 0;
|
||||||
for (_i, current) in user["live_list"].members().enumerate() {
|
for (_i, current) in user["live_list"].members().enumerate() {
|
||||||
|
@ -410,6 +144,7 @@ fn get_clear_count(user: &JsonValue, level: i32) -> i64 {
|
||||||
}
|
}
|
||||||
rv
|
rv
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_full_combo_count(user: &JsonValue, level: i32) -> i64 {
|
fn get_full_combo_count(user: &JsonValue, level: i32) -> i64 {
|
||||||
let mut rv = 0;
|
let mut rv = 0;
|
||||||
for (_i, current) in user["live_mission_list"].members().enumerate() {
|
for (_i, current) in user["live_mission_list"].members().enumerate() {
|
||||||
|
|
273
src/router/items.rs
Normal file
273
src/router/items.rs
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
use json::{object, JsonValue};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use crate::router::global;
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_gems(user: &mut JsonValue, amount: i64) {
|
||||||
|
let mut amount = amount;
|
||||||
|
let mut free = user["gem"]["free"].as_i64().unwrap();
|
||||||
|
let mut paid = user["gem"]["charge"].as_i64().unwrap();
|
||||||
|
|
||||||
|
free -= amount;
|
||||||
|
if free < 0 {
|
||||||
|
amount = -free;
|
||||||
|
free = 0;
|
||||||
|
}
|
||||||
|
paid -= amount;
|
||||||
|
if paid < 0 {
|
||||||
|
paid = 0;
|
||||||
|
}
|
||||||
|
user["gem"]["free"] = free.into();
|
||||||
|
user["gem"]["charge"] = paid.into();
|
||||||
|
user["gem"]["total"] = (free + paid).into();
|
||||||
|
}
|
||||||
|
|
||||||
|
// true - limit reached
|
||||||
|
// false - all good
|
||||||
|
const GIFT_LIMIT: usize = 100000;
|
||||||
|
const LIMIT_ITEMS: i64 = 200000000;
|
||||||
|
const LIMIT_COINS: i64 = 2000000000;
|
||||||
|
const LIMIT_PRIMOGEMS: i64 = 1000000;
|
||||||
|
|
||||||
|
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
||||||
|
let mut has = false;
|
||||||
|
for (_j, dataa) in user["shop_list"].members_mut().enumerate() {
|
||||||
|
if dataa["master_shop_item_id"].as_i64().unwrap() == master_item_id {
|
||||||
|
has = true;
|
||||||
|
let new_amount = dataa["count"].as_i64().unwrap() + count;
|
||||||
|
if new_amount > LIMIT_ITEMS {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
dataa["count"] = new_amount.into();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
user["shop_list"].push(object!{
|
||||||
|
master_shop_item_id: master_item_id,
|
||||||
|
count: count
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||||
|
let mut has = false;
|
||||||
|
for (_j, dataa) in user["item_list"].members_mut().enumerate() {
|
||||||
|
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
||||||
|
has = true;
|
||||||
|
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
||||||
|
if new_amount > LIMIT_ITEMS {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
dataa["amount"] = new_amount.into();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
user["item_list"].push(object!{
|
||||||
|
id: master_item_id,
|
||||||
|
master_item_id: master_item_id,
|
||||||
|
amount: amount,
|
||||||
|
expire_date_time: null
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn give_gift(data: &JsonValue, user: &mut JsonValue) -> bool {
|
||||||
|
if data.is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if data["reward_type"].to_string() == "1" {
|
||||||
|
// basically primogems!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
return !give_primogems(data["amount"].as_i64().unwrap(), user);
|
||||||
|
} else if data["reward_type"].to_string() == "2" {
|
||||||
|
//character
|
||||||
|
give_character(data["value"].to_string(), user);
|
||||||
|
return true;
|
||||||
|
} else if data["reward_type"].to_string() == "3" {
|
||||||
|
return !give_item(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user);
|
||||||
|
} else if data["reward_type"].to_string() == "4" {
|
||||||
|
// basically moraa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
return !give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user);
|
||||||
|
}
|
||||||
|
println!("Redeeming reward not implimented for reward type {}", data["reward_type"].to_string());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||||
|
give_gift(&object!{
|
||||||
|
reward_type: ty_pe,
|
||||||
|
amount: amount,
|
||||||
|
value: id
|
||||||
|
}, user)
|
||||||
|
}
|
||||||
|
pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||||
|
let mut has = false;
|
||||||
|
for (_j, dataa) in user["point_list"].members_mut().enumerate() {
|
||||||
|
if dataa["type"].as_i64().unwrap() == master_item_id {
|
||||||
|
has = true;
|
||||||
|
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
||||||
|
if new_amount > LIMIT_COINS {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
dataa["amount"] = new_amount.into();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
user["point_list"].push(object!{
|
||||||
|
type: master_item_id,
|
||||||
|
amount: amount
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn use_item(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
||||||
|
for (_j, dataa) in user["item_list"].members_mut().enumerate() {
|
||||||
|
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
||||||
|
if dataa["amount"].as_i64().unwrap() >= amount {
|
||||||
|
dataa["amount"] = (dataa["amount"].as_i64().unwrap() - amount).into();
|
||||||
|
} else {
|
||||||
|
dataa["amount"] = (0).into();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn give_primogems(amount: i64, user: &mut JsonValue) -> bool {
|
||||||
|
let new_amount = user["gem"]["free"].as_i64().unwrap() + amount;
|
||||||
|
if new_amount > LIMIT_PRIMOGEMS {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
user["gem"]["free"] = new_amount.into();
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gift_item(item: &JsonValue, reason: &str, user: &mut JsonValue) -> JsonValue {
|
||||||
|
let to_push = object!{
|
||||||
|
id: item["id"].clone(),
|
||||||
|
reward_type: item["type"].clone(),
|
||||||
|
is_receive: 0,
|
||||||
|
reason_text: reason,
|
||||||
|
value: item["value"].clone(),
|
||||||
|
level: item["level"].clone(),
|
||||||
|
amount: item["amount"].clone(),
|
||||||
|
created_date_time: global::timestamp(),
|
||||||
|
expire_date_time: global::timestamp() + (5 * (24 * 60 * 60)),
|
||||||
|
received_date_time: 0
|
||||||
|
};
|
||||||
|
if user["home"]["gift_list"].len() >= GIFT_LIMIT {
|
||||||
|
return to_push;
|
||||||
|
}
|
||||||
|
user["home"]["gift_list"].push(to_push.clone()).unwrap();
|
||||||
|
return to_push;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_number(lowest: usize, highest: usize) -> usize {
|
||||||
|
if lowest == highest {
|
||||||
|
return lowest;
|
||||||
|
}
|
||||||
|
assert!(lowest < highest);
|
||||||
|
|
||||||
|
rand::thread_rng().gen_range(lowest..highest + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gift_item_basic(id: i32, value: i64, ty_pe: i32, reason: &str, user: &mut JsonValue) -> JsonValue {
|
||||||
|
gift_item(&object!{
|
||||||
|
id: random_number(0, global::timestamp_msec() as usize),
|
||||||
|
type: ty_pe,
|
||||||
|
level: 0,
|
||||||
|
amount: value,
|
||||||
|
value: id
|
||||||
|
}, reason, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) {
|
||||||
|
let max = get_user_rank_data(user["user"]["exp"].as_i64().unwrap())["maxLp"].as_u64().unwrap();
|
||||||
|
|
||||||
|
let speed = 285; //4 mins, 45 sec
|
||||||
|
let since_last = global::timestamp() - user["stamina"]["last_updated_time"].as_u64().unwrap();
|
||||||
|
|
||||||
|
let diff = since_last % speed;
|
||||||
|
let restored = (since_last - diff) / speed;
|
||||||
|
user["stamina"]["last_updated_time"] = (global::timestamp() - diff).into();
|
||||||
|
|
||||||
|
let mut stamina = user["stamina"]["stamina"].as_u64().unwrap();
|
||||||
|
if stamina < max {
|
||||||
|
stamina += restored;
|
||||||
|
if stamina > max {
|
||||||
|
stamina = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if remove {
|
||||||
|
stamina -= change_amount;
|
||||||
|
} else {
|
||||||
|
stamina += change_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
user["stamina"]["stamina"] = stamina.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
// true - added
|
||||||
|
// false - already has
|
||||||
|
pub fn give_character(id: String, user: &mut JsonValue) -> bool {
|
||||||
|
for (_i, data) in user["card_list"].members().enumerate() {
|
||||||
|
if data["master_card_id"].to_string() == id || data["id"].to_string() == id {
|
||||||
|
give_item(19100001, 50, user);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let to_push = object!{
|
||||||
|
"id": id.parse::<i32>().unwrap(),
|
||||||
|
"master_card_id": id.parse::<i32>().unwrap(),
|
||||||
|
"exp": 0,
|
||||||
|
"skill_exp": 0,
|
||||||
|
"evolve": [],
|
||||||
|
"created_date_time": global::timestamp()
|
||||||
|
};
|
||||||
|
user["card_list"].push(to_push.clone()).unwrap();
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_user_rank_data(exp: i64) -> JsonValue {
|
||||||
|
let ranks = json::parse(include_str!("userdata/user_rank.json")).unwrap();
|
||||||
|
|
||||||
|
for (i, rank) in ranks.members().enumerate() {
|
||||||
|
if exp < rank["exp"].as_i64().unwrap() {
|
||||||
|
return ranks[i - 1].clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ranks[ranks.len() - 1].clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn give_exp(amount: i32, user: &mut JsonValue) {
|
||||||
|
let current_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
||||||
|
user["user"]["exp"] = (user["user"]["exp"].as_i32().unwrap() + amount).into();
|
||||||
|
let new_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
||||||
|
if current_rank["rank"].to_string() != new_rank["rank"].to_string() {
|
||||||
|
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i64().unwrap() + new_rank["maxLp"].as_i64().unwrap()).into();
|
||||||
|
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,9 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::{global, userdata, items};
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::clear_rate::live_completed;
|
use crate::router::clear_rate::live_completed;
|
||||||
use crate::router::userdata;
|
|
||||||
|
|
||||||
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();
|
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||||
|
@ -193,7 +192,7 @@ pub fn continuee(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers(), &body);
|
let key = global::get_login(req.headers(), &body);
|
||||||
let mut user = userdata::get_acc(&key);
|
let mut user = userdata::get_acc(&key);
|
||||||
|
|
||||||
global::remove_gems(&mut user, 100);
|
items::remove_gems(&mut user, 100);
|
||||||
|
|
||||||
userdata::save_acc(&key, user.clone());
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
@ -364,12 +363,12 @@ fn give_mission_rewards(user: &mut JsonValue, missions: &JsonValue, multiplier:
|
||||||
let mut gift = get_live_mission_info(data["masterLiveMissionRewardId"].as_i64().unwrap());
|
let mut gift = get_live_mission_info(data["masterLiveMissionRewardId"].as_i64().unwrap());
|
||||||
gift["reward_type"] = gift["type"].clone();
|
gift["reward_type"] = gift["type"].clone();
|
||||||
gift["amount"] = (gift["amount"].as_i64().unwrap() * multiplier).into();
|
gift["amount"] = (gift["amount"].as_i64().unwrap() * multiplier).into();
|
||||||
global::give_gift(&gift, user);
|
items::give_gift(&gift, user);
|
||||||
}
|
}
|
||||||
if global::give_gift_basic(3, 16005001, 10 * multiplier, user) {
|
if items::give_gift_basic(3, 16005001, 10 * multiplier, user) {
|
||||||
rv.push(object!{"type":3,"value":16005001,"level":0,"amount":10}).unwrap();
|
rv.push(object!{"type":3,"value":16005001,"level":0,"amount":10}).unwrap();
|
||||||
}
|
}
|
||||||
if global::give_gift_basic(3, 17001001, 2 * multiplier, user) {
|
if items::give_gift_basic(3, 17001001, 2 * multiplier, user) {
|
||||||
rv.push(object!{"type":3,"value":17001001,"level":0,"amount":2}).unwrap();
|
rv.push(object!{"type":3,"value":17001001,"level":0,"amount":2}).unwrap();
|
||||||
}
|
}
|
||||||
rv
|
rv
|
||||||
|
@ -395,9 +394,9 @@ pub fn end(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
let reward_list = give_mission_rewards(&mut user, &missions, 1);
|
let reward_list = give_mission_rewards(&mut user, &missions, 1);
|
||||||
|
|
||||||
global::lp_modification(&mut user, body["use_lp"].as_u64().unwrap(), true);
|
items::lp_modification(&mut user, body["use_lp"].as_u64().unwrap(), true);
|
||||||
|
|
||||||
global::give_exp(body["use_lp"].as_i32().unwrap(), &mut user);
|
items::give_exp(body["use_lp"].as_i32().unwrap(), &mut user);
|
||||||
|
|
||||||
userdata::save_acc(&key, user.clone());
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
@ -449,11 +448,11 @@ pub fn skip(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
let reward_list = give_mission_rewards(&mut user, &missions, body["live_boost"].as_i64().unwrap());
|
let reward_list = give_mission_rewards(&mut user, &missions, body["live_boost"].as_i64().unwrap());
|
||||||
|
|
||||||
global::lp_modification(&mut user, 10 * body["live_boost"].as_u64().unwrap(), true);
|
items::lp_modification(&mut user, 10 * body["live_boost"].as_u64().unwrap(), true);
|
||||||
|
|
||||||
global::give_exp(10 * body["live_boost"].as_i32().unwrap(), &mut user);
|
items::give_exp(10 * body["live_boost"].as_i32().unwrap(), &mut user);
|
||||||
|
|
||||||
global::use_item(21000001, body["live_boost"].as_i64().unwrap(), &mut user);
|
items::use_item(21000001, body["live_boost"].as_i64().unwrap(), &mut user);
|
||||||
|
|
||||||
userdata::save_acc(&key, user.clone());
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
use crate::router::items;
|
||||||
|
|
||||||
pub fn dummy(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn dummy(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers(), &body);
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
@ -76,7 +77,7 @@ pub fn bonus(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
let item_id = crate::router::user::get_info_from_id(info["days"][current]["masterLoginBonusRewardId"].as_i64().unwrap());
|
let item_id = crate::router::user::get_info_from_id(info["days"][current]["masterLoginBonusRewardId"].as_i64().unwrap());
|
||||||
|
|
||||||
global::gift_item(&item_id, &format!("Login bonus day {}!", current+1), &mut user_home);
|
items::gift_item(&item_id, &format!("Login bonus day {}!", current+1), &mut user_home);
|
||||||
data["day_counts"].push(current + 1).unwrap();
|
data["day_counts"].push(current + 1).unwrap();
|
||||||
}
|
}
|
||||||
for (i, data) in to_rm.members().enumerate() {
|
for (i, data) in to_rm.members().enumerate() {
|
||||||
|
|
|
@ -3,9 +3,8 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::{global, userdata, items};
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::userdata;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CARDS: JsonValue = {
|
static ref CARDS: JsonValue = {
|
||||||
|
@ -172,9 +171,9 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let price = PRICE[lottery_id.to_string()][body["master_lottery_price_number"].to_string()].clone();
|
let price = PRICE[lottery_id.to_string()][body["master_lottery_price_number"].to_string()].clone();
|
||||||
|
|
||||||
if price["consumeType"].as_i32().unwrap() == 1 {
|
if price["consumeType"].as_i32().unwrap() == 1 {
|
||||||
global::remove_gems(&mut user, price["price"].as_i64().unwrap());
|
items::remove_gems(&mut user, price["price"].as_i64().unwrap());
|
||||||
} else if price["consumeType"].as_i32().unwrap() == 4 {
|
} else if price["consumeType"].as_i32().unwrap() == 4 {
|
||||||
global::use_item(price["masterItemId"].as_i64().unwrap(), price["price"].as_i64().unwrap(), &mut user);
|
items::use_item(price["masterItemId"].as_i64().unwrap(), price["price"].as_i64().unwrap(), &mut user);
|
||||||
}
|
}
|
||||||
|
|
||||||
cardstogive = get_random_cards(lottery_id, price["count"].as_usize().unwrap());
|
cardstogive = get_random_cards(lottery_id, price["count"].as_usize().unwrap());
|
||||||
|
@ -188,7 +187,7 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
if lottery_type == 1 {
|
if lottery_type == 1 {
|
||||||
for (_i, data) in cardstogive.members().enumerate() {
|
for (_i, data) in cardstogive.members().enumerate() {
|
||||||
let mut is_new = true;
|
let mut is_new = true;
|
||||||
if !global::give_character(data["master_card_id"].to_string(), &mut user) {
|
if !items::give_character(data["master_card_id"].to_string(), &mut user) {
|
||||||
is_new = false;
|
is_new = false;
|
||||||
}
|
}
|
||||||
if is_new {
|
if is_new {
|
||||||
|
@ -213,11 +212,11 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
}
|
}
|
||||||
lottery_list.push(to_push).unwrap();
|
lottery_list.push(to_push).unwrap();
|
||||||
}
|
}
|
||||||
global::give_gift_basic(3, 15540034, 10, &mut user);
|
items::give_gift_basic(3, 15540034, 10, &mut user);
|
||||||
} else if lottery_type == 2 {
|
} else if lottery_type == 2 {
|
||||||
for (_i, data) in cardstogive.members().enumerate() {
|
for (_i, data) in cardstogive.members().enumerate() {
|
||||||
let info = get_card(data["master_lottery_item_id"].to_string(), data["master_lottery_item_number"].to_string());
|
let info = get_card(data["master_lottery_item_id"].to_string(), data["master_lottery_item_number"].to_string());
|
||||||
global::give_gift_basic(info["type"].as_i32().unwrap(), info["value"].as_i64().unwrap(), info["amount"].as_i64().unwrap(), &mut user);
|
items::give_gift_basic(info["type"].as_i32().unwrap(), info["value"].as_i64().unwrap(), info["amount"].as_i64().unwrap(), &mut user);
|
||||||
let to_push = object!{
|
let to_push = object!{
|
||||||
"master_lottery_item_id": data["master_lottery_item_id"].clone(),
|
"master_lottery_item_id": data["master_lottery_item_id"].clone(),
|
||||||
"master_lottery_item_number": data["master_lottery_item_number"].clone(),
|
"master_lottery_item_number": data["master_lottery_item_number"].clone(),
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use json::object;
|
use json::object;
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::{global, userdata, items};
|
||||||
use crate::router::userdata;
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
|
|
||||||
pub fn events(_req: HttpRequest) -> HttpResponse {
|
pub fn events(_req: HttpRequest) -> HttpResponse {
|
||||||
|
@ -23,13 +22,13 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
if body["input_code"].to_string() == "SIF2REVIVALREAL!" {
|
if body["input_code"].to_string() == "SIF2REVIVALREAL!" {
|
||||||
item = global::gift_item_basic(1, 100000, 4, "Another game died... This makes me sad :(", &mut user);
|
item = items::gift_item_basic(1, 100000, 4, "Another game died... This makes me sad :(", &mut user);
|
||||||
} else if body["input_code"].to_string() == "pweasegivegems11" {
|
} else if body["input_code"].to_string() == "pweasegivegems11" {
|
||||||
item = global::gift_item_basic(1, 6000, 1, "Only because you asked...", &mut user);
|
item = items::gift_item_basic(1, 6000, 1, "Only because you asked...", &mut user);
|
||||||
} else if body["input_code"].to_string() == "sleepysleepyslep" {
|
} else if body["input_code"].to_string() == "sleepysleepyslep" {
|
||||||
item = global::gift_item_basic(15540001, 50, 3, "I am tired", &mut user);
|
item = items::gift_item_basic(15540001, 50, 3, "I am tired", &mut user);
|
||||||
} else if body["input_code"].to_string() == "ilikeganyu!!!!!!" {
|
} else if body["input_code"].to_string() == "ilikeganyu!!!!!!" {
|
||||||
item = global::gift_item_basic(16005003, 100, 3, "I need more primogems", &mut user);
|
item = items::gift_item_basic(16005003, 100, 3, "I need more primogems", &mut user);
|
||||||
} else {
|
} else {
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use json::{object, JsonValue};
|
||||||
use actix_web::{HttpResponse, HttpRequest};
|
use actix_web::{HttpResponse, HttpRequest};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::router::{userdata, global};
|
use crate::router::{userdata, global, items};
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -42,9 +42,9 @@ pub fn buy(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
let item = get_item_info(body["master_shop_item_id"].as_i64().unwrap());
|
let item = get_item_info(body["master_shop_item_id"].as_i64().unwrap());
|
||||||
|
|
||||||
global::remove_gems(&mut user, item["price"].as_i64().unwrap());
|
items::remove_gems(&mut user, item["price"].as_i64().unwrap());
|
||||||
global::give_shop(item["masterShopRewardId"].as_i64().unwrap(), item["price"].as_i64().unwrap(), &mut user);
|
items::give_shop(item["masterShopRewardId"].as_i64().unwrap(), item["price"].as_i64().unwrap(), &mut user);
|
||||||
global::lp_modification(&mut user, item["price"].as_u64().unwrap() / 2, false);
|
items::lp_modification(&mut user, item["price"].as_u64().unwrap() / 2, false);
|
||||||
|
|
||||||
userdata::save_acc(&key, user.clone());
|
userdata::save_acc(&key, user.clone());
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::{HttpResponse, HttpRequest};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::encryption;
|
use crate::encryption;
|
||||||
use crate::router::{userdata, global};
|
use crate::router::{userdata, global, items};
|
||||||
|
|
||||||
pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
pub fn deck(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
let key = global::get_login(req.headers(), &body);
|
let key = global::get_login(req.headers(), &body);
|
||||||
|
@ -78,7 +78,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
if data["id"].to_string() != gift_id.to_string() {
|
if data["id"].to_string() != gift_id.to_string() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !global::give_gift(&data, &mut userr) {
|
if !items::give_gift(&data, &mut userr) {
|
||||||
failed.push(gift_id.clone()).unwrap();
|
failed.push(gift_id.clone()).unwrap();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
// User is rewarded with all base cards in the team they chose. This makes up their new deck_list
|
// 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() {
|
for (i, data) in cardstoreward.members().enumerate() {
|
||||||
global::give_character(data.to_string(), &mut user);
|
items::give_character(data.to_string(), &mut user);
|
||||||
if i < 10 {
|
if i < 10 {
|
||||||
user["deck_list"][0]["main_card_ids"][i] = data.clone();
|
user["deck_list"][0]["main_card_ids"][i] = data.clone();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use sha2::{Digest, Sha256};
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
|
use crate::router::items;
|
||||||
use crate::sql::SQLite;
|
use crate::sql::SQLite;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -152,7 +153,7 @@ pub fn get_acc(auth_key: &str) -> JsonValue {
|
||||||
let mut user = get_data(auth_key, "userdata");
|
let mut user = get_data(auth_key, "userdata");
|
||||||
cleanup_account(&mut user);
|
cleanup_account(&mut user);
|
||||||
|
|
||||||
global::lp_modification(&mut user, 0, false);
|
items::lp_modification(&mut user, 0, false);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +280,7 @@ pub fn get_name_and_rank(uid: i64) -> JsonValue {
|
||||||
|
|
||||||
return object!{
|
return object!{
|
||||||
user_name: data["user"]["name"].clone(),
|
user_name: data["user"]["name"].clone(),
|
||||||
user_rank: global::get_user_rank_data(data["user"]["exp"].as_i64().unwrap())["rank"].clone() //todo
|
user_rank: items::get_user_rank_data(data["user"]["exp"].as_i64().unwrap())["rank"].clone() //todo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ use actix_web::{
|
||||||
};
|
};
|
||||||
use json::object;
|
use json::object;
|
||||||
|
|
||||||
use crate::router::userdata;
|
use crate::router::{userdata, items};
|
||||||
use crate::router::global;
|
|
||||||
|
|
||||||
fn get_login_token(req: &HttpRequest) -> Option<String> {
|
fn get_login_token(req: &HttpRequest) -> Option<String> {
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
|
@ -78,7 +77,7 @@ pub fn user(req: HttpRequest) -> HttpResponse {
|
||||||
}
|
}
|
||||||
let mut data = data.unwrap();
|
let mut data = data.unwrap();
|
||||||
|
|
||||||
data["userdata"]["user"]["rank"] = global::get_user_rank_data(data["userdata"]["user"]["exp"].as_i64().unwrap())["rank"].clone();
|
data["userdata"]["user"]["rank"] = items::get_user_rank_data(data["userdata"]["user"]["exp"].as_i64().unwrap())["rank"].clone();
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
result: "OK",
|
result: "OK",
|
||||||
|
|
Loading…
Add table
Reference in a new issue