mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Stamina
This commit is contained in:
parent
ca220a14db
commit
34a16be36e
4 changed files with 20 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
use json;
|
use json;
|
||||||
use json::object;
|
use json::object;
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
//use crate::encryption;
|
use crate::encryption;
|
||||||
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
|
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
|
||||||
use crate::router::userdata;
|
use crate::router::userdata;
|
||||||
|
|
||||||
|
@ -25,12 +25,20 @@ pub fn start(_req: HttpRequest, _body: String) -> HttpResponse {
|
||||||
global::send(resp)
|
global::send(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn end(req: HttpRequest, _body: String) -> HttpResponse {
|
pub fn end(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();
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
let user = userdata::get_acc(key);
|
|
||||||
let user2 = userdata::get_acc_home(key);
|
let user2 = userdata::get_acc_home(key);
|
||||||
|
let mut user = userdata::get_acc(key);
|
||||||
|
|
||||||
|
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i32().unwrap() - body["use_lp"].as_i32().unwrap()).into();
|
||||||
|
if user["stamina"]["stamina"].as_i32().unwrap() < 0 {
|
||||||
|
user["stamina"]["stamina"] = (0).into();
|
||||||
|
}
|
||||||
|
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
||||||
|
|
||||||
|
userdata::save_acc(key, user.clone());
|
||||||
|
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
|
|
@ -10,7 +10,10 @@ pub fn dummy(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();
|
||||||
let blank_header = HeaderValue::from_static("");
|
let blank_header = HeaderValue::from_static("");
|
||||||
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
let user = userdata::get_acc(key);
|
let mut user = userdata::get_acc(key);
|
||||||
|
|
||||||
|
user["user"]["last_login_time"] = global::timestamp().into();
|
||||||
|
userdata::save_acc(key, user.clone());
|
||||||
|
|
||||||
println!("Signin from uid: {}", user["user"]["id"].clone());
|
println!("Signin from uid: {}", user["user"]["id"].clone());
|
||||||
let resp = object!{
|
let resp = object!{
|
||||||
|
|
|
@ -49,8 +49,9 @@ pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
|
||||||
|
|
||||||
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
|
||||||
let mut user = userdata::get_acc(key);
|
let mut user = userdata::get_acc(key);
|
||||||
|
let ur = user["card_list"][user["card_list"].len() - 1]["id"].clone();
|
||||||
|
|
||||||
let id = (body["master_character_id"].as_i32().unwrap() * 10000) + 7; //todo - is this alwasy the case?
|
let id = ur.as_i32().unwrap(); //todo
|
||||||
user["user"]["favorite_master_card_id"] = id.into();
|
user["user"]["favorite_master_card_id"] = id.into();
|
||||||
user["user"]["guest_smile_master_card_id"] = id.into();
|
user["user"]["guest_smile_master_card_id"] = id.into();
|
||||||
user["user"]["guest_cool_master_card_id"] = id.into();
|
user["user"]["guest_cool_master_card_id"] = id.into();
|
||||||
|
@ -81,7 +82,6 @@ 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
|
||||||
|
|
||||||
let ur = user["card_list"][user["card_list"].len() - 1]["id"].clone();
|
|
||||||
for (i, data) in cardstoreward.members().enumerate() {
|
for (i, data) in cardstoreward.members().enumerate() {
|
||||||
global::give_character(data.to_string(), &mut user);
|
global::give_character(data.to_string(), &mut user);
|
||||||
if i < 10 {
|
if i < 10 {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::sync::{Mutex, MutexGuard};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use json::{JsonValue, array, object};
|
use json::{JsonValue, array, object};
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
use crate::router::global;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref ENGINE: Mutex<Option<Connection>> = Mutex::new(None);
|
pub static ref ENGINE: Mutex<Option<Connection>> = Mutex::new(None);
|
||||||
|
@ -100,6 +101,7 @@ fn create_acc(conn: &Connection, uid: i64, login: &str) {
|
||||||
home: json::parse(include_str!("new_user_home.json")).unwrap()
|
home: json::parse(include_str!("new_user_home.json")).unwrap()
|
||||||
};
|
};
|
||||||
data["userdata"]["user"]["id"] = uid.into();
|
data["userdata"]["user"]["id"] = uid.into();
|
||||||
|
data["userdata"]["stamina"]["last_updated_time"] = global::timestamp().into();
|
||||||
|
|
||||||
init_data(conn, &format!("_{}_", key), data);
|
init_data(conn, &format!("_{}_", key), data);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue