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

Add factory upload support to trait, make client handle rejections gracefully #6

This commit is contained in:
NG (Graham)
2025-05-18 21:52:03 -04:00
parent fd75dba80e
commit a0dba39475
12 changed files with 196 additions and 12 deletions

View File

@@ -470,4 +470,26 @@ impl <C: Clone> super::User<C> for UserData {
],
}.as_transmissible())
}
async fn prepare_factory_upload(&self, vehicle: super::VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16> {
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
})?.ok_or_else(|| {
log::error!("Failed to find vehicle slot {} for user_id {} (prepare_factory_upload)", vehicle.slot, self.account.id);
INVALID_ROBOT_ERR
})?;
Ok(rc_factory::VehicleUploadInfo {
name: vehicle.name,
description: vehicle.description,
thumbnail: vehicle.thumbnail,
added_by: self.account.public_id.clone(),
added_by_display_name: self.account.display_name.clone(),
cpu: slot.total_robot_cpu,
total_robot_ranking: slot.total_robot_ranking,
build_version: vehicle.version,
cube_data: slot.robot_data,
colour_data: slot.colour_data,
})
}
}

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};
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData};
pub const TOKEN_SECRET_FILENAME: &str = "token_secret.key";

View File

@@ -71,6 +71,7 @@ pub trait User<C> {
async fn upgrade_slot(&self, increments: i32) -> Result<polariton::operation::Typed<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>;
}
pub struct UserSlots<C> {
@@ -111,3 +112,11 @@ pub struct VehicleData {
pub weapon_order: Vec<i32>,
pub crf_id: Option<i32>,
}
pub struct VehicleUploadData {
pub version: String,
pub slot: i32,
pub name: String,
pub description: String,
pub thumbnail: Vec<u8>,
}