mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement serial_code
This commit is contained in:
parent
2133f2236d
commit
c9376f754d
4 changed files with 84 additions and 15 deletions
|
@ -85,6 +85,9 @@ async fn user_initialize(req: HttpRequest, body: String) -> HttpResponse { route
|
|||
#[post("/api/user/detail")]
|
||||
async fn user_detail(req: HttpRequest, body: String) -> HttpResponse { router::user::detail(req, body) }
|
||||
|
||||
#[get("/api/gift")]
|
||||
async fn gift_get(req: HttpRequest) -> HttpResponse { router::home::gift_get(req) }
|
||||
|
||||
#[post("/api/gift")]
|
||||
async fn gift(req: HttpRequest, body: String) -> HttpResponse { router::user::gift(req, body) }
|
||||
|
||||
|
@ -196,6 +199,9 @@ async fn gglrequestmigrationcode(req: HttpRequest, body: String) -> HttpResponse
|
|||
#[post("/api/user/gglverifymigrationcode")]
|
||||
async fn gglverifymigrationcode(req: HttpRequest, body: String) -> HttpResponse { router::user::verify_migration_code(req, body) }
|
||||
|
||||
#[post("/api/serial_code")]
|
||||
async fn serial_code(req: HttpRequest, body: String) -> HttpResponse { router::serial_code::serial_code(req, body) }
|
||||
|
||||
#[get("/api/serial_code/events")]
|
||||
async fn serial_code_events(req: HttpRequest) -> HttpResponse { router::serial_code::events(req) }
|
||||
|
||||
|
@ -276,6 +282,7 @@ async fn main() -> std::io::Result<()> {
|
|||
println!("Request: {}", req.path());
|
||||
srv.call(req)
|
||||
})
|
||||
.service(serial_code)
|
||||
.service(shop)
|
||||
.service(shop_buy)
|
||||
.service(css)
|
||||
|
@ -354,6 +361,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(gglverifymigrationcode)
|
||||
.service(serial_code_events)
|
||||
.service(gift)
|
||||
.service(gift_get)
|
||||
.default_service(web::route().to(log_unknown_request)))
|
||||
.bind(("0.0.0.0", 8080))?
|
||||
.run();
|
||||
|
|
|
@ -216,7 +216,7 @@ pub fn give_primogems(amount: i64, user: &mut JsonValue) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn gift_item(item: &JsonValue, reason: &str, user: &mut JsonValue) {
|
||||
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(),
|
||||
|
@ -230,9 +230,10 @@ pub fn gift_item(item: &JsonValue, reason: &str, user: &mut JsonValue) {
|
|||
received_date_time: 0
|
||||
};
|
||||
if user["home"]["gift_list"].len() >= GIFT_LIMIT {
|
||||
return;
|
||||
return to_push;
|
||||
}
|
||||
user["home"]["gift_list"].push(to_push).unwrap();
|
||||
user["home"]["gift_list"].push(to_push.clone()).unwrap();
|
||||
return to_push;
|
||||
}
|
||||
|
||||
pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use json::{object, array};
|
||||
use json::{object, array, JsonValue};
|
||||
use crate::router::global;
|
||||
use crate::encryption;
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
|
@ -24,6 +24,33 @@ pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
|
|||
global::send(resp)
|
||||
}
|
||||
|
||||
fn check_gifts(user: &mut JsonValue) {
|
||||
let mut to_remove = array![];
|
||||
for (j, data) in user["home"]["gift_list"].members().enumerate() {
|
||||
if data["is_receive"].to_string() == "1" || data["expire_date_time"].as_u64().unwrap() < global::timestamp() {
|
||||
to_remove.push(j).unwrap();
|
||||
}
|
||||
}
|
||||
for (i, data) in to_remove.members().enumerate() {
|
||||
user["home"]["gift_list"].array_remove(data.as_usize().unwrap() - i);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gift_get(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), "");
|
||||
let mut user = userdata::get_acc_home(&key);
|
||||
check_gifts(&mut user);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"gift_list": user["home"]["gift_list"].clone()
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn preset_get(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), "");
|
||||
let user = userdata::get_acc(&key);
|
||||
|
@ -44,15 +71,7 @@ pub fn home(req: HttpRequest) -> HttpResponse {
|
|||
let key = global::get_login(req.headers(), "");
|
||||
let mut user = userdata::get_acc_home(&key);
|
||||
|
||||
let mut to_remove = array![];
|
||||
for (j, data) in user["home"]["gift_list"].members().enumerate() {
|
||||
if data["is_receive"].to_string() == "1" || data["expire_date_time"].as_u64().unwrap() < global::timestamp() {
|
||||
to_remove.push(j).unwrap();
|
||||
}
|
||||
}
|
||||
for (i, data) in to_remove.members().enumerate() {
|
||||
user["home"]["gift_list"].array_remove(data.as_usize().unwrap() - i);
|
||||
}
|
||||
check_gifts(&mut user);
|
||||
userdata::save_acc_home(&key, user.clone());
|
||||
|
||||
let resp = object!{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use json;
|
||||
use crate::encryption;
|
||||
use json::object;
|
||||
use crate::router::global;
|
||||
use crate::router::userdata;
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
|
||||
pub fn events(_req: HttpRequest) -> HttpResponse {
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
|
@ -14,3 +14,44 @@ pub fn events(_req: HttpRequest) -> HttpResponse {
|
|||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn serial_code(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_home(&key);
|
||||
|
||||
let item;
|
||||
if body["input_code"].to_string() == "SIF2REVIVALREAL!" {
|
||||
item = global::gift_item(&object!{
|
||||
id: global::timestamp(),
|
||||
type: 4,
|
||||
level: 0,
|
||||
amount: 100000,
|
||||
value: 1
|
||||
}, "You typed in code", &mut user);
|
||||
} else {
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"result_code": 3
|
||||
}
|
||||
};
|
||||
return global::send(resp);
|
||||
}
|
||||
|
||||
userdata::save_acc_home(&key, user.clone());
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"serial_code_event": {"id":42,"name":"Serial Code Reward","unique_limit_count":0,"min_user_rank":0,"max_user_rank":0,"end_date":null},
|
||||
"reward_list": [item],
|
||||
"result_code": 0,
|
||||
"gift_list": user["gift_list"].clone(),
|
||||
"excluded_gift_list": []
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue