mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 00:32:20 +08:00
Compare commits
4 Commits
95c253b65a
...
8a666a56b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a666a56b5 | ||
|
|
f4fcbf30ed | ||
|
|
db46013ee0 | ||
|
|
0b532ee191 |
@@ -199,6 +199,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
||||
"/api/webui/startLoginbonus" => webui::start_loginbonus(req, body),
|
||||
"/api/webui/import" => webui::import(req, body),
|
||||
"/api/webui/set_time" => webui::set_time(req, body),
|
||||
"/api/webui/cheat" => webui::cheat(req, body),
|
||||
_ => api_req(req, body).await
|
||||
}
|
||||
} else {
|
||||
@@ -219,6 +220,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
||||
"/api/webui/listCards" => webui::get_card_info(req),
|
||||
"/api/webui/listMusic" => webui::get_music_info(req),
|
||||
"/api/webui/listLoginBonus" => webui::list_login_bonus(req),
|
||||
"/api/webui/listItems" => webui::list_items(req),
|
||||
_ => api_req(req, body).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,55 +66,59 @@ pub fn check_for_region(user: &mut JsonValue, headers: &HeaderMap) {
|
||||
|
||||
// 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 const GIFT_LIMIT: usize = 100000;
|
||||
pub const LIMIT_ITEMS: i64 = 200000000;
|
||||
pub const LIMIT_COINS: i64 = 2000000000;
|
||||
pub const LIMIT_PRIMOGEMS: i64 = 1000000;
|
||||
|
||||
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
||||
let mut has = false;
|
||||
for dataa in user["shop_list"].members_mut() {
|
||||
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 {
|
||||
fn give(array: &mut JsonValue, shop_id: &str, master_item_id: i64, limit: i64, count_id: &str, count: i64, default_push: JsonValue) -> bool {
|
||||
for data in array.members_mut() {
|
||||
if data[shop_id].as_i64().unwrap() == master_item_id {
|
||||
if data[count_id].as_i64().unwrap() >= limit {
|
||||
return true;
|
||||
}
|
||||
dataa["count"] = new_amount.into();
|
||||
break;
|
||||
let mut new_amount = data[count_id].as_i64().unwrap() + count;
|
||||
if new_amount > limit {
|
||||
new_amount = limit;
|
||||
}
|
||||
data[count_id] = new_amount.into();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if !has {
|
||||
user["shop_list"].push(object!{
|
||||
master_shop_item_id: master_item_id,
|
||||
count: count
|
||||
}).unwrap();
|
||||
}
|
||||
array.push(default_push).unwrap();
|
||||
false
|
||||
}
|
||||
|
||||
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||
let mut has = false;
|
||||
for dataa in user["item_list"].members_mut() {
|
||||
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;
|
||||
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
||||
give(
|
||||
&mut user["shop_list"],
|
||||
"master_shop_item_id",
|
||||
master_item_id,
|
||||
LIMIT_ITEMS,
|
||||
"count",
|
||||
count,
|
||||
object!{
|
||||
master_shop_item_id: master_item_id,
|
||||
count: count
|
||||
}
|
||||
}
|
||||
if !has {
|
||||
user["item_list"].push(object!{
|
||||
)
|
||||
}
|
||||
|
||||
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||
give(
|
||||
&mut user["item_list"],
|
||||
"master_item_id",
|
||||
master_item_id,
|
||||
LIMIT_ITEMS,
|
||||
"amount",
|
||||
amount,
|
||||
object!{
|
||||
id: master_item_id,
|
||||
master_item_id: master_item_id,
|
||||
amount: amount,
|
||||
expire_date_time: null
|
||||
}).unwrap();
|
||||
}
|
||||
false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
pub fn use_item(item: &JsonValue, multiplier: i64, user: &mut JsonValue) {
|
||||
@@ -175,25 +179,18 @@ pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue, missi
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut has = false;
|
||||
for data in user["point_list"].members_mut() {
|
||||
if data["type"].as_i64().unwrap() == master_item_id {
|
||||
has = true;
|
||||
let new_amount = data["amount"].as_i64().unwrap() + amount;
|
||||
if new_amount > LIMIT_COINS {
|
||||
return true;
|
||||
}
|
||||
data["amount"] = new_amount.into();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !has {
|
||||
user["point_list"].push(object!{
|
||||
give(
|
||||
&mut user["point_list"],
|
||||
"type",
|
||||
master_item_id,
|
||||
LIMIT_COINS,
|
||||
"amount",
|
||||
amount,
|
||||
object!{
|
||||
type: master_item_id,
|
||||
amount: amount
|
||||
}).unwrap();
|
||||
}
|
||||
false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
||||
@@ -210,10 +207,13 @@ pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
||||
}
|
||||
|
||||
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 {
|
||||
if user["gem"]["free"].as_i64().unwrap() >= LIMIT_PRIMOGEMS {
|
||||
return true;
|
||||
}
|
||||
let new_amount = user["gem"]["free"].as_i64().unwrap() + amount;
|
||||
if user["gem"]["free"].as_i64().unwrap() > LIMIT_PRIMOGEMS {
|
||||
user["gem"]["free"] = LIMIT_PRIMOGEMS.into();
|
||||
}
|
||||
|
||||
user["gem"]["free"] = new_amount.into();
|
||||
false
|
||||
|
||||
@@ -454,7 +454,7 @@ pub fn webui_import_user(user: JsonValue) -> Result<JsonValue, String> {
|
||||
})
|
||||
}
|
||||
|
||||
fn webui_login_token(token: &str) -> Option<String> {
|
||||
pub fn webui_login_token(token: &str) -> Option<String> {
|
||||
let uid = DATABASE.lock_and_select("SELECT user_id FROM webui WHERE token=?1", params!(token)).unwrap_or_default();
|
||||
if uid == String::new() || token.is_empty() {
|
||||
return None;
|
||||
|
||||
@@ -5,6 +5,7 @@ use actix_web::{
|
||||
http::header::ContentType
|
||||
};
|
||||
use json::{JsonValue, object};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::include_file;
|
||||
use crate::router::{userdata, items};
|
||||
@@ -37,7 +38,6 @@ fn error(msg: &str) -> HttpResponse {
|
||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||
.insert_header(ContentType::json())
|
||||
.body(json::stringify(resp))
|
||||
|
||||
}
|
||||
|
||||
pub fn login(_req: HttpRequest, body: String) -> HttpResponse {
|
||||
@@ -324,12 +324,56 @@ pub fn get_music_info(req: HttpRequest) -> HttpResponse {
|
||||
.body(json::stringify(resp))
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref ITEM: JsonValue = json::parse(&include_file!("src/router/webui/item.json")).unwrap();
|
||||
static ref LOGIN_BONUS: JsonValue = json::parse(&include_file!("src/router/webui/login_bonus.json")).unwrap();
|
||||
}
|
||||
|
||||
pub fn list_login_bonus(_req: HttpRequest) -> HttpResponse {
|
||||
|
||||
let resp = json::parse(&include_file!("src/router/webui/login_bonus.json")).unwrap();
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::json())
|
||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||
.body(json::stringify(resp))
|
||||
.body(json::stringify(LOGIN_BONUS.clone()))
|
||||
}
|
||||
|
||||
pub fn list_items(_req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::json())
|
||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||
.body(json::stringify(ITEM.clone()))
|
||||
}
|
||||
|
||||
pub fn cheat(req: HttpRequest, _body: String) -> HttpResponse {
|
||||
let token = get_login_token(&req);
|
||||
if token.is_none() {
|
||||
return error("Not logged in");
|
||||
}
|
||||
let key = userdata::webui_login_token(&token.unwrap());
|
||||
if key.is_some() {
|
||||
return error("Not logged in");
|
||||
}
|
||||
let key = key.unwrap();
|
||||
let mut user = userdata::get_acc_home(&key);
|
||||
|
||||
for item in ITEM.entries() {
|
||||
let id = item.0.parse::<i32>().unwrap_or(0);
|
||||
let data = item.1;
|
||||
if id == 0 {
|
||||
continue;
|
||||
}
|
||||
items::gift_item_basic(id, items::LIMIT_ITEMS, data["reward_type"].as_i32().unwrap(), "You have cheated. Here are \"gifts\"", &mut user);
|
||||
}
|
||||
|
||||
userdata::save_acc_home(&key, user);
|
||||
|
||||
let resp = object!{
|
||||
result: "OK"
|
||||
};
|
||||
|
||||
HttpResponse::Ok()
|
||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||
//.insert_header(("Access-Control-Allow-Credentials", "true"))
|
||||
.insert_header(ContentType::json())
|
||||
.body(json::stringify(resp))
|
||||
|
||||
}
|
||||
|
||||
1044
src/router/webui/item.json
Normal file
1044
src/router/webui/item.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user