I DID NOT TEST THIS COMMIT CARGO CLIPPY DID STUFF FOR ME AND I'M TOO LAZY TO TEST SO HOPEFULLY NOTHING BROKE

This commit is contained in:
Ethan O'Brien 2024-05-24 00:56:25 -05:00
parent ea48327e10
commit 7df2f3e277
16 changed files with 188 additions and 201 deletions

View file

@ -172,7 +172,7 @@ macro_rules! include_file {
( $s:expr ) => {
{
let file = include_flate_codegen::deflate_file!($s);
let ret = crate::decode(file);
let ret = $crate::decode(file);
std::string::String::from_utf8(ret).unwrap()
}
};

View file

@ -6,7 +6,7 @@ use crate::encryption;
fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_multiplier: i64, evolve: bool) -> JsonValue {
for (i, data) in user["card_list"].members().enumerate() {
if data["id"].to_string() == body["id"].to_string() {
if data["id"] == body["id"] {
let materials = &body["material_item_list"];
let mut card = data.clone();
let mut money: i64 = 0;
@ -32,7 +32,7 @@ fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_mult
return card;
}
}
return object!{};
object!{}
}
pub fn reinforce(req: HttpRequest, body: String) -> HttpResponse {

View file

@ -143,7 +143,7 @@ fn get_json() -> JsonValue {
let mut ids = array![];
for (_i, id) in lives.members().enumerate() {
let info = DATABASE.get_live_data(id.as_i64().unwrap());
if !info.is_ok() {
if info.is_err() {
continue;
}
let info = info.unwrap();

View file

@ -55,15 +55,15 @@ pub fn recommend(req: HttpRequest, body: String) -> HttpResponse {
let friends = userdata::get_acc_friends(&key);
let mut random = userdata::get_random_uids(20);
let index = random.members().into_iter().position(|r| *r.to_string() == user_id.to_string());
if !index.is_none() {
let index = random.members().position(|r| *r.to_string() == user_id.to_string());
if index.is_some() {
random.array_remove(index.unwrap());
}
let mut rv = array![];
for (_i, uid) in random.members().enumerate() {
let user = global::get_user(uid.as_i64().unwrap(), &friends, false);
if user["user"]["friend_request_disabled"].to_string() == "1" || user.is_empty() {
if user["user"]["friend_request_disabled"] == "1" || user.is_empty() {
continue;
}
rv.push(user).unwrap();
@ -125,14 +125,14 @@ pub fn approve(req: HttpRequest, body: String) -> HttpResponse {
let mut friends = userdata::get_acc_friends(&key);
let uid = body["user_id"].as_i64().unwrap();
let index = friends["pending_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
if !index.is_none() {
let index = friends["pending_user_id_list"].members().position(|r| *r.to_string() == uid.to_string());
if index.is_some() {
friends["pending_user_id_list"].array_remove(index.unwrap());
if body["approve"].to_string() == "1" && ! friends["friend_user_id_list"].contains(uid) && friends["friend_user_id_list"].len() < FRIEND_LIMIT {
if body["approve"] == "1" && ! friends["friend_user_id_list"].contains(uid) && friends["friend_user_id_list"].len() < FRIEND_LIMIT {
friends["friend_user_id_list"].push(uid).unwrap();
}
userdata::friend_request_approve(uid, user_id, body["approve"].to_string() == "1", "request_user_id_list");
userdata::friend_request_approve(uid, user_id, body["approve"] == "1", "request_user_id_list");
userdata::save_acc_friends(&key, friends);
}
@ -151,8 +151,8 @@ pub fn cancel(req: HttpRequest, body: String) -> HttpResponse {
let mut friends = userdata::get_acc_friends(&key);
let uid = body["user_id"].as_i64().unwrap();
let index = friends["request_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
if !index.is_none() {
let index = friends["request_user_id_list"].members().position(|r| *r.to_string() == uid.to_string());
if index.is_some() {
friends["request_user_id_list"].array_remove(index.unwrap());
}
userdata::friend_request_approve(uid, user_id, false, "pending_user_id_list");
@ -173,8 +173,8 @@ pub fn delete(req: HttpRequest, body: String) -> HttpResponse {
let mut friends = userdata::get_acc_friends(&key);
let uid = body["user_id"].as_i64().unwrap();
let index = friends["friend_user_id_list"].members().into_iter().position(|r| *r.to_string() == uid.to_string());
if !index.is_none() {
let index = friends["friend_user_id_list"].members().position(|r| *r.to_string() == uid.to_string());
if index.is_some() {
friends["friend_user_id_list"].array_remove(index.unwrap());
}
userdata::friend_remove(uid, user_id);

View file

@ -43,31 +43,31 @@ pub fn get_login(headers: &HeaderMap, body: &str) -> String {
let blank_header = HeaderValue::from_static("");
let login = headers.get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
let decoded = general_purpose::STANDARD.decode(login).unwrap_or(vec![]);
match get_uuid(&String::from_utf8_lossy(&decoded).to_string()) {
let decoded = general_purpose::STANDARD.decode(login).unwrap_or_default();
match get_uuid(String::from_utf8_lossy(&decoded).as_ref()) {
Some(token) => {
return token;
token
},
None => {
let rv = gree::get_uuid(headers, body);
assert!(rv != String::new());
return rv;
rv
},
};
}
}
pub fn timestamp() -> u64 {
let now = SystemTime::now();
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
return unix_timestamp.as_secs();
unix_timestamp.as_secs()
}
pub fn timestamp_msec() -> u32 {
let now = SystemTime::now();
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
return unix_timestamp.subsec_nanos();
unix_timestamp.subsec_nanos()
}
pub fn timestamp_since_midnight() -> u64 {
@ -76,8 +76,8 @@ pub fn timestamp_since_midnight() -> u64 {
let midnight = unix_timestamp.as_secs() % (24 * 60 * 60);
let rv = unix_timestamp.as_secs() - midnight;
rv
unix_timestamp.as_secs() - midnight
}
fn init_time(server_data: &mut JsonValue, token: &str) {
@ -91,7 +91,7 @@ fn init_time(server_data: &mut JsonValue, token: &str) {
edited = true;
}
if edited {
userdata::save_server_data(&token, server_data.clone());
userdata::save_server_data(token, server_data.clone());
}
}
@ -156,7 +156,7 @@ pub fn get_card(id: i64, user: &JsonValue) -> JsonValue {
return data.clone();
}
}
return object!{};
object!{}
}
fn get_cards(arr: JsonValue, user: &JsonValue) -> JsonValue {
@ -168,13 +168,13 @@ fn get_cards(arr: JsonValue, user: &JsonValue) -> JsonValue {
}
rv.push(to_push).unwrap();
}
return rv;
rv
}
fn get_clear_count(user: &JsonValue, level: i32) -> i64 {
let mut rv = 0;
for (_i, current) in user["live_list"].members().enumerate() {
if current["level"].to_string() == level.to_string() {
if current["level"] == level {
rv += 1;
}
}

View file

@ -33,7 +33,7 @@ fn setup_tables(conn: &SQLite) {
}
fn update_cert(uid: i64, cert: &str) {
if !DATABASE.lock_and_select("SELECT cert FROM users WHERE user_id=?1;", params!(uid)).is_ok() {
if DATABASE.lock_and_select("SELECT cert FROM users WHERE user_id=?1;", params!(uid)).is_err() {
let token = userdata::get_login_token(uid);
if token != String::new() {
DATABASE.lock_and_exec(
@ -69,19 +69,16 @@ fn verify_signature(signature: &[u8], message: &[u8], public_key: &[u8]) -> bool
let mut verifier = Verifier::new(MessageDigest::sha1(), &pkey).unwrap();
verifier.update(message).unwrap();
match verifier.verify(signature) {
Ok(_) => true,
Err(_) => false,
}
verifier.verify(signature).is_ok()
}
pub fn get_uuid(headers: &HeaderMap, body: &str) -> String {
let body = encryption::decrypt_packet(&body).unwrap();
let body = encryption::decrypt_packet(body).unwrap();
let blank_header = HeaderValue::from_static("");
let login = headers.get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
let uid = headers.get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
let version = headers.get("aoharu-client-version").unwrap_or(&blank_header).to_str().unwrap_or("");
let timestamp = headers.get("aoharu-timestamp").unwrap_or(&blank_header).to_str().unwrap_or("");
if uid == "" || login == "" || version == "" || timestamp == "" {
if uid.is_empty() || login.is_empty() || version.is_empty() || timestamp.is_empty() {
return String::new();
}
@ -90,12 +87,12 @@ pub fn get_uuid(headers: &HeaderMap, body: &str) -> String {
let data = format!("{}{}{}{}{}", uid, "sk1bdzb310n0s9tl", version, timestamp, body);
let encoded = general_purpose::STANDARD.encode(data.as_bytes());
let decoded = general_purpose::STANDARD.decode(login).unwrap_or(vec![]);
let decoded = general_purpose::STANDARD.decode(login).unwrap_or_default();
if verify_signature(&decoded, &encoded.as_bytes(), &cert.as_bytes()) {
return DATABASE.lock_and_select("SELECT uuid FROM users WHERE user_id=?1;", params!(uid)).unwrap();
if verify_signature(&decoded, encoded.as_bytes(), cert.as_bytes()) {
DATABASE.lock_and_select("SELECT uuid FROM users WHERE user_id=?1;", params!(uid)).unwrap()
} else {
return String::new();
String::new()
}
}
@ -114,7 +111,7 @@ fn rot13(input: &str) -> String {
fn decrypt_transfer_password(password: &str) -> String {
let reversed = password.chars().rev().collect::<String>();
let rot = rot13(&reversed);
let decoded = general_purpose::STANDARD.decode(rot).unwrap_or(vec![]);
let decoded = general_purpose::STANDARD.decode(rot).unwrap_or_default();
String::from_utf8_lossy(&decoded).to_string()
}
@ -178,7 +175,7 @@ pub fn uid(req: HttpRequest) -> HttpResponse {
let uid_data: Vec<&str> = auth_header.split(",xoauth_requestor_id=\"").collect();
if let Some(uid_data2) = uid_data.get(1) {
let uid_data2: Vec<&str> = uid_data2.split('"').collect();
if let Some(uid_str) = uid_data2.get(0) {
if let Some(uid_str) = uid_data2.first() {
uid = uid_str.to_string();
}
}
@ -223,7 +220,7 @@ pub fn migration_verify(req: HttpRequest, body: String) -> HttpResponse {
let user = userdata::get_acc_transfer(uid, &body["migration_code"].to_string(), &password);
let resp;
if user["success"].as_bool().unwrap() != true || uid == 0 {
if !user["success"].as_bool().unwrap() || uid == 0 {
resp = object!{
result: "ERR",
messsage: "User Not Found"
@ -269,7 +266,7 @@ pub fn balance(req: HttpRequest) -> HttpResponse {
let uid_data: Vec<&str> = auth_header.split(",xoauth_requestor_id=\"").collect();
if let Some(uid_data2) = uid_data.get(1) {
let uid_data2: Vec<&str> = uid_data2.split('"').collect();
if let Some(uid_str) = uid_data2.get(0) {
if let Some(uid_str) = uid_data2.first() {
uid = uid_str.to_string();
}
}
@ -295,7 +292,7 @@ pub fn migration_code(req: HttpRequest) -> HttpResponse {
let uid_data: Vec<&str> = auth_header.split(",xoauth_requestor_id=\"").collect();
if let Some(uid_data2) = uid_data.get(1) {
let uid_data2: Vec<&str> = uid_data2.split('"').collect();
if let Some(uid_str) = uid_data2.get(0) {
if let Some(uid_str) = uid_data2.first() {
uid = uid_str.to_string();
}
}
@ -318,7 +315,7 @@ pub fn migration_password_register(req: HttpRequest, body: String) -> HttpRespon
let uid_data: Vec<&str> = auth_header.split(",xoauth_requestor_id=\"").collect();
if let Some(uid_data2) = uid_data.get(1) {
let uid_data2: Vec<&str> = uid_data2.split('"').collect();
if let Some(uid_str) = uid_data2.get(0) {
if let Some(uid_str) = uid_data2.first() {
uid = uid_str.to_string();
}
}
@ -337,7 +334,7 @@ pub fn migration_password_register(req: HttpRequest, body: String) -> HttpRespon
}
fn get_protocol() -> String {
if env::args().nth(1).unwrap_or(String::new()) == String::from("https") {
if env::args().nth(1).unwrap_or_default() == *"https" {
return String::from("https");
}
String::from("http")
@ -348,7 +345,7 @@ fn gree_authorize(req: &HttpRequest) -> String {
let blank_header = HeaderValue::from_static("");
let auth_header = req.headers().get("Authorization").unwrap_or(&blank_header).to_str().unwrap_or("");
if auth_header == "" {
if auth_header.is_empty() {
return String::new();
}
let auth_header = auth_header.substring(6, auth_header.len());
@ -366,7 +363,7 @@ fn gree_authorize(req: &HttpRequest) -> String {
let hostname = req.headers().get("host").unwrap_or(&blank_header).to_str().unwrap_or("");
let current_url = format!("{}://{}{}", get_protocol(), hostname, req.path());
let uri = req.uri().to_string();
let extra = if uri.contains("?") {
let extra = if uri.contains('?') {
format!("&{}", uri.split('?').nth(1).unwrap_or(""))
} else { String::new() };

View file

@ -11,7 +11,7 @@ pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
let mut user = userdata::get_acc_home(&key);
for (_i, data) in user["home"]["preset_setting"].members_mut().enumerate() {
if data["slot"].to_string() == body["slot"].to_string() {
if data["slot"] == body["slot"] {
*data = body.clone();
}
}
@ -28,7 +28,7 @@ pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
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() {
if data["is_receive"] == "1" || data["expire_date_time"].as_u64().unwrap() < global::timestamp() {
to_remove.push(j).unwrap();
}
}

View file

@ -81,19 +81,19 @@ pub fn give_gift(data: &JsonValue, user: &mut JsonValue, missions: &mut JsonValu
if data.is_empty() {
return false;
}
if data["reward_type"].to_string() == "1" {
if data["reward_type"] == "1" {
// basically primogems!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return !give_primogems(data["amount"].as_i64().unwrap(), user);
} else if data["reward_type"].to_string() == "2" {
} else if data["reward_type"] == "2" {
//character
give_character(data["value"].to_string(), user, missions, clear_missions);
return true;
} else if data["reward_type"].to_string() == "3" {
} else if data["reward_type"] == "3" {
return !give_item(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user);
} else if data["reward_type"].to_string() == "4" {
} else if data["reward_type"] == "4" {
// basically moraa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return !give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user, missions, clear_missions);
} else if data["reward_type"].to_string() == "8" {
} else if data["reward_type"] == "8" {
// title
let title = data["value"].as_i64().unwrap();
if !user["master_title_ids"].contains(title) {
@ -101,8 +101,8 @@ pub fn give_gift(data: &JsonValue, user: &mut JsonValue, missions: &mut JsonValu
}
return true;
}
println!("Redeeming reward not implemented for reward type {}", data["reward_type"].to_string());
return false;
println!("Redeeming reward not implemented for reward type {}", data["reward_type"]);
false
}
pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i64, user: &mut JsonValue, missions: &mut JsonValue, clear_missions: &mut JsonValue) -> bool {
give_gift(&object!{
@ -181,7 +181,7 @@ pub fn gift_item(item: &JsonValue, reason: &str, user: &mut JsonValue) -> JsonVa
return to_push;
}
user["home"]["gift_list"].push(to_push.clone()).unwrap();
return to_push;
to_push
}
fn random_number(lowest: usize, highest: usize) -> usize {
@ -234,7 +234,7 @@ pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) {
// false - already has
pub fn give_character(id: String, user: &mut JsonValue, missions: &mut JsonValue, clear_missions: &mut JsonValue) -> bool {
for (_i, data) in user["card_list"].members().enumerate() {
if data["master_card_id"].to_string() == id || data["id"].to_string() == id {
if data["master_card_id"] == id || data["id"] == id {
give_item(19100001, 50, user);
return false;
}
@ -264,14 +264,14 @@ pub fn get_user_rank_data(exp: i64) -> JsonValue {
return databases::RANKS[i - 1].clone();
}
}
return databases::RANKS[databases::RANKS.len() - 1].clone();
databases::RANKS[databases::RANKS.len() - 1].clone()
}
pub fn give_exp(amount: i32, user: &mut JsonValue, mission: &mut JsonValue, rv: &mut JsonValue) {
let current_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
user["user"]["exp"] = (user["user"]["exp"].as_i32().unwrap() + amount).into();
let new_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
if current_rank["rank"].to_string() != new_rank["rank"].to_string() {
if current_rank["rank"] != new_rank["rank"] {
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i64().unwrap() + new_rank["maxLp"].as_i64().unwrap()).into();
user["stamina"]["last_updated_time"] = global::timestamp().into();
@ -315,7 +315,7 @@ pub fn update_mission_status_multi(master_mission_id: JsonValue, expire: u64, co
let mut rv = array![];
for (_i, mission) in master_mission_id.members().enumerate() {
let val = update_mission_status(mission.as_i64().unwrap(), expire, completed, claimed, advance, missions);
if !val.is_none() {
if val.is_some() {
rv.push(val.unwrap()).unwrap();
}
}
@ -363,14 +363,12 @@ pub fn advance_variable_mission(min: i64, max: i64, count: i64, missions: &mut J
break;
}
if mission_info["conditionNumber"].as_i64().unwrap() > mission_status["progress"].as_i64().unwrap() + count {
if !update_mission_status(i, 0, false, false, count, missions).is_none() {
if update_mission_status(i, 0, false, false, count, missions).is_some() {
rv.push(i).unwrap();
}
} else {
if !update_mission_status(i, 0, true, false, count, missions).is_none() {
} else if update_mission_status(i, 0, true, false, count, missions).is_some() {
rv.push(i).unwrap();
}
}
break;
}
rv
@ -388,7 +386,7 @@ pub fn advance_mission(id: i64, count: i64, max: i64, missions: &mut JsonValue)
}
let completed = new == max;
let advanced = new - mission["progress"].as_i64().unwrap();
if !update_mission_status(id, 0, completed, false, advanced, missions).is_none() {
if update_mission_status(id, 0, completed, false, advanced, missions).is_some() {
return Some(id);
}
None
@ -412,15 +410,13 @@ pub fn completed_daily_mission(id: i64, missions: &mut JsonValue) -> JsonValue {
}
if mission["progress"].as_i32().unwrap() == 4 {
if !update_mission_status(1224003, 0, true, false, 1, missions).is_none() {
if update_mission_status(1224003, 0, true, false, 1, missions).is_some() {
rv.push(1224003).unwrap();
}
} else {
if !update_mission_status(1224003, 0, false, false, 1, missions).is_none() {
} else if update_mission_status(1224003, 0, false, false, 1, missions).is_some() {
rv.push(1224003).unwrap();
}
}
if !update_mission_status(id, next_reset, true, false, 1, missions).is_none() {
if update_mission_status(id, next_reset, true, false, 1, missions).is_some() {
rv.push(id).unwrap();
}
rv

View file

@ -100,26 +100,26 @@ pub fn guest(req: HttpRequest, body: String) -> HttpResponse {
"status":0
}).unwrap();
} else {
if friends["friend_user_id_list"].len() != 0 {
if !friends["friend_user_id_list"].is_empty() {
guest_list.push(global::get_user(friends["friend_user_id_list"][random_number(0, friends["friend_user_id_list"].len() - 1)].as_i64().unwrap(), &friends, false)).unwrap();
}
let expected: usize = 5;
if guest_list.len() < expected {
let mut random = userdata::get_random_uids((expected-guest_list.len()) as i32);
let index = random.members().into_iter().position(|r| *r.to_string() == user_id.to_string());
if !index.is_none() {
let index = random.members().position(|r| *r.to_string() == user_id.to_string());
if index.is_some() {
random.array_remove(index.unwrap());
}
for (_i, uid) in random.members().enumerate() {
let guest = global::get_user(uid.as_i64().unwrap(), &friends, false);
if guest["user"]["friend_request_disabled"].to_string() == "1" || guest.is_empty() {
if guest["user"]["friend_request_disabled"] == "1" || guest.is_empty() {
continue;
}
guest_list.push(guest).unwrap();
}
}
if guest_list.len() == 0 {
if guest_list.is_empty() {
guest_list.push(object!{
"user": {
"name": "A sad Guest",
@ -244,7 +244,7 @@ pub fn update_live_data(user: &mut JsonValue, data: &JsonValue, add: bool) -> Js
let mut has = false;
for (_i, current) in user["live_list"].members_mut().enumerate() {
if current["master_live_id"].to_string() == rv["master_live_id"].to_string() && (current["level"].to_string() == rv["level"].to_string() || data["level"].as_i32().unwrap() == 0) {
if current["master_live_id"] == rv["master_live_id"] && (current["level"] == rv["level"] || data["level"].as_i32().unwrap() == 0) {
has = true;
if add {
rv["clear_count"] = (current["clear_count"].as_i64().unwrap() + 1).into();
@ -285,7 +285,7 @@ pub fn update_live_mission_data(user: &mut JsonValue, data: &JsonValue) {
};
for (_i, current) in user["live_mission_list"].members_mut().enumerate() {
if current["master_live_id"].to_string() == rv["master_live_id"].to_string() {
if current["master_live_id"] == rv["master_live_id"] {
for (_i, id) in data["clear_master_live_mission_ids"].members().enumerate() {
if !current["clear_master_live_mission_ids"].contains(id.as_i32().unwrap()) {
current["clear_master_live_mission_ids"].push(id.as_i32().unwrap()).unwrap();
@ -305,7 +305,7 @@ fn get_live_mission_completed_ids(user: &JsonValue, live_id: i64, score: i64, co
for (_i, data) in databases::MISSION_DATA.members().enumerate() {
match data["type"].as_i32()? {
1 => {
if live_info[&format!("score{}", data["value"].to_string())].as_i64()? <= score {
if live_info[&format!("score{}", data["value"])].as_i64()? <= score {
out.push(data["id"].as_i32()?).ok()?;
}
},
@ -334,7 +334,7 @@ fn get_live_mission_completed_ids(user: &JsonValue, live_id: i64, score: i64, co
}
let mut rv = array![];
for (_i, current) in user["live_mission_list"].members().enumerate() {
if current["master_live_id"].to_string() == live_id.to_string() {
if current["master_live_id"] == live_id {
for (_i, id) in out.members().enumerate() {
if !current["clear_master_live_mission_ids"].contains(id.as_i32().unwrap()) {
rv.push(id.as_i32().unwrap()).unwrap();
@ -372,11 +372,11 @@ fn give_mission_rewards(user: &mut JsonValue, missions: &JsonValue, user_mission
fn get_master_id(id: i64) -> i64 {
let id = id.to_string();
let mut masterid = 0;
if id.starts_with("2") {
if id.starts_with('2') {
masterid += 9;
} else if id.starts_with("3") {
} else if id.starts_with('3') {
masterid += 9 + 9;
} else if id.starts_with("4") {
} else if id.starts_with('4') {
masterid += 9 + 9 + 12;
}
masterid + id.char_indices().last().unwrap().1.to_string().parse::<i64>().unwrap()
@ -415,15 +415,15 @@ fn get_live_character_list(lp_used: i32, deck_id: i32, user: &JsonValue, mission
}
}
let mut index = characters_in_deck.members().into_iter().position(|r| r.as_i64().unwrap() == data["id"].as_i64().unwrap());
let mut index = characters_in_deck.members().position(|r| r.as_i64().unwrap() == data["id"].as_i64().unwrap());
if index.is_none() {
index = characters_in_deck.members().into_iter().position(|r| r.as_i64().unwrap() == data["master_card_id"].as_i64().unwrap());
index = characters_in_deck.members().position(|r| r.as_i64().unwrap() == data["master_card_id"].as_i64().unwrap());
}
let exp = BOND_WEIGHT[index.unwrap_or(10)].as_i32().unwrap_or(0) * (lp_used / 10);
let additional_exp;
if has.contains(character) {
additional_exp = 0;
let j = has.members().into_iter().position(|r| r.as_i64().unwrap() == character).unwrap_or(10);
let j = has.members().position(|r| r.as_i64().unwrap() == character).unwrap_or(10);
if j != 10 {
let start = rv[has_i[j].as_usize().unwrap()]["before_exp"].as_i64().unwrap();
let mut bond = start + exp as i64;
@ -431,7 +431,7 @@ fn get_live_character_list(lp_used: i32, deck_id: i32, user: &JsonValue, mission
if bond > rv[has_i[j].as_usize().unwrap()]["exp"].as_i64().unwrap() {
let completed = bond >= limit;
let mission = items::update_mission_status(mission_id, 0, completed, false, bond - start, missions);
if !mission.is_none() {
if mission.is_some() {
completed_missions.push(mission.unwrap()).unwrap();
}
rv[has_i[j].as_usize().unwrap()]["exp"] = bond.into();
@ -452,7 +452,7 @@ fn get_live_character_list(lp_used: i32, deck_id: i32, user: &JsonValue, mission
if !full && additional_exp > 0 {
let completed = bond >= limit;
let mission = items::update_mission_status(mission_id, 0, completed, false, bond - start, missions);
if !mission.is_none() {
if mission.is_some() {
completed_missions.push(mission.unwrap()).unwrap();
}
}
@ -493,7 +493,7 @@ fn live_end(req: &HttpRequest, body: &String, skipped: bool) -> JsonValue {
let mut cleared_missions = items::advance_variable_mission(1105001, 1105017, 1, &mut user_missions);
if body["master_live_id"].to_string().len() > 1 {
let id = body["master_live_id"].to_string().split("").collect::<Vec<_>>()[2].parse::<i64>().unwrap_or(0);
if id <= 4 && id >= 1 {
if (1..=4).contains(&id) {
let to_push = items::completed_daily_mission(1273009 + id - 1, &mut user_missions);
for (_i, data) in to_push.members().enumerate() {
cleared_missions.push(data.as_i32().unwrap()).unwrap();
@ -512,36 +512,32 @@ fn live_end(req: &HttpRequest, body: &String, skipped: bool) -> JsonValue {
missions = get_live_mission_completed_ids(&user, body["master_live_id"].as_i64().unwrap(), body["live_score"]["score"].as_i64().unwrap(), body["live_score"]["max_combo"].as_i64().unwrap(), live["clear_count"].as_i64().unwrap_or(0), body["level"].as_i64().unwrap(), is_full_combo, is_perfect).unwrap_or(array![]);
if is_full_combo {
if !items::advance_mission(1176001, 1, 1, &mut user_missions).is_none() {
if items::advance_mission(1176001, 1, 1, &mut user_missions).is_some() {
cleared_missions.push(1176001).unwrap();
}
if !items::advance_mission(1176002, 1, 100, &mut user_missions).is_none() {
if items::advance_mission(1176002, 1, 100, &mut user_missions).is_some() {
cleared_missions.push(1176002).unwrap();
}
if !items::advance_mission(1176003, 1, 200, &mut user_missions).is_none() {
if items::advance_mission(1176003, 1, 200, &mut user_missions).is_some() {
cleared_missions.push(1176003).unwrap();
}
if !items::advance_mission(1176004, 1, 300, &mut user_missions).is_none() {
if items::advance_mission(1176004, 1, 300, &mut user_missions).is_some() {
cleared_missions.push(1176004).unwrap();
}
if !items::advance_mission(1176005, 1, 400, &mut user_missions).is_none() {
if items::advance_mission(1176005, 1, 400, &mut user_missions).is_some() {
cleared_missions.push(1176005).unwrap();
}
if !items::advance_mission(1176006, 1, 500, &mut user_missions).is_none() {
if items::advance_mission(1176006, 1, 500, &mut user_missions).is_some() {
cleared_missions.push(1176006).unwrap();
}
}
if is_perfect {
if !items::advance_mission(1177001, 1, 1, &mut user_missions).is_none() {
if is_perfect && items::advance_mission(1177001, 1, 1, &mut user_missions).is_some() {
cleared_missions.push(1177001).unwrap();
}
}
if is_perfect && body["level"].as_i32().unwrap() == 4 {
if !items::advance_mission(1177002, 1, 1, &mut user_missions).is_none() {
if is_perfect && body["level"].as_i32().unwrap() == 4 && items::advance_mission(1177002, 1, 1, &mut user_missions).is_some() {
cleared_missions.push(1177002).unwrap();
}
}
}
update_live_mission_data(&mut user, &object!{
master_live_id: body["master_live_id"].as_i64().unwrap(),

View file

@ -11,11 +11,11 @@ pub fn tutorial(req: HttpRequest, body: String) -> HttpResponse {
let id = body["master_character_id"].to_string();
let user = &id[id.len() - 2..].parse::<i32>().unwrap();
let mut lotteryid = 9110000;
if id.starts_with("2") {
if id.starts_with('2') {
lotteryid += 9; //muse
} else if id.starts_with("3") {
} else if id.starts_with('3') {
lotteryid += 9 + 9; //aquors
} else if id.starts_with("4") {
} else if id.starts_with('4') {
lotteryid += 9 + 9 + 12; //nijigasaki
}
lotteryid += user;
@ -52,7 +52,7 @@ fn get_random_card(item: &JsonValue, rv: &mut JsonValue, rng: &mut rand::rngs::T
let mut random_id = 0;
while random_id == 0 {
let card = rng.gen_range(1..databases::POOL[lottery_id.to_string()][databases::POOL[lottery_id.to_string()].len() - 1].as_i64().unwrap() + 1);
if !get_card_master_id(lottery_id.to_string(), card.to_string()).is_none() {
if get_card_master_id(lottery_id.to_string(), card.to_string()).is_some() {
random_id = card;
break;
}
@ -67,7 +67,7 @@ fn get_random_card(item: &JsonValue, rv: &mut JsonValue, rng: &mut rand::rngs::T
}
fn get_random_cards(id: i64, mut count: usize) -> JsonValue {
let total_ratio: i64 = databases::RARITY[id.to_string()].members().into_iter().map(|item| if item["ensured"].as_i32().unwrap() == 1 { 0 } else { item["ratio"].as_i64().unwrap() }).sum();
let total_ratio: i64 = databases::RARITY[id.to_string()].members().map(|item| if item["ensured"].as_i32().unwrap() == 1 { 0 } else { item["ratio"].as_i64().unwrap() }).sum();
let mut rng = rand::thread_rng();
let mut rv = array![];
let mut promised = false;
@ -75,7 +75,7 @@ fn get_random_cards(id: i64, mut count: usize) -> JsonValue {
if count > 1 {
for (_i, item) in databases::RARITY[id.to_string()].members().enumerate() {
if item["ensured"].as_i32().unwrap() == 1 {
get_random_card(&item, &mut rv, &mut rng);
get_random_card(item, &mut rv, &mut rng);
promised = true;
break;
}
@ -90,7 +90,7 @@ fn get_random_cards(id: i64, mut count: usize) -> JsonValue {
for (_i, item) in databases::RARITY[id.to_string()].members().enumerate() {
cumulative_ratio += item["ratio"].as_i64().unwrap();
if random_number <= cumulative_ratio {
get_random_card(&item, &mut rv, &mut rng);
get_random_card(item, &mut rv, &mut rng);
break;
}
}

View file

@ -21,17 +21,17 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
let mut user = userdata::get_acc_home(&key);
let itemz;
if body["input_code"].to_string() == "SIF2REVIVALREAL!" {
if body["input_code"] == "SIF2REVIVALREAL!" {
itemz = array![items::gift_item_basic(1, 100000, 4, "Another game died... This makes me sad :(", &mut user)];
} else if body["input_code"].to_string() == "pweasegivegems11" {
} else if body["input_code"] == "pweasegivegems11" {
itemz = array![items::gift_item_basic(1, 6000, 1, "Only because you asked...", &mut user)];
} else if body["input_code"].to_string() == "sleepysleepyslep" {
} else if body["input_code"] == "sleepysleepyslep" {
itemz = array![items::gift_item_basic(15540001, 50, 3, "I am tired", &mut user)];
} else if body["input_code"].to_string() == "ilikeganyu!!!!!!" {
} else if body["input_code"] == "ilikeganyu!!!!!!" {
itemz = array![items::gift_item_basic(16005003, 100, 3, "I need more primogems", &mut user)];
} else if body["input_code"].to_string() == "serial_code" {
} else if body["input_code"] == "serial_code" {
itemz = array![items::gift_item_basic(17001003, 100, 3, "nyaa~", &mut user)];
} else if body["input_code"].to_string() == "ganuy" {
} else if body["input_code"] == "ganuy" {
itemz = array![
items::gift_item_basic(40010015, 1, 2, "I need more primogem!!!!!!", &mut user),
items::gift_item_basic(30010015, 1, 2, "I need more primogem!!!!!!", &mut user),
@ -42,7 +42,7 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
items::gift_item_basic(40030013, 1, 2, "I need more primogem!!!!!!", &mut user),
items::gift_item_basic(10070016, 1, 2, "I need more primogem!!!!!!", &mut user)
];
} else if body["input_code"].to_string() == "kode" {
} else if body["input_code"] == "kode" {
itemz = array![
items::gift_item_basic(10060018, 1, 2, "meow", &mut user),
items::gift_item_basic(20050019, 1, 2, "meow", &mut user),
@ -50,7 +50,7 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
items::gift_item_basic(10010014, 1, 2, "meow", &mut user),
items::gift_item_basic(10010015, 1, 2, "meow", &mut user)
];
} else if body["input_code"].to_string() == "meow" {
} else if body["input_code"] == "meow" {
itemz = array![
items::gift_item_basic(10010020, 1, 2, "I need more primogem!!!!!!", &mut user),
items::gift_item_basic(10040016, 1, 2, "I need more primogem!!!!!!", &mut user),
@ -74,7 +74,7 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse {
items::gift_item_basic(40080011, 1, 2, "I need more primogem!!!!!!", &mut user),
items::gift_item_basic(40090011, 1, 2, "I need more primogem!!!!!!", &mut user)
];
} else if body["input_code"].to_string() == "HuTao" {
} else if body["input_code"] == "HuTao" {
itemz = array![
items::gift_item_basic(15500001, 500, 3, "Okay...............", &mut user),
items::gift_item_basic(15500002, 500, 3, "Okay...............", &mut user),

View file

@ -5,7 +5,7 @@ use crate::encryption;
use crate::router::{userdata, global};
fn get_asset_hash(req: &HttpRequest, body: &JsonValue) -> String {
if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP {
if body["asset_version"] != global::ASSET_VERSION && body["asset_version"] != global::ASSET_VERSION_JP {
println!("Warning! Asset version is not what was expected. (Did the app update?)");
}
@ -13,20 +13,18 @@ fn get_asset_hash(req: &HttpRequest, body: &JsonValue) -> String {
let platform = req.headers().get("aoharu-platform").unwrap_or(&blank_header).to_str().unwrap_or("");
let android = !platform.to_lowercase().contains("iphone");
let hash = if body["asset_version"].to_string() == global::ASSET_VERSION_JP {
let hash = if body["asset_version"] == global::ASSET_VERSION_JP {
if android {
global::ASSET_HASH_ANDROID_JP
} else {
global::ASSET_HASH_IOS_JP
}
} else {
if android {
} else if android {
global::ASSET_HASH_ANDROID
} else {
global::ASSET_HASH_IOS
}
};
return hash.to_string();
hash.to_string()
}
pub fn asset_hash(req: HttpRequest, body: String) -> HttpResponse {

View file

@ -72,10 +72,10 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
for (_i, gift_id) in body["gift_ids"].members().enumerate() {
let mut to_remove = 0;
for (j, data) in user["home"]["gift_list"].members_mut().enumerate() {
if data["id"].to_string() != gift_id.to_string() {
if data["id"] != *gift_id {
continue;
}
if !items::give_gift(&data, &mut userr, &mut missions, &mut cleared_missions) {
if !items::give_gift(data, &mut userr, &mut missions, &mut cleared_missions) {
failed.push(gift_id.clone()).unwrap();
break;
}
@ -192,33 +192,33 @@ pub fn announcement(req: HttpRequest) -> HttpResponse {
pub fn uid_to_code(uid: String) -> String {
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
return uid
.replace("1", "A")
.replace("2", "G")
.replace("3", "W")
.replace("4", "Q")
.replace("5", "Y")
.replace("6", "6")
.replace("7", "I")
.replace("8", "P")
.replace("9", "U")
.replace("0", "M")
+ "7";
uid
.replace('1', "A")
.replace('2', "G")
.replace('3', "W")
.replace('4', "Q")
.replace('5', "Y")
.replace('6', "6")
.replace('7', "I")
.replace('8', "P")
.replace('9', "U")
.replace('0', "M")
+ "7"
}
pub fn code_to_uid(code: String) -> String {
//just replace uid with numbers because im too lazy to have a real database and this is close enough anyways
return code
.replace("7", "")
.replace("A", "1")
.replace("G", "2")
.replace("W", "3")
.replace("Q", "4")
.replace("Y", "5")
.replace("6", "6")
.replace("I", "7")
.replace("P", "8")
.replace("U", "9")
.replace("M", "0");
code
.replace('7', "")
.replace('A', "1")
.replace('G', "2")
.replace('W', "3")
.replace('Q', "4")
.replace('Y', "5")
.replace('6', "6")
.replace('I', "7")
.replace('P', "8")
.replace('U', "9")
.replace('M', "0")
}
pub fn get_migration_code(req: HttpRequest, body: String) -> HttpResponse {
@ -260,7 +260,7 @@ pub fn verify_migration_code(req: HttpRequest, body: String) -> HttpResponse {
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
if user["success"].as_bool().unwrap() == false || uid == 0 {
if !user["success"].as_bool().unwrap() || uid == 0 {
let resp = object!{
"code": 2,
"server_time": global::timestamp(),
@ -290,7 +290,7 @@ pub fn request_migration_code(req: HttpRequest, body: String) -> HttpResponse {
let user = userdata::get_acc_transfer(uid, &body["migrationCode"].to_string(), &body["pass"].to_string());
if user["success"].as_bool().unwrap() != true || uid == 0 {
if !user["success"].as_bool().unwrap() || uid == 0 {
let resp = object!{
"code": 2,
"server_time": global::timestamp(),
@ -448,15 +448,15 @@ pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
let cardstoreward: JsonValue;
let mut masterid = 3000000;
if id.starts_with("1") {
if id.starts_with('1') {
cardstoreward = array![10010001, 10020001, 10030001, 10040001, 10050001, 10060001, 10070001, 10080001, 10090001]; //muse
} else if id.starts_with("2") {
} else if id.starts_with('2') {
cardstoreward = array![20010001, 20020001, 20030001, 20040001, 20050001, 20060001, 20070001, 20080001, 20090001]; //aqours
masterid += 9; //muse
} else if id.starts_with("3") {
} else if id.starts_with('3') {
cardstoreward = array![30010001, 30020001, 30030001, 30040001, 30050001, 30060001, 30070001, 30080001, 30090001, 30100001, 30110001]; //nijigasaki
masterid += 9 + 9; //aqours
} else if id.starts_with("4") {
} else if id.starts_with('4') {
cardstoreward = array![40010001, 40020001, 40030001, 40040001, 40050001, 40060001, 40070001, 40080001, 40090001]; //liella
masterid += 9 + 9 + 12; //nijigasaki
} else {

View file

@ -74,7 +74,7 @@ fn acc_exists(uid: i64) -> bool {
DATABASE.lock_and_select("SELECT user_id FROM userdata WHERE user_id=?1", params!(uid)).is_ok()
}
fn get_key(auth_key: &str) -> i64 {
let uid = get_uid(&auth_key);
let uid = get_uid(auth_key);
let key = if uid == 0 {
generate_uid()
} else {
@ -82,7 +82,7 @@ fn get_key(auth_key: &str) -> i64 {
};
if !acc_exists(key) {
create_acc(key, &auth_key);
create_acc(key, auth_key);
}
key
@ -160,7 +160,7 @@ fn create_acc(uid: i64, login: &str) {
fn get_uid(token: &str) -> i64 {
let data = DATABASE.lock_and_select("SELECT user_id FROM tokens WHERE token = ?1;", params!(token));
if !data.is_ok() {
if data.is_err() {
return 0;
}
let data = data.unwrap();
@ -170,7 +170,7 @@ fn get_uid(token: &str) -> i64 {
// Needed by gree
pub fn get_login_token(uid: i64) -> String {
let data = DATABASE.lock_and_select("SELECT token FROM tokens WHERE user_id=?1", params!(uid));
if !data.is_ok() {
if data.is_err() {
return String::new();
}
data.unwrap()
@ -207,7 +207,7 @@ fn cleanup_account(user: &mut JsonValue) {
}
fn get_data(auth_key: &str, row: &str) -> JsonValue {
let key = get_key(&auth_key);
let key = get_key(auth_key);
let result = DATABASE.lock_and_select(&format!("SELECT {} FROM {} WHERE user_id=?1", row, row), params!(key));
@ -219,14 +219,14 @@ pub fn get_acc(auth_key: &str) -> JsonValue {
cleanup_account(&mut user);
items::lp_modification(&mut user, 0, false);
return user;
user
}
pub fn get_acc_home(auth_key: &str) -> JsonValue {
let mut user = get_data(auth_key, "userhome");
user["home"]["pending_friend_count"] = get_acc_friends(auth_key)["pending_user_id_list"].len().into();
return user;
user
}
pub fn get_acc_missions(auth_key: &str) -> JsonValue {
get_data(auth_key, "missions")
@ -258,13 +258,13 @@ pub fn get_acc_eventlogin(auth_key: &str) -> JsonValue {
}
pub fn save_data(auth_key: &str, row: &str, data: JsonValue) {
let key = get_key(&auth_key);
let key = get_key(auth_key);
DATABASE.lock_and_exec(&format!("UPDATE {} SET {}=?1 WHERE user_id=?2", row, row), params!(json::stringify(data), key));
}
pub fn save_acc(auth_key: &str, data: JsonValue) {
DATABASE.lock_and_exec("UPDATE userdata SET friend_request_disabled=?1 WHERE user_id=?2", params!(data["user"]["friend_request_disabled"].as_i32().unwrap(), get_key(&auth_key)));
DATABASE.lock_and_exec("UPDATE userdata SET friend_request_disabled=?1 WHERE user_id=?2", params!(data["user"]["friend_request_disabled"].as_i32().unwrap(), get_key(auth_key)));
save_data(auth_key, "userdata", data);
}
pub fn save_acc_home(auth_key: &str, data: JsonValue) {
@ -307,15 +307,15 @@ fn hash_password(password: &str) -> String {
let hashed_password = hasher.finalize();
let salt_hash = [&salt[..], &hashed_password[..]].concat();
general_purpose::STANDARD.encode(&salt_hash)
general_purpose::STANDARD.encode(salt_hash)
}
fn verify_password(password: &str, salted_hash: &str) -> bool {
if password == "" || salted_hash == "" {
if password.is_empty() || salted_hash.is_empty() {
return false;
}
let bytes = general_purpose::STANDARD.decode(salted_hash);
if !bytes.is_ok() {
if bytes.is_err() {
return password == salted_hash;
}
let bytes = bytes.unwrap();
@ -335,7 +335,7 @@ fn verify_password(password: &str, salted_hash: &str) -> bool {
pub fn get_acc_transfer(uid: i64, token: &str, password: &str) -> JsonValue {
let data = DATABASE.lock_and_select("SELECT password FROM migration WHERE token=?1", params!(token));
if !data.is_ok() {
if data.is_err() {
return object!{success: false};
}
if verify_password(password, &data.unwrap()) {
@ -371,7 +371,7 @@ pub fn get_name_and_rank(uid: i64) -> JsonValue {
let result = DATABASE.lock_and_select("SELECT userdata FROM userdata WHERE user_id=?1", params!(uid));
let data = json::parse(&result.unwrap()).unwrap();
return object!{
object!{
user_name: data["user"]["name"].clone(),
user_rank: items::get_user_rank_data(data["user"]["exp"].as_i64().unwrap())["rank"].clone() //todo
}
@ -414,12 +414,12 @@ pub fn friend_request_approve(uid: i64, requestor: i64, accepted: bool, key: &st
let uid = get_uid(&login_token);
let friends = DATABASE.lock_and_select("SELECT friends FROM friends WHERE user_id=?1", params!(uid));
let mut friends = json::parse(&friends.unwrap()).unwrap();
let index = friends[key].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
if !index.is_none() {
let index = friends[key].members().position(|r| *r.to_string() == requestor.to_string());
if index.is_some() {
friends[key].array_remove(index.unwrap());
}
let index = friends["request_user_id_list"].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
if !index.is_none() {
let index = friends["request_user_id_list"].members().position(|r| *r.to_string() == requestor.to_string());
if index.is_some() {
friends["request_user_id_list"].array_remove(index.unwrap());
}
if accepted && !friends["friend_user_id_list"].contains(requestor) && friends["friend_user_id_list"].len() < crate::router::friend::FRIEND_LIMIT {
@ -436,7 +436,7 @@ pub fn friend_request_disabled(uid: i64) -> bool {
let uid = get_uid(&login_token);
let user = DATABASE.lock_and_select("SELECT userdata FROM userdata WHERE user_id=?1", params!(uid));
let user = json::parse(&user.unwrap()).unwrap();
user["user"]["friend_request_disabled"].to_string() == "1"
user["user"]["friend_request_disabled"] == "1"
}
pub fn friend_remove(uid: i64, requestor: i64) {
@ -447,8 +447,8 @@ pub fn friend_remove(uid: i64, requestor: i64) {
let uid = get_uid(&login_token);
let friends = DATABASE.lock_and_select("SELECT friends FROM friends WHERE user_id=?1", params!(uid));
let mut friends = json::parse(&friends.unwrap()).unwrap();
let index = friends["friend_user_id_list"].members().into_iter().position(|r| *r.to_string() == requestor.to_string());
if !index.is_none() {
let index = friends["friend_user_id_list"].members().position(|r| *r.to_string() == requestor.to_string());
if index.is_some() {
friends["friend_user_id_list"].array_remove(index.unwrap());
}
DATABASE.lock_and_exec("UPDATE friends SET friends=?1 WHERE user_id=?2", params!(json::stringify(friends), uid));
@ -479,9 +479,9 @@ fn create_webui_token() -> String {
pub fn webui_login(uid: i64, password: &str) -> Result<String, String> {
create_webui_store();
let pass = DATABASE.lock_and_select("SELECT password FROM migration WHERE token=?1", params!(crate::router::user::uid_to_code(uid.to_string()))).unwrap_or(String::new());
let pass = DATABASE.lock_and_select("SELECT password FROM migration WHERE token=?1", params!(crate::router::user::uid_to_code(uid.to_string()))).unwrap_or_default();
if !verify_password(password, &pass) {
if acc_exists(uid) && pass == "" {
if acc_exists(uid) && pass.is_empty() {
return Err(String::from("Migration token not set. Set token in game settings."));
}
return Err(String::from("User/password don't match"));
@ -516,22 +516,22 @@ pub fn webui_import_user(user: JsonValue) -> Result<JsonValue, String> {
}
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(String::new());
if uid == String::new() || token == "" {
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;
}
let uid = uid.parse::<i64>().unwrap_or(0);
if uid == 0 {
return None;
}
let last_login = DATABASE.lock_and_select("SELECT last_login FROM webui WHERE user_id=?1", params!(uid)).unwrap_or(String::new()).parse::<i64>().unwrap_or(0);
let last_login = DATABASE.lock_and_select("SELECT last_login FROM webui WHERE user_id=?1", params!(uid)).unwrap_or_default().parse::<i64>().unwrap_or(0);
let limit = 24 * 60 * 60; //1 day
//Expired token
if (global::timestamp() as i64) > last_login + limit {
DATABASE.lock_and_exec("DELETE FROM webui WHERE user_id=?1", params!(uid));
return None;
}
let login_token = DATABASE.lock_and_select("SELECT token FROM tokens WHERE user_id=?1", params!(uid)).unwrap_or(String::new());
let login_token = DATABASE.lock_and_select("SELECT token FROM tokens WHERE user_id=?1", params!(uid)).unwrap_or_default();
if login_token == String::new() {
return None;
}
@ -541,11 +541,11 @@ fn webui_login_token(token: &str) -> Option<String> {
pub fn webui_get_user(token: &str) -> Option<JsonValue> {
let login_token = webui_login_token(token)?;
return Some(object!{
Some(object!{
userdata: get_acc(&login_token),
loginbonus: get_acc_loginbonus(&login_token),
time: get_server_data(&login_token)["server_time"].clone()
});
})
}
pub fn webui_start_loginbonus(bonus_id: i64, token: &str) -> JsonValue {
@ -566,10 +566,10 @@ pub fn webui_start_loginbonus(bonus_id: i64, token: &str) -> JsonValue {
}
save_acc_loginbonus(&login_token, bonuses);
return object!{
object!{
result: "OK",
id: bonus_id
};
}
}
pub fn set_server_time(time: i64, token: &str) -> JsonValue {
@ -592,9 +592,9 @@ pub fn set_server_time(time: i64, token: &str) -> JsonValue {
server_data["server_time"] = time.into();
save_server_data(&login_token, server_data);
return object!{
object!{
result: "OK"
};
}
}
pub fn webui_logout(token: &str) {

View file

@ -12,7 +12,7 @@ use crate::router::{userdata, items};
fn get_login_token(req: &HttpRequest) -> Option<String> {
let blank_header = HeaderValue::from_static("");
let cookies = req.headers().get("Cookie").unwrap_or(&blank_header).to_str().unwrap_or("");
if cookies == "" {
if cookies.is_empty() {
return None;
}
return Some(cookies.split("ew_token=").last().unwrap_or("").split(';').collect::<Vec<_>>()[0].to_string());
@ -117,7 +117,7 @@ pub fn set_time(req: HttpRequest, body: String) -> HttpResponse {
pub fn logout(req: HttpRequest) -> HttpResponse {
let token = get_login_token(&req);
if !token.is_none() {
if token.is_some() {
userdata::webui_logout(&token.unwrap());
}
let resp = object!{
@ -133,9 +133,9 @@ pub fn logout(req: HttpRequest) -> HttpResponse {
pub fn main(req: HttpRequest) -> HttpResponse {
if req.path() == "/" {
let token = get_login_token(&req);
if !token.is_none() {
if token.is_some() {
let data = userdata::webui_get_user(&token.unwrap());
if !data.is_none() {
if data.is_some() {
return HttpResponse::Found()
.insert_header(("Location", "/home/"))
.body("");

View file

@ -83,7 +83,7 @@ impl SQLite {
match self.engine.lock() {
Ok(conn) => {
let mut stmt = conn.prepare("SELECT * FROM lives WHERE live_id=?1")?;
return Ok(stmt.query_row(params!(id), |row| {
return stmt.query_row(params!(id), |row| {
Ok(Live {
live_id: row.get(0)?,
normal_failed: row.get(1)?,
@ -95,7 +95,7 @@ impl SQLite {
master_failed: row.get(7)?,
master_pass: row.get(8)?,
})
})?);
});
}
Err(_) => {
std::thread::sleep(std::time::Duration::from_millis(self.sleep_duration));