diff --git a/rc_core/src/persist/user/account_json.rs b/rc_core/src/persist/user/account_json.rs index 6fd669b..0733c96 100644 --- a/rc_core/src/persist/user/account_json.rs +++ b/rc_core/src/persist/user/account_json.rs @@ -694,6 +694,18 @@ impl super::User for UserData { } } + async fn set_slot_name(&self, slot: i32, name: String) -> Result<(), i16> { + let to_save = rc_database::schema::garage::ActiveModel { + name: rc_database::sea_orm::ActiveValue::Set(name), + ..Default::default() + }; + self.db.update_garage_by_user_id_and_slot(to_save, self.account.id, slot as u32).await.map_err(|e| { + log::error!("Failed to save garage {} for user_id {}: {}", slot, self.account.id, e); + DATABASE_ERR + })?; + Ok(()) + } + fn signup_date(&self) -> i64 { super::since_windows_epoch(self.account.creation_time) } diff --git a/rc_core/src/persist/user/traits.rs b/rc_core/src/persist/user/traits.rs index 3c7e6ab..d51b620 100644 --- a/rc_core/src/persist/user/traits.rs +++ b/rc_core/src/persist/user/traits.rs @@ -72,6 +72,7 @@ pub trait User: ChatUser { async fn save_slot_controls(&self, controls: ControlData) -> Result<(), i16>; async fn save_slot_customisations(&self, customs: CustomisationData) -> Result<(), i16>; async fn get_slot_customisations(&self, uuid: &str) -> Result, i16>; + async fn set_slot_name(&self, slot: i32, name: String) -> Result<(), i16>; fn signup_date(&self) -> i64; async fn singleplayer_robots(&self, factory: &dyn rc_factory::VehicleFactoryAdapter, weapon_order: &crate::cubes::WeaponListParser) -> Result, i16>; async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result; diff --git a/rc_services_room/src/operations/garage_slot_name.rs b/rc_services_room/src/operations/garage_slot_name.rs new file mode 100644 index 0000000..123db48 --- /dev/null +++ b/rc_services_room/src/operations/garage_slot_name.rs @@ -0,0 +1,30 @@ +use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl}; +use polariton::operation::{ParameterTable, Typed}; + +const CODE: u8 = 46; + +const SLOT_PARAM_KEY: u8 = 45; // int; in +const NAME_PARAM_KEY: u8 = 42; // str; in + +pub(super) struct GarageSlotRenamer; + +#[async_trait::async_trait] +impl SimpleOperation for GarageSlotRenamer { + type User = crate::UserTy; + const CODE: u8 = CODE; + + async fn handle(&self, params: ParameterTable, user: &Self::User) -> Result, SimpleOpError> { + let mut params = params.to_dict(); + if let Some(Typed::Int(slot)) = params.remove(&SLOT_PARAM_KEY) { + if let Some(Typed::Str(name)) = params.remove(&NAME_PARAM_KEY) { + let user_info = user.user()?; + user_info.set_slot_name(slot, name.string).await?; + } + } + Ok(params.into()) + } +} + +pub(super) fn garage_slot_rename_provider() -> SimpleOpImpl { + SimpleOpImpl::new(GarageSlotRenamer) +} diff --git a/rc_services_room/src/operations/mod.rs b/rc_services_room/src/operations/mod.rs index 6514e5b..188dcdb 100644 --- a/rc_services_room/src/operations/mod.rs +++ b/rc_services_room/src/operations/mod.rs @@ -95,6 +95,7 @@ mod avatar_set_custom; mod avatar_set; mod garage_slot_controls; mod garage_slot_set_customisations; +mod garage_slot_name; use polariton_server::operations::OperationsHandler; @@ -213,4 +214,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler .add(avatar_set::avatar_set_provider()) .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()) }