LP restoration

This commit is contained in:
Ethan O'Brien 2024-04-02 14:36:09 -05:00
parent b6546793f6
commit 68be3978fe
3 changed files with 106 additions and 5 deletions

93
Cargo.lock generated
View file

@ -50,7 +50,7 @@ dependencies = [
"mime",
"percent-encoding",
"pin-project-lite",
"rand",
"rand 0.8.5",
"sha1",
"smallvec",
"tokio",
@ -524,9 +524,10 @@ dependencies = [
"hmac",
"json",
"lazy_static",
"libmath",
"md5",
"openssl",
"rand",
"rand 0.8.5",
"reqwest",
"rusqlite",
"sha1",
@ -592,6 +593,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "futures-channel"
version = "0.3.30"
@ -891,6 +898,15 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libmath"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81f9daadfd4d8c4946fa32071d428cb70e493ab2c55a57a48da5261447d124cf"
dependencies = [
"rand 0.3.23",
]
[[package]]
name = "libsqlite3-sys"
version = "0.27.0"
@ -1165,6 +1181,29 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = [
"libc",
"rand 0.4.6",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
@ -1173,7 +1212,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_core 0.6.4",
]
[[package]]
@ -1183,9 +1222,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
"rand_core 0.6.4",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
@ -1195,6 +1249,15 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.4.1"
@ -1817,6 +1880,28 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.52.0"

View file

@ -19,3 +19,4 @@ md5 = "0.7.0"
urlencoding = "2.1.3"
sha1 = "0.10.6"
substring = "1.4.5"
libmath = "0.1.4"

View file

@ -3,6 +3,7 @@ use std::sync::{Mutex, MutexGuard};
use lazy_static::lazy_static;
use json::{JsonValue, array, object};
use crate::router::global;
use math::round;
lazy_static! {
pub static ref ENGINE: Mutex<Option<Connection>> = Mutex::new(None);
@ -179,7 +180,21 @@ fn get_data(a6573cbe: &str) -> JsonValue {
}
pub fn get_acc(a6573cbe: &str) -> JsonValue {
return get_data(a6573cbe)["userdata"].clone();
let mut user = get_data(a6573cbe)["userdata"].clone();
let max = 100; //todo
let speed = 300; //5 mins
let since_last = global::timestamp() - user["stamina"]["last_updated_time"].as_u64().unwrap();
let restored = round::floor((since_last / speed) as f64, 0) as u64;
let time_diff = since_last - (restored * speed);
user["stamina"]["last_updated_time"] = (global::timestamp() - time_diff).into();
let mut stamina = user["stamina"]["stamina"].as_u64().unwrap() + restored;
if stamina > max {
stamina = max;
}
user["stamina"]["stamina"] = stamina.into();
return user;
}
pub fn get_acc_home(a6573cbe: &str) -> JsonValue {