mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement factory in main database, close #80
This commit is contained in:
@@ -33,7 +33,7 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
let cubes = oj_rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(oj_rc_core::persist::user::UserImpl::load(&args.data, &cubes).await.expect("Bad user data"));
|
||||
let factory = std::sync::Arc::new(<oj_rc_core::persist::config::ConfigImpl as oj_rc_core::ConfigProvider<()>>::factory::<'_, '_>(&cubes).await.expect("Bad vehicle factory (CRF) config"));
|
||||
let factory = std::sync::Arc::new(<oj_rc_core::persist::config::ConfigImpl as oj_rc_core::ConfigProvider<()>>::factory(&cubes, &|| users.factory_impl()).await.expect("Bad vehicle factory (CRF) config"));
|
||||
let parsers = oj_rc_core::cubes::CubeParsers::new(&cubes);
|
||||
let init_ctx = std::sync::Arc::new(InitConfig {
|
||||
cubes,
|
||||
|
||||
44
rc_services_room/src/operations/crf_remove.rs
Normal file
44
rc_services_room/src/operations/crf_remove.rs
Normal file
@@ -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()
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user