From 73e625eea9442f0a6e68bcb5a8a1e94e89246324 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Sun, 21 Jul 2024 22:29:01 -0500 Subject: [PATCH] Fix crashes after all songs cleared --- src/router/event.rs | 106 +++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 30 deletions(-) diff --git a/src/router/event.rs b/src/router/event.rs index 30dcab7..89eb028 100644 --- a/src/router/event.rs +++ b/src/router/event.rs @@ -29,10 +29,6 @@ fn get_event_data(key: &str, event_id: u32) -> JsonValue { event[event_id.to_string()]["star_event"]["star_event_bonus_daily_count"] = 0.into(); } - if is_star_event { - event[event_id.to_string()]["star_event"]["is_star_event_update"] = 1.into(); - } - event[event_id.to_string()].clone() } @@ -102,13 +98,44 @@ pub fn event(req: HttpRequest, body: String) -> Option { let body = &encryption::decrypt_packet(&body).unwrap(); let body: EventGet = serde_json::from_str(body).unwrap(); - let event = get_event_data(&key, body.master_event_id); + let mut event = get_event_data(&key, body.master_event_id); + + let is_star_event = STAR_EVENT_IDS.contains(&body.master_event_id); + + if is_star_event { + let user = userdata::get_acc(&key); + let old = event["star_event"]["star_level"].as_i64().unwrap(); + event["star_event"]["star_level"] = get_star_rank(get_points(body.master_event_id, &user)).into(); + let leveled = old != event["star_event"]["star_level"].as_i64().unwrap(); + + let mut all_clear = 1; + for data in event["star_event"]["star_music_list"].members() { + if data["is_cleared"] == 0 { + all_clear = 0; + } + } + if all_clear == 1 { + event["star_event"]["star_music_list"] = array![]; + switch_music(&mut event, 1); + switch_music(&mut event, 2); + switch_music(&mut event, 3); + switch_music(&mut event, 4); + switch_music(&mut event, 5); + save_event_data(&key, body.master_event_id, event.clone()); + } + + if leveled { + save_event_data(&key, body.master_event_id, event.clone()); + event["star_event"]["is_star_event_update"] = 1.into(); + } + } Some(event) } pub fn star_event(req: HttpRequest, body: String) -> Option { let key = global::get_login(req.headers(), &body); + let user = userdata::get_acc(&key); let body = &encryption::decrypt_packet(&body).unwrap(); let body: StarEvent = serde_json::from_str(body).unwrap(); @@ -118,27 +145,8 @@ pub fn star_event(req: HttpRequest, body: String) -> Option { let mut star_event = event["star_event"].clone(); star_event["is_inherited_level_reward"] = 0.into(); - let mut all_clear = 1; - for data in event["star_event"]["star_music_list"].members() { - if data["is_cleared"] == 0 { - all_clear = 0; - } - } - if all_clear == 1 { - switch_music(&mut event, 1); - switch_music(&mut event, 2); - switch_music(&mut event, 3); - switch_music(&mut event, 4); - switch_music(&mut event, 5); - } - let old = event["star_event"]["star_level"].as_i64().unwrap(); - event["star_event"]["star_level"] = get_star_rank(event["point_ranking"]["point"].as_i64().unwrap()).into(); - - star_event["is_star_level_up"] = if old == event["star_event"]["star_level"] { - 0 - } else { - 1 - }.into(); + event["star_event"]["star_level"] = get_star_rank(get_points(body.master_event_id, &user)).into(); + star_event["is_star_level_up"] = 1.into(); save_event_data(&key, body.master_event_id, event.clone()); @@ -193,12 +201,47 @@ pub fn ranking(_req: HttpRequest, _body: String) -> Option { }) } -const POINTS_PER_LEVEL: i64 = 55; +const POINTS_PER_LEVEL: i64 = 65; fn get_star_rank(points: i64) -> i64 { ((points - (points % POINTS_PER_LEVEL)) / POINTS_PER_LEVEL) + 1 } +const LIMIT_COINS: i64 = 2000000000; + +fn give_event_points(event_id: u32, amount: i64, user: &mut JsonValue) -> bool { + let mut has = false; + for data in user["event_point_list"].members_mut() { + if data["type"] == 1 { + has = true; + let new_amount = data["amount"].as_i64().unwrap() + amount; + if new_amount > LIMIT_COINS { + return true; + } + data["amount"] = new_amount.into(); + break; + } + } + if !has { + user["event_point_list"].push(object!{ + master_event_id: event_id, + type: 1, + amount: amount, + reward_status: [] + }).unwrap(); + } + false +} + +fn get_points(event_id: u32, user: &JsonValue) -> i64 { + for data in user["event_point_list"].members() { + if data["type"] == 1 && data["master_event_id"] == event_id { + return data["amount"].as_i64().unwrap() + } + } + 0 +} + pub fn event_live(req: HttpRequest, body: String, skipped: bool) -> Option { let key = global::get_login(req.headers(), &body); let body_temp = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); @@ -212,6 +255,7 @@ pub fn event_live(req: HttpRequest, body: String, skipped: bool) -> Option Option Option Option