From 2115bbb08b6b2a06e1eede92ed2f1c71db809c3f Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:15:20 -0500 Subject: [PATCH] Implement `/api/mission/clear` --- src/main.rs | 4 ++++ src/router/mission.rs | 43 ++++++++++++++++++++++++++++++++++++++----- src/router/user.rs | 1 - 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index d8c9c5b..999fe06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,6 +117,9 @@ async fn live_clearrate(req: HttpRequest) -> HttpResponse { router::live::clearr #[get("/api/mission")] async fn mission(req: HttpRequest) -> HttpResponse { router::mission::mission(req) } +#[get("/api/mission/clear")] +async fn mission_clear(req: HttpRequest, body: String) -> HttpResponse { router::mission::clear(req, body) } + #[get("/api/home")] async fn home(req: HttpRequest) -> HttpResponse { router::home::home(req) } @@ -213,6 +216,7 @@ async fn main() -> std::io::Result<()> { .service(lottery) .service(friend) .service(mission) + .service(mission_clear) .service(home) .service(start_assethash) .service(user) diff --git a/src/router/mission.rs b/src/router/mission.rs index f0ab4fc..98493d8 100644 --- a/src/router/mission.rs +++ b/src/router/mission.rs @@ -2,17 +2,50 @@ use json; use json::object; use crate::router::global; use actix_web::{HttpResponse, HttpRequest}; -//use crate::router::userdata; +use crate::router::userdata; +use crate::encryption; -pub fn mission(_req: HttpRequest) -> HttpResponse { - //let key = global::get_login(req.headers()); - //let user = userdata::get_acc(&key); +pub fn mission(req: HttpRequest) -> HttpResponse { + let key = global::get_login(req.headers(), ""); + let missions = userdata::get_acc_missions(&key); let resp = object!{ "code": 0, "server_time": global::timestamp(), "data": { - "mission_list": [] + "mission_list": missions + } + }; + global::send(resp) +} + +pub fn clear(req: HttpRequest, body: String) -> HttpResponse { + let key = global::get_login(req.headers(), &body); + let mut missions = userdata::get_acc_missions(&key); + let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); + + for (_i, id) in body["master_mission_ids"].members().enumerate() { + for (i, mission) in missions.members().enumerate() { + if mission["master_mission_id"].to_string() == id.to_string() { + //I think this is all? + missions[i]["progress"] = (1).into(); + break; + } + } + } + + userdata::save_acc_missions(&key, missions); + + let resp = object!{ + "code": 0, + "server_time": global::timestamp(), + "data": { + "clear_mission_ids": body["master_mission_ids"].clone() + } + }; + global::send(resp) +} + } }; global::send(resp) diff --git a/src/router/user.rs b/src/router/user.rs index 6755bed..7075f80 100644 --- a/src/router/user.rs +++ b/src/router/user.rs @@ -232,7 +232,6 @@ pub fn detail(_req: HttpRequest, body: String) -> HttpResponse { to_push["user"].remove("ss_user_id"); to_push["user"].remove("birthday"); user_detail_list.push(to_push).unwrap(); - } let resp = object!{ "code": 0,