forked from spacebar/rust-nex
DeleteObject and ReportCourse
This commit is contained in:
parent
66004f7713
commit
86ad03ca1b
5 changed files with 150 additions and 6 deletions
17
rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json
generated
Normal file
17
rnex-core/.sqlx/query-5cea63e5c1d279af23ef56d7ba02f49ac8c4cb5668559a92daebea815a2d64ec.json
generated
Normal file
|
|
@ -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"
|
||||
}
|
||||
14
rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json
generated
Normal file
14
rnex-core/.sqlx/query-75f4e823a82add9c1608a43a0dff6633db4cd635037622fd61d7a3a6a872db2e.json
generated
Normal file
|
|
@ -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"
|
||||
}
|
||||
22
rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json
generated
Normal file
22
rnex-core/.sqlx/query-f7c6fdbd098c8c6f3e5520794c115a39af3e23d1acd523118088cf6f1b9dab92.json
generated
Normal file
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<GetMetaInfo, ErrorCode>;
|
||||
async fn get_meta(
|
||||
&self,
|
||||
metaparam: GetMetaParam,
|
||||
) -> Result<GetMetaInfo, ErrorCode>;
|
||||
#[method_id(24)]
|
||||
async fn prepare_post_object(
|
||||
&self,
|
||||
|
|
@ -407,4 +431,9 @@ pub trait DataStore {
|
|||
&self,
|
||||
application_id: u32,
|
||||
) -> Result<bool, ErrorCode>;
|
||||
#[method_id(87)]
|
||||
async fn report_course(
|
||||
&self,
|
||||
report_course_param: DataStoreReportCourseParam
|
||||
) -> Result<(), ErrorCode>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue