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/startLoginbonus" => webui::start_loginbonus(req, body),
|
||||||
"/api/webui/import" => webui::import(req, body),
|
"/api/webui/import" => webui::import(req, body),
|
||||||
"/api/webui/set_time" => webui::set_time(req, body),
|
"/api/webui/set_time" => webui::set_time(req, body),
|
||||||
|
"/api/webui/cheat" => webui::cheat(req, body),
|
||||||
_ => api_req(req, body).await
|
_ => api_req(req, body).await
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -219,6 +220,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
"/api/webui/listCards" => webui::get_card_info(req),
|
"/api/webui/listCards" => webui::get_card_info(req),
|
||||||
"/api/webui/listMusic" => webui::get_music_info(req),
|
"/api/webui/listMusic" => webui::get_music_info(req),
|
||||||
"/api/webui/listLoginBonus" => webui::list_login_bonus(req),
|
"/api/webui/listLoginBonus" => webui::list_login_bonus(req),
|
||||||
|
"/api/webui/listItems" => webui::list_items(req),
|
||||||
_ => api_req(req, body).await
|
_ => api_req(req, body).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,55 +66,59 @@ pub fn check_for_region(user: &mut JsonValue, headers: &HeaderMap) {
|
|||||||
|
|
||||||
// true - limit reached
|
// true - limit reached
|
||||||
// false - all good
|
// false - all good
|
||||||
const GIFT_LIMIT: usize = 100000;
|
pub const GIFT_LIMIT: usize = 100000;
|
||||||
const LIMIT_ITEMS: i64 = 200000000;
|
pub const LIMIT_ITEMS: i64 = 200000000;
|
||||||
const LIMIT_COINS: i64 = 2000000000;
|
pub const LIMIT_COINS: i64 = 2000000000;
|
||||||
const LIMIT_PRIMOGEMS: i64 = 1000000;
|
pub const LIMIT_PRIMOGEMS: i64 = 1000000;
|
||||||
|
|
||||||
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
fn give(array: &mut JsonValue, shop_id: &str, master_item_id: i64, limit: i64, count_id: &str, count: i64, default_push: JsonValue) -> bool {
|
||||||
let mut has = false;
|
for data in array.members_mut() {
|
||||||
for dataa in user["shop_list"].members_mut() {
|
if data[shop_id].as_i64().unwrap() == master_item_id {
|
||||||
if dataa["master_shop_item_id"].as_i64().unwrap() == master_item_id {
|
if data[count_id].as_i64().unwrap() >= limit {
|
||||||
has = true;
|
|
||||||
let new_amount = dataa["count"].as_i64().unwrap() + count;
|
|
||||||
if new_amount > LIMIT_ITEMS {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
dataa["count"] = new_amount.into();
|
let mut new_amount = data[count_id].as_i64().unwrap() + count;
|
||||||
break;
|
if new_amount > limit {
|
||||||
|
new_amount = limit;
|
||||||
|
}
|
||||||
|
data[count_id] = new_amount.into();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !has {
|
array.push(default_push).unwrap();
|
||||||
user["shop_list"].push(object!{
|
|
||||||
master_shop_item_id: master_item_id,
|
|
||||||
count: count
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
||||||
let mut has = false;
|
give(
|
||||||
for dataa in user["item_list"].members_mut() {
|
&mut user["shop_list"],
|
||||||
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
"master_shop_item_id",
|
||||||
has = true;
|
master_item_id,
|
||||||
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
LIMIT_ITEMS,
|
||||||
if new_amount > LIMIT_ITEMS {
|
"count",
|
||||||
return true;
|
count,
|
||||||
}
|
object!{
|
||||||
dataa["amount"] = new_amount.into();
|
master_shop_item_id: master_item_id,
|
||||||
break;
|
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,
|
id: master_item_id,
|
||||||
master_item_id: master_item_id,
|
master_item_id: master_item_id,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
expire_date_time: null
|
expire_date_time: null
|
||||||
}).unwrap();
|
}
|
||||||
}
|
)
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_item(item: &JsonValue, multiplier: i64, user: &mut JsonValue) {
|
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;
|
give(
|
||||||
for data in user["point_list"].members_mut() {
|
&mut user["point_list"],
|
||||||
if data["type"].as_i64().unwrap() == master_item_id {
|
"type",
|
||||||
has = true;
|
master_item_id,
|
||||||
let new_amount = data["amount"].as_i64().unwrap() + amount;
|
LIMIT_COINS,
|
||||||
if new_amount > LIMIT_COINS {
|
"amount",
|
||||||
return true;
|
amount,
|
||||||
}
|
object!{
|
||||||
data["amount"] = new_amount.into();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
user["point_list"].push(object!{
|
|
||||||
type: master_item_id,
|
type: master_item_id,
|
||||||
amount: amount
|
amount: amount
|
||||||
}).unwrap();
|
}
|
||||||
}
|
)
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
||||||
@@ -210,11 +207,14 @@ pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn give_primogems(amount: i64, user: &mut JsonValue) -> bool {
|
pub fn give_primogems(amount: i64, user: &mut JsonValue) -> bool {
|
||||||
let new_amount = user["gem"]["free"].as_i64().unwrap() + amount;
|
if user["gem"]["free"].as_i64().unwrap() >= LIMIT_PRIMOGEMS {
|
||||||
if new_amount > LIMIT_PRIMOGEMS {
|
|
||||||
return true;
|
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();
|
user["gem"]["free"] = new_amount.into();
|
||||||
false
|
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();
|
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() {
|
if uid == String::new() || token.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use actix_web::{
|
|||||||
http::header::ContentType
|
http::header::ContentType
|
||||||
};
|
};
|
||||||
use json::{JsonValue, object};
|
use json::{JsonValue, object};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use crate::include_file;
|
use crate::include_file;
|
||||||
use crate::router::{userdata, items};
|
use crate::router::{userdata, items};
|
||||||
@@ -37,7 +38,6 @@ fn error(msg: &str) -> HttpResponse {
|
|||||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn login(_req: HttpRequest, body: String) -> HttpResponse {
|
pub fn login(_req: HttpRequest, body: String) -> HttpResponse {
|
||||||
@@ -324,12 +324,56 @@ pub fn get_music_info(req: HttpRequest) -> HttpResponse {
|
|||||||
.body(json::stringify(resp))
|
.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 {
|
pub fn list_login_bonus(_req: HttpRequest) -> HttpResponse {
|
||||||
|
|
||||||
let resp = json::parse(&include_file!("src/router/webui/login_bonus.json")).unwrap();
|
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type(ContentType::json())
|
.content_type(ContentType::json())
|
||||||
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
//.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