From ab19c723cd8a553aed1fe059519dd287513c586c Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Mon, 26 May 2025 21:30:28 -0400 Subject: [PATCH] Configure all death, spawn, and garage bay skins for #3 --- rc_core/src/data/garage_bay.rs | 11 + rc_core/src/persist/user/account_json.rs | 81 +++++ rc_core/src/persist/user/initial_data.rs | 6 + rc_core/src/persist/user/mod.rs | 24 +- rc_core/src/persist/user/traits.rs | 50 +++ ...0250526_000001_add_garage_customisation.rs | 54 +++ rc_database/src/migration/mod.rs | 2 + rc_database/src/schema/garage.rs | 4 + rc_database/src/wrapper.rs | 25 ++ .../src/operations/all_customisations_info.rs | 312 ++++++++++-------- .../src/operations/garage_slot_controls.rs | 58 ++++ .../garage_slot_set_customisations.rs | 49 +++ rc_services_room/src/operations/mod.rs | 4 + .../src/operations/robot_customisations.rs | 47 ++- 14 files changed, 584 insertions(+), 143 deletions(-) create mode 100644 rc_database/src/migration/m20250526_000001_add_garage_customisation.rs create mode 100644 rc_services_room/src/operations/garage_slot_controls.rs create mode 100644 rc_services_room/src/operations/garage_slot_set_customisations.rs diff --git a/rc_core/src/data/garage_bay.rs b/rc_core/src/data/garage_bay.rs index c175639..34ff165 100644 --- a/rc_core/src/data/garage_bay.rs +++ b/rc_core/src/data/garage_bay.rs @@ -64,6 +64,17 @@ pub enum ControlType { Count = 2, } +impl std::convert::From for ControlType { + #[inline] + fn from(value: crate::persist::user::ControlType) -> Self { + match value { + crate::persist::user::ControlType::Camera => Self::Camera, + crate::persist::user::ControlType::Keyboard => Self::Keyboard, + crate::persist::user::ControlType::Count => Self::Count, + } + } +} + pub struct ControlOptions { pub vertical_strafing: bool, pub sideways_driving: bool, diff --git a/rc_core/src/persist/user/account_json.rs b/rc_core/src/persist/user/account_json.rs index ad5a958..319c2b5 100644 --- a/rc_core/src/persist/user/account_json.rs +++ b/rc_core/src/persist/user/account_json.rs @@ -182,10 +182,27 @@ impl UserData { async fn all_vehicles(&self) -> Result, rc_database::sea_orm::DbErr> { self.db.garages_by_user_id(self.account.id).await } + + async fn double_check_permissions(&self) -> Result { + Ok(self.db.perms_by_user_id(self.account.id).await?.unwrap()) + } + + async fn err_on_banned(&self) -> Result<(), i16> { + let perms = self.double_check_permissions().await.map_err(|e| { + log::error!("Failed to retrieve user {} permissions: {}", self.account.id, e); + DATABASE_ERR + })?; + if perms.banned { + Err(crate::data::error_codes::WebServicesError::Banned as i16) + } else { + Ok(()) + } + } } const INVALID_ROBOT_ERR: i16 = crate::data::error_codes::WebServicesError::InvalidRobot as i16; // 140 const DATABASE_ERR: i16 = crate::data::error_codes::WebServicesError::DatabaseError as i16; // 8 +const UNEXPECTED_ERR: i16 = crate::data::error_codes::WebServicesError::UnexpectedError as i16; // 9 #[async_trait::async_trait] impl super::User for UserData { @@ -249,6 +266,7 @@ impl super::User for UserData { } async fn select_garage(&self, slot: i32) -> Result<(), i16> { + self.err_on_banned().await?; self.db.update_garage_selected_by_user_id_and_slot(self.account.id, slot as u32).await.map_err(|e| { log::error!("Failed to select vehicle slot {} user_id {}: {}", slot, self.account.id, e); DATABASE_ERR @@ -293,6 +311,7 @@ impl super::User for UserData { } async fn slot_by_id(&self, id: i32) -> Result, i16> { + self.err_on_banned().await?; match self.load_garage_by_slot(id as _).await { Ok(Some(slot)) => { let cube_count = slot.cube_count() as i32; @@ -329,6 +348,7 @@ impl super::User for UserData { } async fn save_slot(&self, vehicle: crate::persist::user::VehicleData) -> Result<(), i16> { + self.err_on_banned().await?; let entity = rc_database::schema::garage::ActiveModel { weapon_order: rc_database::sea_orm::ActiveValue::Set(rc_database::schema::dump_csv(&vehicle.weapon_order)), robot_data: rc_database::sea_orm::ActiveValue::Set(vehicle.robot_data), @@ -345,6 +365,7 @@ impl super::User for UserData { } async fn save_slot_order(&self, slots: Vec) -> Result<(), i16> { + self.err_on_banned().await?; let slots: Vec = slots.into_iter().map(|x| x as u32).collect(); let entity = rc_database::schema::user_aux::ActiveModel { data: rc_database::sea_orm::ActiveValue::Set(serde_json::to_string_pretty(&slots).unwrap()), @@ -358,6 +379,7 @@ impl super::User for UserData { } async fn new_slot(&self, reset_slot: Option) -> Result, i16> { + self.err_on_banned().await?; let model = if let Some(slot) = reset_slot { let new_data = super::initial_data::default_reset_slot(); if let Some(reset_g) = self.db.update_garage_by_user_id_and_slot(new_data, self.account.id, slot as u32).await.map_err(|e| { @@ -394,6 +416,7 @@ impl super::User for UserData { } async fn upgrade_slot(&self, increments: i32) -> Result, i16> { + self.err_on_banned().await?; if increments <= 0 { // no-op return Ok(polariton::operation::Typed::Bool(true)); @@ -432,11 +455,65 @@ impl super::User for UserData { } } + async fn save_slot_controls(&self, controls: super::ControlData) -> Result<(), i16> { + self.err_on_banned().await?; + let entity = rc_database::schema::garage::ActiveModel { + control_type: rc_database::sea_orm::ActiveValue::Set(controls.control_ty.into_db()), + vertical_strafing: rc_database::sea_orm::ActiveValue::Set(controls.vertical_strafing), + sideways_driving: rc_database::sea_orm::ActiveValue::Set(controls.sideways_driving), + tracks_turn_on_spot: rc_database::sea_orm::ActiveValue::Set(controls.tracks_turn_on_spot), + ..Default::default() + }; + self.save_garage_by_slot(entity, controls.slot as u32).await.map_err(|e| { + log::error!("Failed to save controls for slot {} for user_id {}: {}", controls.slot, self.account.id, e); + DATABASE_ERR + })?; + Ok(()) + } + + async fn save_slot_customisations(&self, customs: super::CustomisationData) -> Result<(), i16> { + self.err_on_banned().await?; + if let Some(uuid) = super::str_to_i64(&customs.uuid) { + let entity = rc_database::schema::garage::ActiveModel { + bay_skin_id: rc_database::sea_orm::ActiveValue::Set(customs.bay), + spawn_animation_id: rc_database::sea_orm::ActiveValue::Set(customs.spawn), + death_animation_id: rc_database::sea_orm::ActiveValue::Set(customs.death), + ..Default::default() + }; + self.db.update_garage_by_uuid(entity, uuid).await.map_err(|e| { + log::error!("Failed to save customisations for garage {} for user_id {}: {}", uuid, self.account.id, e); + DATABASE_ERR + })?; + } + Ok(()) + } + + async fn get_slot_customisations(&self, uuid: &str) -> Result, i16> { + if let Some(uuid) = super::str_to_i64(uuid) { + let garage_opt = self.db.garage_by_uuid(uuid).await.map_err(|e| { + log::error!("Failed to retrieve garage {} for user_id {}: {}", uuid, self.account.id, e); + DATABASE_ERR + })?; + if let Some(garage) = garage_opt { + Ok(super::GetCustomisationData { + bay: polariton::operation::Typed::Str(garage.bay_skin_id.into()), + spawn: polariton::operation::Typed::Str(garage.spawn_animation_id.into()), + death: polariton::operation::Typed::Str(garage.death_animation_id.into()), + }) + } else { + Err(DATABASE_ERR) + } + } else { + Err(UNEXPECTED_ERR) + } + } + fn signup_date(&self) -> i64 { super::since_windows_epoch(self.account.creation_time) } async fn singleplayer_robots(&self) -> Result, i16> { + self.err_on_banned().await?; let current_slot = self.db.garage_selected(self.account.id).await.map_err(|e| { log::error!("Failed to retrieve selected vehicle for user_id {} (singleplayer_robots): {}", self.account.id, e); DATABASE_ERR @@ -472,6 +549,7 @@ impl super::User for UserData { } async fn prepare_factory_upload(&self, vehicle: super::VehicleUploadData) -> Result { + self.err_on_banned().await?; let slot = self.load_garage_by_slot(vehicle.slot as u32).await.map_err(|e| { log::error!("Failed to retrieve vehicle slot {} for user_id {} (prepare_factory_upload): {}", vehicle.slot, self.account.id, e); DATABASE_ERR @@ -494,6 +572,7 @@ impl super::User for UserData { } async fn last_seen(&self) -> Result { + self.err_on_banned().await?; let last_seen_aux_opt = self.db.user_aux_by_user_id_and_descriptor(self.account.id, rc_database::schema::user_aux::Descriptor::LastSeen).await .map_err(|e| { log::error!("Failed to retrieve LastSeen (user_aux) for user_id {}: {}", self.account.id, e); @@ -528,6 +607,7 @@ impl super::User for UserData { } async fn get_avatar_info(&self) -> Result, i16> { + self.err_on_banned().await?; let avatar_id_aux = self.db.user_aux_by_user_id_and_descriptor(self.account.id, rc_database::schema::user_aux::Descriptor::AvatarId).await .map_err(|e| { log::error!("Failed to retrieve AvatarId (user_aux) for user_id {}: {}", self.account.id, e); @@ -549,6 +629,7 @@ impl super::User for UserData { } async fn set_avatar_info(&self, info: super::AvatarInfo) -> Result<(), i16> { + self.err_on_banned().await?; let to_update = rc_database::schema::user_aux::ActiveModel { data: rc_database::sea_orm::ActiveValue::Set(if info.use_custom { u32::MAX } else { info.avatar_id as u32 }.to_string()), ..Default::default() diff --git a/rc_core/src/persist/user/initial_data.rs b/rc_core/src/persist/user/initial_data.rs index 81a0f57..5f953dd 100644 --- a/rc_core/src/persist/user/initial_data.rs +++ b/rc_core/src/persist/user/initial_data.rs @@ -185,6 +185,8 @@ pub fn default_new_slot(user_id: u32, slot: u32, bay_cpu: u32) -> rc_database::s tracks_turn_on_spot: rc_database::sea_orm::ActiveValue::Set(false), mastery_level: rc_database::sea_orm::ActiveValue::Set(1), bay_skin_id: rc_database::sea_orm::ActiveValue::Set("RC_MothershipSkin_Neptune_01".to_owned()), + death_animation_id: rc_database::sea_orm::ActiveValue::Set("Explosion".to_owned()), + spawn_animation_id: rc_database::sea_orm::ActiveValue::Set("Spawn".to_owned()), weapon_order: rc_database::sea_orm::ActiveValue::Set("".to_owned()), robot_data: rc_database::sea_orm::ActiveValue::Set(vec![0u8; 4]), colour_data: rc_database::sea_orm::ActiveValue::Set(vec![0u8; 4]), @@ -216,6 +218,8 @@ pub fn default_reset_slot() -> rc_database::schema::garage::ActiveModel { tracks_turn_on_spot: rc_database::sea_orm::ActiveValue::Set(false), mastery_level: Default::default(), bay_skin_id: rc_database::sea_orm::ActiveValue::Set("RC_MothershipSkin_Neptune_01".to_owned()), + death_animation_id: rc_database::sea_orm::ActiveValue::Set("Explosion".to_owned()), + spawn_animation_id: rc_database::sea_orm::ActiveValue::Set("Spawn".to_owned()), weapon_order: rc_database::sea_orm::ActiveValue::Set("".to_owned()), robot_data: rc_database::sea_orm::ActiveValue::Set(vec![0u8; 4]), colour_data: rc_database::sea_orm::ActiveValue::Set(vec![0u8; 4]), @@ -249,6 +253,8 @@ fn default_garage_slots(user_id: u32) -> Vec String { format!("{}_{}", uuid.0, uuid.1) } +pub fn str_to_uuid(s: &str) -> Option<(u32, u32)> { + if let Some((uuid_0, uuid_1)) = s.split_once('_') { + let uuid_0 = if let Ok(uuid_0) = uuid_0.parse() { + uuid_0 + } else { + return None; + }; + let uuid_1 = if let Ok(uuid_1) = uuid_1.parse() { + uuid_1 + } else { + return None; + }; + Some((uuid_0, uuid_1)) + } else { + None + } +} + pub fn i64_as_uuid_str(num: i64) -> String { uuid_str(&i64_split(num)) } @@ -66,3 +84,7 @@ pub fn i64_join(uuid: (u32, u32)) -> i64 { bytes.1[0], bytes.1[1], bytes.1[2], bytes.1[3]] ) as i64 } + +pub fn str_to_i64(s :&str) -> Option { + str_to_uuid(s).map(i64_join) +} diff --git a/rc_core/src/persist/user/traits.rs b/rc_core/src/persist/user/traits.rs index 565e366..332c0ff 100644 --- a/rc_core/src/persist/user/traits.rs +++ b/rc_core/src/persist/user/traits.rs @@ -69,6 +69,9 @@ pub trait User: ChatUser { async fn save_slot_order(&self, slots: Vec) -> Result<(), i16>; async fn new_slot(&self, reset_slot: Option) -> Result, i16>; async fn upgrade_slot(&self, increments: i32) -> Result, i16>; + 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>; fn signup_date(&self) -> i64; async fn singleplayer_robots(&self) -> Result, i16>; async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result; @@ -124,6 +127,53 @@ pub struct VehicleUploadData { pub thumbnail: Vec, } +pub struct ControlData { + pub slot: i32, + pub control_ty: ControlType, + pub vertical_strafing: bool, + pub sideways_driving: bool, + pub tracks_turn_on_spot: bool, +} + +pub enum ControlType { + Camera = 0, + Keyboard = 1, + Count = 2, +} + +impl ControlType { + pub fn from_i32(i: i32) -> Result { + match i { + 0 => Ok(Self::Camera), + 1 => Ok(Self::Keyboard), + 2 => Ok(Self::Count), + _ => Err(crate::data::error_codes::WebServicesError::UnexpectedError as i16), + } + } + + #[inline] + pub(super) fn into_db(self) -> rc_database::schema::garage::ControlType { + match self { + Self::Camera => rc_database::schema::garage::ControlType::Camera, + Self::Keyboard => rc_database::schema::garage::ControlType::Keyboard, + Self::Count => rc_database::schema::garage::ControlType::Count, + } + } +} + +pub struct CustomisationData { + pub uuid: String, + pub bay: String, + pub spawn: String, + pub death: String, +} + +pub struct GetCustomisationData { + pub bay: polariton::operation::Typed, + pub spawn: polariton::operation::Typed, + pub death: polariton::operation::Typed, +} + pub struct GetAvatarInfo { pub avatar_id: polariton::operation::Typed, pub use_custom: polariton::operation::Typed, diff --git a/rc_database/src/migration/m20250526_000001_add_garage_customisation.rs b/rc_database/src/migration/m20250526_000001_add_garage_customisation.rs new file mode 100644 index 0000000..c390af8 --- /dev/null +++ b/rc_database/src/migration/m20250526_000001_add_garage_customisation.rs @@ -0,0 +1,54 @@ +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20250526_000001_add_garage_customisation" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + // Define how to apply this migration: Add death and spawn animation columns + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // sqlite adapter doesn't support multiple alter operations in one declaration + manager + .alter_table( + Table::alter() + .table(crate::schema::garage::Entity) + .add_column(ColumnDef::new(crate::schema::garage::Column::SpawnAnimationId).string().not_null().default("Spawn".to_owned())) + .to_owned() + ) + .await?; + manager + .alter_table( + Table::alter() + .table(crate::schema::garage::Entity) + .add_column(ColumnDef::new(crate::schema::garage::Column::DeathAnimationId).string().not_null().default("Explosion".to_owned())) + .to_owned() + ) + .await + + } + + // Define how to rollback this migration: Drop the added colums. + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(crate::schema::garage::Entity) + .drop_column(crate::schema::garage::Column::SpawnAnimationId) + .to_owned() + ) + .await?; + manager + .alter_table( + Table::alter() + .table(crate::schema::garage::Entity) + .drop_column(crate::schema::garage::Column::DeathAnimationId) + .to_owned() + ) + .await + } +} diff --git a/rc_database/src/migration/mod.rs b/rc_database/src/migration/mod.rs index 29fb197..6dd9348 100644 --- a/rc_database/src/migration/mod.rs +++ b/rc_database/src/migration/mod.rs @@ -5,6 +5,7 @@ mod m20250424_000002_create_user_permissions_table; mod m20250424_000003_create_garage_table; mod m20250424_000004_create_user_aux_table; mod m20250424_000005_create_campaign_tables; +mod m20250526_000001_add_garage_customisation; pub struct Migrator; @@ -17,6 +18,7 @@ impl MigratorTrait for Migrator { Box::new(m20250424_000003_create_garage_table::Migration), Box::new(m20250424_000004_create_user_aux_table::Migration), Box::new(m20250424_000005_create_campaign_tables::Migration), + Box::new(m20250526_000001_add_garage_customisation::Migration), ] } } diff --git a/rc_database/src/schema/garage.rs b/rc_database/src/schema/garage.rs index 14d9794..c803e43 100644 --- a/rc_database/src/schema/garage.rs +++ b/rc_database/src/schema/garage.rs @@ -21,11 +21,15 @@ pub struct Model { pub tutorial_robot: bool, pub starter_robot_index: Option, pub control_type: ControlType, + // control options pub vertical_strafing: bool, pub sideways_driving: bool, pub tracks_turn_on_spot: bool, + // end control options pub mastery_level: u32, pub bay_skin_id: String, + pub death_animation_id: String, + pub spawn_animation_id: String, pub weapon_order: String, // csv? pub robot_data: Vec, pub colour_data: Vec, diff --git a/rc_database/src/wrapper.rs b/rc_database/src/wrapper.rs index 7f5b309..22575f3 100644 --- a/rc_database/src/wrapper.rs +++ b/rc_database/src/wrapper.rs @@ -140,6 +140,13 @@ impl Database { .await } + pub async fn garage_by_uuid(&self, uuid: i64) -> Result, sea_orm::DbErr> { + crate::schema::garage::Entity::find() + .filter(crate::schema::garage::Column::Uuid.eq(uuid)) + .one(&self.orm) + .await + } + pub async fn insert_garages(&self, entities: Vec) -> Result<(), sea_orm::DbErr> { crate::schema::garage::Entity::insert_many(entities.into_iter()).exec(&self.orm).await?; Ok(()) @@ -175,6 +182,24 @@ impl Database { } } + pub async fn update_garage_by_uuid(&self, mut entity: crate::schema::garage::ActiveModel, uuid: i64) -> Result, sea_orm::DbErr> { + let id_opt = crate::schema::garage::Entity::find() + .select_only() + .column(crate::schema::garage::Column::Id) + .filter(crate::schema::garage::Column::Uuid.eq(uuid)) + .into_model::() + .one(&self.orm) + .await?; + if let Some(id) = id_opt { + entity.id = sea_orm::ActiveValue::Set(id.id); + Ok(Some(crate::schema::garage::Entity::update(entity) + .exec(&self.orm) + .await?)) + } else { + Ok(None) + } + } + pub async fn update_garage_selected_by_user_id_and_slot(&self, user_id: u32, slot: u32) -> Result<(), sea_orm::DbErr> { self.orm.transaction(|txn| { Box::pin(async move { diff --git a/rc_services_room/src/operations/all_customisations_info.rs b/rc_services_room/src/operations/all_customisations_info.rs index 41ebdde..1877a8b 100644 --- a/rc_services_room/src/operations/all_customisations_info.rs +++ b/rc_services_room/src/operations/all_customisations_info.rs @@ -12,150 +12,200 @@ const OWNED_SPAWNS_KEY: u8 = 232; const OWNED_DEATHS_KEY: u8 = 233; const OWNED_EMOTES_KEY: u8 = 76; +fn all_skins() -> Vec { + vec![ + /*CustomisationData { // level ??? + id: "RC_MothershipSkin_Premium_01".to_string(), + localised_name: "strMothershipSkinPremium".to_string(), + skin_scene_name: "RC_MothershipSkin_Neptune_01".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "TODO_preview_img".to_string(), + is_default: false, + },*/ + CustomisationData { // level13 + id: "RC_MothershipSkin_Neptune_01".to_string(), + localised_name: "strMothershipSkinNeptune01".to_string(), + skin_scene_name: "RC_MothershipSkin_Neptune_01".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "MothershipSkin_Neptune_BG".to_string(), + is_default: false, + }, + CustomisationData { // level 11 + id: "RC_MothershipSkin_Earth_01".to_string(), + localised_name: "strMothershipSkinEarth01".to_string(), + skin_scene_name: "RC_MothershipSkin_Earth_01".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "MothershipSkin_Earth_BG".to_string(), + is_default: false, + }, + CustomisationData { // level12 + id: "RC_MothershipSkin_Mars_01".to_string(), + localised_name: "strMothershipSkinMars01".to_string(), + skin_scene_name: "RC_MothershipSkin_Mars_01".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "MothershipSkin_Mars_BG".to_string(), + is_default: false, + }, + CustomisationData { // level14 + id: "RC_MothershipSkin_Retro_01".to_string(), + localised_name: "strMothershipSkinRetro01".to_string(), + skin_scene_name: "RC_MothershipSkin_Retro_01".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "MothershipSkin_Retro_BG".to_string(), + is_default: false, + }, + CustomisationData { // level2 (the is_default one seems to be special) + id: "RC_Mothership".to_string(), + localised_name: "strMothershipSkinDefault".to_string(), + skin_scene_name: "RC_Mothership".to_string(), + simulation_prefab: "TODO_sim_prefab".to_string(), + preview_image_name: "Mothership_Premium_BG".to_string(), // FIXME + is_default: true, + }, + ] +} + +fn all_spawns() -> Vec { + vec![ + CustomisationData { + id: "Spawn".to_string(), + localised_name: "strSpawnEffectDefault".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn".to_string(), + preview_image_name: "a".to_string(), + is_default: true, + }, + CustomisationData { + id: "Spawn_BlackHole".to_string(), + localised_name: "strSpawnFXBlackHole".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_BlackHole".to_string(), + preview_image_name: "Mothership_Premium_BG".to_string(), + is_default: false, + }, + CustomisationData { + id: "Spawn_Lander".to_string(), + localised_name: "strSpawnFXRoyaleLander".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_Lander".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Spawn_Lootcrate".to_string(), + localised_name: "strSpawnFXLootCrate".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_Lootcrate".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Spawn_Warp".to_string(), + localised_name: "strSpawnFXWarpIn".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_Warp".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Spawn_Present".to_string(), + localised_name: "strSpawnFXPresent".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_Present".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Spawn_EasterEgg".to_string(), + localised_name: "strSpawnFXHatch".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Spawn_EasterEgg".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + ] +} + +fn all_deaths() -> Vec { + vec![ + CustomisationData { + id: "Explosion".to_string(), + localised_name: "strDeathEffectDefault".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion".to_string(), + preview_image_name: "a".to_string(), + is_default: true, + }, + CustomisationData { + id: "Explosion_Toon".to_string(), + localised_name: "strDeathFXCartoonExplosion".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_Toon".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Explosion_Feathers_Rainbow".to_string(), + localised_name: "strDeathFXFeatherExplosion".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_Feathers_Rainbow".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Explosion_Nuclear".to_string(), + localised_name: "strDeathFXNuclearExplosion".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_Nuclear".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Explosion_Warp".to_string(), + localised_name: "strDeathFXEmergencyWarp".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_Warp".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Explosion_BlackHole".to_string(), + localised_name: "strDeathFXBlackHole".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_BlackHole".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + CustomisationData { + id: "Explosion_Firework".to_string(), + localised_name: "strDeathFXFireworkExplosion".to_string(), + skin_scene_name: "Splash_Loading_Screen".to_string(), + simulation_prefab: "Explosion_Firework".to_string(), + preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), + is_default: false, + }, + ] +} + pub(super) fn all_customisations_provider() -> SimpleFunc<216, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); params.insert(SKINS_KEY, Typed::Arr(Arr { ty: TypePrefix::HashMap, // hashtable - items: vec![ - CustomisationData { - id: "RC_MothershipSkin_Neptune_01".to_string(), - localised_name: "strNeptune".to_string(), - skin_scene_name: "RC_MothershipSkin_Neptune_01".to_string(), - simulation_prefab: "TODO_sim_prefab".to_string(), - preview_image_name: "TODO_preview_img".to_string(), - is_default: true, - }.as_transmissible(), - ], + items: all_skins().into_iter().map(|x| x.as_transmissible()).collect(), })); params.insert(SPAWNS_KEY, Typed::Arr(Arr { ty: TypePrefix::HashMap, // hashtable - items: vec![ - // TODO set these up with the correct values (IDs are correct) - CustomisationData { - id: "Spawn".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_BlackHole".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_BlackHole".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_Lander".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_Lander".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_Lootcrate".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_Lootcrate".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_Warp".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_Warp".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_Present".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_Present".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Spawn_EasterEgg".to_string(), - localised_name: "strSpawnFXWarpIn".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Spawn_EasterEgg".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - ], + items: all_spawns().into_iter().map(|x| x.as_transmissible()).collect(), })); params.insert(DEATHS_KEY, Typed::Arr(Arr { ty: TypePrefix::HashMap, // hashtable - items: vec![ - // TODO set these up with the correct values (IDs are correct) - CustomisationData { - id: "Explosion".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_Toon".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_Toon".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_Feathers_Rainbow".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_Feathers_Rainbow".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_Nuclear".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_Nuclear".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_Warp".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_Warp".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_BlackHole".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_BlackHole".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - CustomisationData { - id: "Explosion_Firework".to_string(), - localised_name: "strDeathFXEmergencyWarp".to_string(), - skin_scene_name: "Splash_Loading_Screen".to_string(), - simulation_prefab: "Explosion_Firework".to_string(), - preview_image_name: "RC_Splash_Screen_01_Japanese".to_string(), - is_default: true, - }.as_transmissible(), - ], + items: all_deaths().into_iter().map(|x| x.as_transmissible()).collect(), })); - params.insert(OWNED_SKINS_KEY, Typed::StrArr(vec![].into())); - params.insert(OWNED_SPAWNS_KEY, Typed::StrArr(vec![].into())); - params.insert(OWNED_DEATHS_KEY, Typed::StrArr(vec![].into())); + params.insert(OWNED_SKINS_KEY, Typed::StrArr(all_skins().into_iter().map(|x| x.id.into()).collect::>().into())); + params.insert(OWNED_SPAWNS_KEY, Typed::StrArr(all_spawns().into_iter().map(|x| x.id.into()).collect::>().into())); + params.insert(OWNED_DEATHS_KEY, Typed::StrArr(all_deaths().into_iter().map(|x| x.id.into()).collect::>().into())); params.insert(OWNED_EMOTES_KEY, Typed::StrArr(vec![].into())); Ok(params.into()) }) diff --git a/rc_services_room/src/operations/garage_slot_controls.rs b/rc_services_room/src/operations/garage_slot_controls.rs new file mode 100644 index 0000000..5697156 --- /dev/null +++ b/rc_services_room/src/operations/garage_slot_controls.rs @@ -0,0 +1,58 @@ +use polariton::operation::{ParameterTable, Typed, OperationResponse}; + +const CODE: u8 = 115; + +const INDEX_PARAM_KEY: u8 = 45; // int; in +const CONTROL_TY_PARAM_KEY: u8 = 59; // int (enum); in +const CONTROL_OPTIONS_PARAM_KEY: u8 = 60; // arr of bool (3); in + +pub(super) fn garage_slot_controls_provider() -> GarageSlotControlsSaveProvider { + GarageSlotControlsSaveProvider +} + +async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result { + let mut params = params.to_dict(); + if let Some(Typed::Int(index)) = params.remove(&INDEX_PARAM_KEY) { + if let Some(Typed::Int(control_ty)) = params.remove(&CONTROL_TY_PARAM_KEY) { + if let Some(Typed::Arr(control_options)) = params.remove(&CONTROL_OPTIONS_PARAM_KEY) { + let mut controls = rc_core::persist::user::ControlData { + slot: index, + control_ty: rc_core::persist::user::ControlType::from_i32(control_ty)?, + vertical_strafing: false, + sideways_driving: false, + tracks_turn_on_spot: false, + }; + for (i, val) in control_options.items.iter().enumerate() { + if let Typed::Bool(val) = val { + match i { + 0 => controls.vertical_strafing = *val, + 1 => controls.sideways_driving = *val, + 2 => controls.tracks_turn_on_spot = *val, + _ => log::warn!("Got too many options for setting garage slot controls"), + } + } + } + let user_info = user.user()?; + user_info.save_slot_controls(controls).await?; + } + } + } + Ok(params.into()) +} + +pub struct GarageSlotControlsSaveProvider; + +#[async_trait::async_trait] +impl polariton_server::operations::Operation<()> for GarageSlotControlsSaveProvider { + type User = crate::UserTy; + + async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> { + polariton_server::operations::result_to_op_resp::(do_handling(params, user).await) + } +} + +impl polariton_server::operations::OperationCode for GarageSlotControlsSaveProvider { + fn op_code() -> u8 { + CODE + } +} diff --git a/rc_services_room/src/operations/garage_slot_set_customisations.rs b/rc_services_room/src/operations/garage_slot_set_customisations.rs new file mode 100644 index 0000000..301266c --- /dev/null +++ b/rc_services_room/src/operations/garage_slot_set_customisations.rs @@ -0,0 +1,49 @@ +use polariton::operation::{ParameterTable, Typed, OperationResponse}; + +const CODE: u8 = 217; + +const UUID_PARAM_KEY: u8 = 54; // str; in +const BAY_SKIN_PARAM_KEY: u8 = 234; // str; in +const SPAWN_SKIN_PARAM_KEY: u8 = 235; // str; in +const DEATH_SKIN_PARAM_KEY: u8 = 236; // str; in + +pub(super) fn garage_slot_customisation_provider() -> GarageSlotCustomisationSaveProvider { + GarageSlotCustomisationSaveProvider +} + +async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result { + let mut params = params.to_dict(); + if let Some(Typed::Str(uuid)) = params.remove(&UUID_PARAM_KEY) { + if let Some(Typed::Str(bay_skin)) = params.remove(&BAY_SKIN_PARAM_KEY) { + if let Some(Typed::Str(spawn)) = params.remove(&SPAWN_SKIN_PARAM_KEY) { + if let Some(Typed::Str(death)) = params.remove(&DEATH_SKIN_PARAM_KEY) { + let user_info = user.user()?; + user_info.save_slot_customisations(rc_core::persist::user::CustomisationData { + uuid: uuid.string, + bay: bay_skin.string, + spawn: spawn.string, + death: death.string, + }).await?; + } + } + } + } + Ok(params.into()) +} + +pub struct GarageSlotCustomisationSaveProvider; + +#[async_trait::async_trait] +impl polariton_server::operations::Operation<()> for GarageSlotCustomisationSaveProvider { + type User = crate::UserTy; + + async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> { + polariton_server::operations::result_to_op_resp::(do_handling(params, user).await) + } +} + +impl polariton_server::operations::OperationCode for GarageSlotCustomisationSaveProvider { + fn op_code() -> u8 { + CODE + } +} diff --git a/rc_services_room/src/operations/mod.rs b/rc_services_room/src/operations/mod.rs index 50ce836..d6620a9 100644 --- a/rc_services_room/src/operations/mod.rs +++ b/rc_services_room/src/operations/mod.rs @@ -93,6 +93,8 @@ mod crf_purchase; mod crf_upload; mod avatar_set_custom; mod avatar_set; +mod garage_slot_controls; +mod garage_slot_set_customisations; use polariton_server::operations::OperationsHandler; @@ -208,4 +210,6 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler .add(crf_upload::crf_upload_provider(&init_ctx.factory)) .add(avatar_set_custom::custom_avatar_upload_handler()) .add(avatar_set::avatar_set_provider()) + .add(garage_slot_controls::garage_slot_controls_provider()) + .add(garage_slot_set_customisations::garage_slot_customisation_provider()) } diff --git a/rc_services_room/src/operations/robot_customisations.rs b/rc_services_room/src/operations/robot_customisations.rs index 8678776..9669060 100644 --- a/rc_services_room/src/operations/robot_customisations.rs +++ b/rc_services_room/src/operations/robot_customisations.rs @@ -1,17 +1,42 @@ -use polariton_server::operations::SimpleFunc; -use polariton::operation::{ParameterTable, Typed}; +use polariton::operation::{ParameterTable, Typed, OperationResponse}; -//const BAY_ID_KEY: u8 = 54; // in +const CODE: u8 = 218; + +const UUID_KEY: u8 = 54; // str; in const BAY_SKIN_KEY: u8 = 234; const SPAWN_EFFECT_KEY: u8 = 235; const DEATH_EFFECT_KEY: u8 = 236; -pub(super) fn bay_customisations_provider() -> SimpleFunc<218, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { - SimpleFunc::new(|params, _| { - let mut params = params.to_dict(); - params.insert(BAY_SKIN_KEY, Typed::Str("RC_MothershipSkin_Neptune_01".into())); - params.insert(SPAWN_EFFECT_KEY, Typed::Str("Spawn_Warp".into())); - params.insert(DEATH_EFFECT_KEY, Typed::Str("Explosion_Warp".into())); - Ok(params.into()) - }) +pub(super) fn bay_customisations_provider() -> GarageSlotCustomisationProvider { + GarageSlotCustomisationProvider +} + +async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result { + let mut params = params.to_dict(); + if let Some(Typed::Str(uuid)) = params.remove(&UUID_KEY) { + let user_info = user.user()?; + let customs = user_info.get_slot_customisations(&uuid.string).await?; + params.insert(BAY_SKIN_KEY, customs.bay); + params.insert(SPAWN_EFFECT_KEY, customs.spawn); + params.insert(DEATH_EFFECT_KEY, customs.death); + } + + Ok(params.into()) +} + +pub(super) struct GarageSlotCustomisationProvider; + +#[async_trait::async_trait] +impl polariton_server::operations::Operation<()> for GarageSlotCustomisationProvider { + type User = crate::UserTy; + + async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> { + polariton_server::operations::result_to_op_resp::(do_handling(params, user).await) + } +} + +impl polariton_server::operations::OperationCode for GarageSlotCustomisationProvider { + fn op_code() -> u8 { + CODE + } }