mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add slot renaming op code support to fix #24
This commit is contained in:
@@ -694,6 +694,18 @@ impl <C: Clone> super::User<C> 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 {
|
fn signup_date(&self) -> i64 {
|
||||||
super::since_windows_epoch(self.account.creation_time)
|
super::since_windows_epoch(self.account.creation_time)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ pub trait User<C>: ChatUser {
|
|||||||
async fn save_slot_controls(&self, controls: ControlData) -> Result<(), i16>;
|
async fn save_slot_controls(&self, controls: ControlData) -> Result<(), i16>;
|
||||||
async fn save_slot_customisations(&self, customs: CustomisationData) -> Result<(), i16>;
|
async fn save_slot_customisations(&self, customs: CustomisationData) -> Result<(), i16>;
|
||||||
async fn get_slot_customisations(&self, uuid: &str) -> Result<GetCustomisationData<C>, i16>;
|
async fn get_slot_customisations(&self, uuid: &str) -> Result<GetCustomisationData<C>, i16>;
|
||||||
|
async fn set_slot_name(&self, slot: i32, name: String) -> Result<(), i16>;
|
||||||
fn signup_date(&self) -> i64;
|
fn signup_date(&self) -> i64;
|
||||||
async fn singleplayer_robots(&self, factory: &dyn rc_factory::VehicleFactoryAdapter, weapon_order: &crate::cubes::WeaponListParser) -> Result<polariton::operation::Typed<C>, i16>;
|
async fn singleplayer_robots(&self, factory: &dyn rc_factory::VehicleFactoryAdapter, weapon_order: &crate::cubes::WeaponListParser) -> Result<polariton::operation::Typed<C>, i16>;
|
||||||
async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16>;
|
async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16>;
|
||||||
|
|||||||
30
rc_services_room/src/operations/garage_slot_name.rs
Normal file
30
rc_services_room/src/operations/garage_slot_name.rs
Normal file
@@ -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 <C: Send + 'static> SimpleOperation<C> for GarageSlotRenamer {
|
||||||
|
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(&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<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, GarageSlotRenamer> {
|
||||||
|
SimpleOpImpl::new(GarageSlotRenamer)
|
||||||
|
}
|
||||||
@@ -95,6 +95,7 @@ mod avatar_set_custom;
|
|||||||
mod avatar_set;
|
mod avatar_set;
|
||||||
mod garage_slot_controls;
|
mod garage_slot_controls;
|
||||||
mod garage_slot_set_customisations;
|
mod garage_slot_set_customisations;
|
||||||
|
mod garage_slot_name;
|
||||||
|
|
||||||
use polariton_server::operations::OperationsHandler;
|
use polariton_server::operations::OperationsHandler;
|
||||||
|
|
||||||
@@ -213,4 +214,5 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
|||||||
.add(avatar_set::avatar_set_provider())
|
.add(avatar_set::avatar_set_provider())
|
||||||
.add(garage_slot_controls::garage_slot_controls_provider())
|
.add(garage_slot_controls::garage_slot_controls_provider())
|
||||||
.add(garage_slot_set_customisations::garage_slot_customisation_provider())
|
.add(garage_slot_set_customisations::garage_slot_customisation_provider())
|
||||||
|
.add(garage_slot_name::garage_slot_rename_provider())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user