1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Configure all death, spawn, and garage bay skins for #3

This commit is contained in:
NG (Graham)
2025-05-26 21:30:28 -04:00
parent 956bb2149d
commit ab19c723cd
14 changed files with 584 additions and 143 deletions

View File

@@ -64,6 +64,17 @@ pub enum ControlType {
Count = 2,
}
impl std::convert::From<crate::persist::user::ControlType> 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,

View File

@@ -182,10 +182,27 @@ impl UserData {
async fn all_vehicles(&self) -> Result<Vec<rc_database::schema::garage::Model>, rc_database::sea_orm::DbErr> {
self.db.garages_by_user_id(self.account.id).await
}
async fn double_check_permissions(&self) -> Result<rc_database::schema::permissions::Model, rc_database::sea_orm::DbErr> {
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 <C: Clone> super::User<C> for UserData {
@@ -249,6 +266,7 @@ impl <C: Clone> super::User<C> 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 <C: Clone> super::User<C> for UserData {
}
async fn slot_by_id(&self, id: i32) -> Result<crate::persist::user::UserSlotData<C>, 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 <C: Clone> super::User<C> 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 <C: Clone> super::User<C> for UserData {
}
async fn save_slot_order(&self, slots: Vec<i32>) -> Result<(), i16> {
self.err_on_banned().await?;
let slots: Vec<u32> = 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 <C: Clone> super::User<C> for UserData {
}
async fn new_slot(&self, reset_slot: Option<i32>) -> Result<super::NewSlotData<C>, 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 <C: Clone> super::User<C> for UserData {
}
async fn upgrade_slot(&self, increments: i32) -> Result<polariton::operation::Typed<C>, i16> {
self.err_on_banned().await?;
if increments <= 0 {
// no-op
return Ok(polariton::operation::Typed::Bool(true));
@@ -432,11 +455,65 @@ impl <C: Clone> super::User<C> 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<super::GetCustomisationData<C>, 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<polariton::operation::Typed<C>, 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 <C: Clone> super::User<C> for UserData {
}
async fn prepare_factory_upload(&self, vehicle: super::VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16> {
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 <C: Clone> super::User<C> for UserData {
}
async fn last_seen(&self) -> Result<u64, i16> {
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 <C: Clone> super::User<C> for UserData {
}
async fn get_avatar_info(&self) -> Result<super::GetAvatarInfo<C>, 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 <C: Clone> super::User<C> 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()

View File

@@ -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<rc_database::schema::garage::Active
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]),

View File

@@ -11,7 +11,7 @@ mod inventory;
pub use inventory::UnlockedParts;
mod traits;
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser, AvatarInfo, GetAvatarInfo};
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser, AvatarInfo, GetAvatarInfo, ControlData, ControlType, CustomisationData, GetCustomisationData};
pub const TOKEN_SECRET_FILENAME: &str = "token_secret.key";
@@ -47,6 +47,24 @@ pub fn uuid_str(uuid: &(u32, u32)) -> 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<i64> {
str_to_uuid(s).map(i64_join)
}

View File

@@ -69,6 +69,9 @@ pub trait User<C>: ChatUser {
async fn save_slot_order(&self, slots: Vec<i32>) -> Result<(), i16>;
async fn new_slot(&self, reset_slot: Option<i32>) -> Result<NewSlotData<C>, i16>;
async fn upgrade_slot(&self, increments: i32) -> Result<polariton::operation::Typed<C>, 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<GetCustomisationData<C>, i16>;
fn signup_date(&self) -> i64;
async fn singleplayer_robots(&self) -> Result<polariton::operation::Typed<C>, i16>;
async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16>;
@@ -124,6 +127,53 @@ pub struct VehicleUploadData {
pub thumbnail: Vec<u8>,
}
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<Self, i16> {
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<C> {
pub bay: polariton::operation::Typed<C>,
pub spawn: polariton::operation::Typed<C>,
pub death: polariton::operation::Typed<C>,
}
pub struct GetAvatarInfo<C> {
pub avatar_id: polariton::operation::Typed<C>,
pub use_custom: polariton::operation::Typed<C>,

View File

@@ -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
}
}

View File

@@ -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),
]
}
}

View File

@@ -21,11 +21,15 @@ pub struct Model {
pub tutorial_robot: bool,
pub starter_robot_index: Option<u32>,
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<u8>,
pub colour_data: Vec<u8>,

View File

@@ -140,6 +140,13 @@ impl Database {
.await
}
pub async fn garage_by_uuid(&self, uuid: i64) -> Result<Option<crate::schema::garage::Model>, 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<crate::schema::garage::ActiveModel>) -> 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<Option<crate::schema::garage::Model>, 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::<crate::schema::common_query::Id>()
.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 {

View File

@@ -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<CustomisationData> {
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<CustomisationData> {
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<CustomisationData> {
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<ParameterTable, i16>) + 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::<Vec<_>>().into()));
params.insert(OWNED_SPAWNS_KEY, Typed::StrArr(all_spawns().into_iter().map(|x| x.id.into()).collect::<Vec<_>>().into()));
params.insert(OWNED_DEATHS_KEY, Typed::StrArr(all_deaths().into_iter().map(|x| x.id.into()).collect::<Vec<_>>().into()));
params.insert(OWNED_EMOTES_KEY, Typed::StrArr(vec![].into()));
Ok(params.into())
})

View File

@@ -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<ParameterTable, i16> {
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::<CODE, ()>(do_handling(params, user).await)
}
}
impl polariton_server::operations::OperationCode for GarageSlotControlsSaveProvider {
fn op_code() -> u8 {
CODE
}
}

View File

@@ -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<ParameterTable, i16> {
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::<CODE, ()>(do_handling(params, user).await)
}
}
impl polariton_server::operations::OperationCode for GarageSlotCustomisationSaveProvider {
fn op_code() -> u8 {
CODE
}
}

View File

@@ -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<crate::UserTy>
.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())
}

View File

@@ -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<ParameterTable, i16>) + 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<ParameterTable, i16> {
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::<CODE, ()>(do_handling(params, user).await)
}
}
impl polariton_server::operations::OperationCode for GarageSlotCustomisationProvider {
fn op_code() -> u8 {
CODE
}
}