Add endpoint to cheat

This commit is contained in:
Ethan O'Brien
2026-02-06 14:39:49 -06:00
parent f4fcbf30ed
commit 8a666a56b5
5 changed files with 251 additions and 215 deletions

View File

@@ -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 {

View File

@@ -66,10 +66,10 @@ 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;
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() {

View File

@@ -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;

View File

@@ -342,3 +342,38 @@ pub fn list_items(_req: HttpRequest) -> HttpResponse {
//.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))
}

File diff suppressed because it is too large Load Diff