mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add garage slot copy op functionality to fix #28
This commit is contained in:
35
rc_services_room/src/operations/garage_slot_copy.rs
Normal file
35
rc_services_room/src/operations/garage_slot_copy.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 69; // nice
|
||||
|
||||
const ORIGINAL_SLOT_PARAM_KEY: u8 = 43; // int; in
|
||||
const REUSE_SLOT_PARAM_KEY: u8 = 8; // int (optional); in
|
||||
const COPY_STR_PARAM_KEY: u8 = 213; // str; in
|
||||
|
||||
pub(super) struct GarageSlotCopier;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for GarageSlotCopier {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Int(slot)) = params.remove(&ORIGINAL_SLOT_PARAM_KEY) {
|
||||
if let Some(Typed::Str(copy_str)) = params.remove(©_STR_PARAM_KEY) {
|
||||
let user_info = user.user()?;
|
||||
if let Some(Typed::Int(reuse_slot)) = params.remove(&REUSE_SLOT_PARAM_KEY) {
|
||||
user_info.copy_slot(slot, Some(reuse_slot), ©_str.string).await?;
|
||||
} else {
|
||||
user_info.copy_slot(slot, None, ©_str.string).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn garage_slot_copy_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, GarageSlotCopier> {
|
||||
SimpleOpImpl::new(GarageSlotCopier)
|
||||
}
|
||||
@@ -96,6 +96,7 @@ mod avatar_set;
|
||||
mod garage_slot_controls;
|
||||
mod garage_slot_set_customisations;
|
||||
mod garage_slot_name;
|
||||
mod garage_slot_copy;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -215,4 +216,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(garage_slot_controls::garage_slot_controls_provider())
|
||||
.add(garage_slot_set_customisations::garage_slot_customisation_provider())
|
||||
.add(garage_slot_name::garage_slot_rename_provider())
|
||||
.add(garage_slot_copy::garage_slot_copy_provider())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user