From 86ad03ca1b133690da582e6d992b7fd953bbdd7a Mon Sep 17 00:00:00 2001 From: red binder Date: Sun, 21 Jun 2026 16:18:39 +0200 Subject: [PATCH] DeleteObject and ReportCourse --- ...2f49ac8c4cb5668559a92daebea815a2d64ec.json | 17 +++++ ...f6633db4cd635037622fd61d7a3a6a872db2e.json | 14 ++++ ...15a39af3e23d1acd523118088cf6f1b9dab92.json | 22 ++++++ rnex-core/src/nex/datastore.rs | 72 +++++++++++++++++-- rnex-core/src/rmc/protocols/datastore.rs | 31 +++++++- 5 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json create mode 100644 rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json create mode 100644 rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json diff --git a/rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json b/rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json new file mode 100644 index 0000000..2eb0052 --- /dev/null +++ b/rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO datastore.reports (\n data_id,\n reporter_pid,\n category,\n reason\n ) VALUES (\n $1, $2, $3, $4\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Int4", + "Int2", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec" +} diff --git a/rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json b/rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json new file mode 100644 index 0000000..934b1e2 --- /dev/null +++ b/rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE datastore.objects SET deleted=true WHERE data_id=$1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [] + }, + "hash": "75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e" +} diff --git a/rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json b/rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json new file mode 100644 index 0000000..bcc6b52 --- /dev/null +++ b/rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT update_password\n FROM datastore.objects\n WHERE data_id = $1 AND upload_completed = TRUE AND deleted = FALSE\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "update_password", + "type_info": "Int8" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false + ] + }, + "hash": "f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92" +} diff --git a/rnex-core/src/nex/datastore.rs b/rnex-core/src/nex/datastore.rs index d427575..3f1d3ca 100644 --- a/rnex-core/src/nex/datastore.rs +++ b/rnex-core/src/nex/datastore.rs @@ -1,9 +1,4 @@ use std::convert; - -use crate::rmc::protocols::datastore::{ - DataStoreFileServerObjectInfo, DataStoreGetCourseRecordParam, DataStoreGetCourseRecordResult, - DataStoreUploadCourseRecordParam, -}; use chrono::{NaiveDateTime, Utc}; use futures::TryStreamExt; use futures::future::join_all; @@ -23,6 +18,8 @@ use rnex_core::rmc::protocols::datastore::{ DataStoreGetCustomRankingByDataIDParam, DataStorePrepareGetParam, DataStoreReqGetInfo, DataStoreSearchParam, GetMetaInfo, GetMetaParam, KeyValue, Permission, PersistenceTarget, RateCustomRankingParam, RatingInfo, RatingInfoWithSlot, RatingInitParamWithSlot, + DataStoreDeleteParam, DataStoreFileServerObjectInfo, DataStoreGetCourseRecordParam, + DataStoreGetCourseRecordResult, DataStoreReportCourseParam, DataStoreUploadCourseRecordParam }; use rnex_core::rmc::response::ErrorCode; use rnex_core::rmc::structures::qbuffer::QBuffer; @@ -1671,4 +1668,69 @@ impl DataStore for User { // official servers always return true? application ID is always 0 as far as i know. maybe a check is warranted for the app id? Ok(true) } + + async fn report_course(&self, report_course_param: DataStoreReportCourseParam) -> Result<(), ErrorCode> { + let row = sqlx::query!( + r#" + INSERT INTO datastore.reports ( + data_id, + reporter_pid, + category, + reason + ) VALUES ( + $1, $2, $3, $4 + ) + "#, + report_course_param.dataid, + self.pid, + report_course_param.report_category as i16, + report_course_param.report_reason + ) + .execute(get_db()) + .await + .map_err(|e| { + log::error!("DB Error: {:?}", e); + ErrorCode::Core_NotImplemented // i don't know why, but returning this makes the game show "Report sent OK" so i'll use it + })?; + + Ok(()) + } + + async fn delete_object(&self, param: DataStoreDeleteParam) -> Result<(), ErrorCode> { + let row = sqlx::query!( + r#" + SELECT update_password + FROM datastore.objects + WHERE data_id = $1 AND upload_completed = TRUE AND deleted = FALSE + "#, + param.dataid + ) + .fetch_one(get_db()) + .await + .map_err(|e| { + log::error!("DB Error: {:?}", e); + ErrorCode::DataStore_NotFound + })?; + + let passwd = row.update_password; + + if param.update_password != passwd { + return Err(ErrorCode::DataStore_PermissionDenied); + } + + log::info!("update password check passed"); + + let deletequery = sqlx::query!( + "UPDATE datastore.objects SET deleted=true WHERE data_id=$1", + param.dataid + ) + .execute(get_db()) + .await + .map_err(|e| { + log::error!("DB Error: {:?}", e); + ErrorCode::DataStore_NotFound + })?; + + Ok(()) + } } diff --git a/rnex-core/src/rmc/protocols/datastore.rs b/rnex-core/src/rmc/protocols/datastore.rs index f0d2047..524d25d 100644 --- a/rnex-core/src/rmc/protocols/datastore.rs +++ b/rnex-core/src/rmc/protocols/datastore.rs @@ -302,10 +302,34 @@ pub struct DataStoreFileServerObjectInfo { pub get_info: DataStoreReqGetInfo, } +#[derive(RmcSerialize, Clone)] +#[rmc_struct(0)] +pub struct DataStoreReportCourseParam { + pub dataid: i64, + pub mii_name: String, + pub report_category: i8, + pub report_reason: String, +} + +#[derive(RmcSerialize, Clone)] +#[rmc_struct(0)] +pub struct DataStoreDeleteParam { + pub dataid: i64, + pub update_password: i64, +} + #[rmc_proto(115)] pub trait DataStore { + #[method_id(4)] + async fn delete_object( + &self, + param: DataStoreDeleteParam, + ) -> Result<(), ErrorCode>; #[method_id(8)] - async fn get_meta(&self, metaparam: GetMetaParam) -> Result; + async fn get_meta( + &self, + metaparam: GetMetaParam, + ) -> Result; #[method_id(24)] async fn prepare_post_object( &self, @@ -407,4 +431,9 @@ pub trait DataStore { &self, application_id: u32, ) -> Result; + #[method_id(87)] + async fn report_course( + &self, + report_course_param: DataStoreReportCourseParam + ) -> Result<(), ErrorCode>; }