mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Fix CPU number calculation and display in lots of places
This commit is contained in:
@@ -9,7 +9,7 @@ const SLOT_PARAM_KEY: u8 = 43; // in; int
|
||||
const FACTORY_ID_PARAM_KEY: u8 = 94; // in; int
|
||||
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &std::sync::Arc<oj_rc_core::factory::Factory>, weapon_order: &std::sync::Arc<oj_rc_core::cubes::WeaponListParser>) -> Result<ParameterTable, i16> {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory: &std::sync::Arc<oj_rc_core::factory::Factory>, weapon_order: &std::sync::Arc<oj_rc_core::cubes::WeaponListParser>, cpu_counter: &std::sync::Arc<oj_rc_core::cubes::CpuListParser>,) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
let slot = if let Some(Typed::Int(slot)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
@@ -37,7 +37,7 @@ async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory:
|
||||
weapon_order: weapons,
|
||||
crf_id: Some(factory_id),
|
||||
};
|
||||
user_info.save_slot(to_save).await?;
|
||||
user_info.save_slot(to_save, cpu_counter).await?;
|
||||
} else {
|
||||
log::warn!("Failed to retrieve (for copy-construct) non-existent factory vehicle {}", factory_id);
|
||||
return Err(oj_rc_core::data::error_codes::WebServicesError::DatabaseError as i16);
|
||||
@@ -51,6 +51,7 @@ async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, factory:
|
||||
pub struct CrfItemPurchaseProvider {
|
||||
factory: std::sync::Arc<oj_rc_core::factory::Factory>,
|
||||
weapon_order: std::sync::Arc<oj_rc_core::cubes::WeaponListParser>,
|
||||
cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -58,7 +59,7 @@ impl polariton_server::operations::Operation<()> for CrfItemPurchaseProvider {
|
||||
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, &self.factory, &self.weapon_order).await)
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_handling(params, user, &self.factory, &self.weapon_order, &self.cpu_counter).await)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +70,10 @@ impl polariton_server::operations::OperationCode for CrfItemPurchaseProvider {
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn crf_copy_to_bay_provider(factory: &std::sync::Arc<oj_rc_core::factory::Factory>, weapon_order: std::sync::Arc<oj_rc_core::cubes::WeaponListParser>) -> CrfItemPurchaseProvider {
|
||||
pub(super) fn crf_copy_to_bay_provider(factory: &std::sync::Arc<oj_rc_core::factory::Factory>, weapon_order: std::sync::Arc<oj_rc_core::cubes::WeaponListParser>, cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>) -> CrfItemPurchaseProvider {
|
||||
CrfItemPurchaseProvider {
|
||||
factory: factory.to_owned(),
|
||||
weapon_order,
|
||||
cpu_counter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,13 @@ const COMPRESSED_COLOUR_DATA_PARAM_KEY: u8 = 33; // byte arr
|
||||
|
||||
const INVALID_ROBOT_ERR: i16 = 140;
|
||||
|
||||
pub(super) fn garage_machine_save_provider() -> MachineSaver {
|
||||
MachineSaver
|
||||
pub(super) fn garage_machine_save_provider(cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>) -> MachineSaver {
|
||||
MachineSaver {
|
||||
cpu_counter
|
||||
}
|
||||
}
|
||||
|
||||
async fn do_save(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
async fn do_save(params: ParameterTable<()>, user: &crate::UserTy, cpu_counter: &std::sync::Arc<oj_rc_core::cubes::CpuListParser>) -> Result<ParameterTable, i16> {
|
||||
log::debug!("machine save params: {:?}", params);
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Int(slot_index)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
@@ -80,7 +82,7 @@ async fn do_save(params: ParameterTable<()>, user: &crate::UserTy) -> Result<Par
|
||||
weapon_order: weapon_order_filtered,
|
||||
crf_id: None,
|
||||
};
|
||||
user_info.save_slot(vehicle_data).await?;
|
||||
user_info.save_slot(vehicle_data, cpu_counter).await?;
|
||||
let mut params_out = std::collections::HashMap::with_capacity(1);
|
||||
params_out.insert(ERROR_PARAM_KEY, Typed::Int(0));
|
||||
return Ok(params_out.into());
|
||||
@@ -99,14 +101,16 @@ async fn do_save(params: ParameterTable<()>, user: &crate::UserTy) -> Result<Par
|
||||
Err(INVALID_ROBOT_ERR)
|
||||
}
|
||||
|
||||
pub struct MachineSaver;
|
||||
pub struct MachineSaver {
|
||||
cpu_counter: std::sync::Arc<oj_rc_core::cubes::CpuListParser>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for MachineSaver {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE_MACHINE_SAVER, ()>(do_save(params, user).await)
|
||||
polariton_server::operations::result_to_op_resp::<CODE_MACHINE_SAVER, ()>(do_save(params, user, &self.cpu_counter).await)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(building_xp::building_xp_save_provider())
|
||||
.add(robot_sanction::all_robot_sanctions_provider())
|
||||
.add(reconnect_game::available_reconnect_provider())
|
||||
.add(machine::garage_machine_save_provider())
|
||||
.add(machine::garage_machine_save_provider(init_ctx.parsers.cpu_counter()))
|
||||
.add(polariton_server::operations::Ack::<32, _>::default()) // TODO handle SaveMachineColorRequest instead of ignoring it
|
||||
.add(polariton_server::operations::Ack::<45, _>::default()) // TODO handle UpdateThumbnailVersionRequest instead of ignoring it
|
||||
.add(weapon_order::weapon_order_provider(&init_ctx.cubes))
|
||||
@@ -209,7 +209,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(crf_earnings::robot_shop_user_earnings_provider())
|
||||
.add(crf_list_query::crf_item_list_query_provider(&init_ctx.factory))
|
||||
.add(crf_vehicle_data::crf_item_data_provider(&init_ctx.factory))
|
||||
.add(crf_purchase::crf_copy_to_bay_provider(&init_ctx.factory, init_ctx.parsers.weapon_order()))
|
||||
.add(crf_purchase::crf_copy_to_bay_provider(&init_ctx.factory, init_ctx.parsers.weapon_order(), init_ctx.parsers.cpu_counter()))
|
||||
.add(crf_upload::crf_upload_provider(&init_ctx.factory))
|
||||
.add(avatar_set_custom::custom_avatar_upload_handler())
|
||||
.add(avatar_set::avatar_set_provider())
|
||||
|
||||
Reference in New Issue
Block a user