Implement factory in main database, close #80

This commit is contained in:
NG (Graham) committed 2026-02-01 18:14:16 -05:00
1 parent a346299de8
commit 3b909327d8
33 files changed
+741 -78

No files matched your search

@@ -0,0 +1,44 @@
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::{ParameterTable, Typed};
use oj_rc_factory::VehicleFactoryAdapter;
const CODE: u8 = 91;
const ID_PARAM_KEY: u8 = 94; // int; in
const EARNINGS_PARAM_KEY: u8 = 96;
pub(super) struct FactoryRemoveVehicle {
factory: std::sync::Arc<oj_rc_core::factory::Factory>,
}
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for FactoryRemoveVehicle {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, mut params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
if let Some(Typed::Int(factory_id)) = params.remove(&ID_PARAM_KEY) {
let user_info = user.user()?;
let user_id = user_info.account_id();
self.factory.remove_vehicle(factory_id, user_id).await.map_err(|e| {
log::error!("Failed to remove vehicle {} by user {} from factory: {}", factory_id, user_id, e);
SimpleOpError::with_message(
oj_rc_core::data::error_codes::WebServicesError::DatabaseError as i16,
format!("Failed to remove vehicle (for offset) from factory: {}", e)
)
})?;
}
// TODO Factory earnings
params.insert(EARNINGS_PARAM_KEY, Typed::HashMap(vec![
(Typed::Str("buyCount".into()), Typed::Int(0)),
(Typed::Str("earnings".into()), Typed::Int(0)),
].into()));
Ok(params)
}
}
pub(super) fn factory_remove_provider<C: Send + 'static>(factory: &std::sync::Arc<oj_rc_core::factory::Factory>) -> SimpleOpImpl<C, crate::UserTy, FactoryRemoveVehicle> {
SimpleOpImpl::new(FactoryRemoveVehicle {
factory: factory.to_owned()
})
}
+3
View File
@@ -106,6 +106,7 @@ mod crf_shift_vehicle;
mod crf_make_featured;
mod crf_unmake_featured;
mod tech_tree_unlock_cube;
mod crf_remove;
use polariton_server::operations::OperationsHandler;
@@ -236,4 +237,6 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
.add(crf_unmake_featured::factory_featured_provider(&init_ctx.factory))
.add(polariton_server::operations::Ack::<101, _>::default()) // RestoreCRFFeaturedRobot unused and also redundant???
.add(tech_tree_unlock_cube::tech_tree_cube_unlock_provider(&init_ctx.cubes))
.add(crf_remove::factory_remove_provider(&init_ctx.factory))
.add(polariton_server::operations::Ack::<94, _>::default()) // ReportCommunityShopItemRequest FIXME: log reports
}