mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add garage add, select, and re-order operations for #14
This commit is contained in:
52
rc_services_room/src/operations/garage_slot_add.rs
Normal file
52
rc_services_room/src/operations/garage_slot_add.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 38;
|
||||
|
||||
const SLOT_REUSE_PARAM_KEY: u8 = 43; // int; in
|
||||
const SLOT_PARAM_KEY: u8 = 45; // uint
|
||||
const UUID_0_PARAM_KEY: u8 = 40; // str of uint
|
||||
const UUID_1_PARAM_KEY: u8 = 41; // str of uint
|
||||
const NAME_PARAM_KEY: u8 = 42; // str
|
||||
const DEFAULT_BAY_CPU_PARAM_KEY: u8 = 8; // int
|
||||
const MASTERY_LEVEL_PARAM_KEY: u8 = 18; // int
|
||||
|
||||
pub(super) fn garage_slot_add_provider() -> SlotCreator {
|
||||
SlotCreator
|
||||
}
|
||||
|
||||
async fn do_add(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
let reset_slot = if let Some(Typed::Int(reuse_garage_slot)) = params.get(&SLOT_REUSE_PARAM_KEY) {
|
||||
// reset existing garage slot
|
||||
Some(*reuse_garage_slot)
|
||||
} else {
|
||||
// create new garage slot
|
||||
None
|
||||
};
|
||||
let new_slot = user_info.new_slot(reset_slot).await?;
|
||||
params.insert(SLOT_PARAM_KEY, new_slot.slot);
|
||||
params.insert(UUID_0_PARAM_KEY, new_slot.uuid_0);
|
||||
params.insert(UUID_1_PARAM_KEY, new_slot.uuid_1);
|
||||
params.insert(MASTERY_LEVEL_PARAM_KEY, new_slot.mastery_level);
|
||||
params.insert(NAME_PARAM_KEY, new_slot.name);
|
||||
params.insert(DEFAULT_BAY_CPU_PARAM_KEY, new_slot.bay_cpu);
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct SlotCreator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for SlotCreator {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_add(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for SlotCreator {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
14
rc_services_room/src/operations/garage_slot_limit.rs
Normal file
14
rc_services_room/src/operations/garage_slot_limit.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use polariton_server::operations::Immediate;
|
||||
|
||||
//use rc_core::ConfigProvider;
|
||||
|
||||
const PARAM_KEY: u8 = 68;
|
||||
|
||||
pub(super) fn garage_slots_limit(_conf: &rc_core::ConfigImpl) -> Immediate<60, crate::UserTy> {
|
||||
//let limit = conf.game_mode_config();
|
||||
Immediate::new(move || {
|
||||
let mut params = std::collections::HashMap::with_capacity(1);
|
||||
params.insert(PARAM_KEY, polariton::operation::Typed::Int(100));
|
||||
params.into()
|
||||
})
|
||||
}
|
||||
35
rc_services_room/src/operations/garage_slot_select.rs
Normal file
35
rc_services_room/src/operations/garage_slot_select.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 44;
|
||||
|
||||
const SLOT_PARAM_KEY: u8 = 48; // uint; in
|
||||
|
||||
pub(super) fn garage_slot_selector() -> SlotSelector {
|
||||
SlotSelector
|
||||
}
|
||||
|
||||
async fn do_select(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
let user_info = user.user()?;
|
||||
if let Some(Typed::Int(to_select)) = params.remove(&SLOT_PARAM_KEY) {
|
||||
user_info.select_garage(to_select).await?;
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct SlotSelector;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for SlotSelector {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> {
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(do_select(params, user).await)
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_server::operations::OperationCode for SlotSelector {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ pub(super) fn garage_slot_provider() -> GarageSlotsProvider {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let user_info = user.user()?;
|
||||
let mut params = params.to_dict();
|
||||
let all_slots = user_info.all_slots_by_id().await;
|
||||
let all_slots = user_info.all_slots().await;
|
||||
params.insert(SLOTS_PARAM_KEY, all_slots.slot_info);
|
||||
params.insert(SELECTED_SLOT_PARAM_KEY, Typed::Int(user_info.selected_garage().await.1 as _));
|
||||
params.insert(SLOT_ORDER_PARAM_KEY, all_slots.slot_order);
|
||||
|
||||
42
rc_services_room/src/operations/garage_slots_order.rs
Normal file
42
rc_services_room/src/operations/garage_slots_order.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use polariton::operation::{ParameterTable, Typed, OperationResponse};
|
||||
|
||||
const CODE: u8 = 114;
|
||||
|
||||
const SLOT_ORDER_PARAM_KEY: u8 = 58;
|
||||
|
||||
pub(super) fn garage_slot_order_provider() -> GarageSlotsOrderProvider {
|
||||
GarageSlotsOrderProvider
|
||||
}
|
||||
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result<ParameterTable, i16> {
|
||||
let mut params = params.to_dict();
|
||||
if let Some(Typed::Arr(order)) = params.remove(&SLOT_ORDER_PARAM_KEY) {
|
||||
log::info!("Slot order is {}", order);
|
||||
let mut order_i32 = Vec::with_capacity(order.items.len());
|
||||
for item in order.items.iter() {
|
||||
if let Typed::Int(item) = item {
|
||||
order_i32.push(*item);
|
||||
}
|
||||
}
|
||||
let user_info = user.user()?;
|
||||
user_info.save_slot_order(order_i32).await?;
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
|
||||
pub struct GarageSlotsOrderProvider;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl polariton_server::operations::Operation<()> for GarageSlotsOrderProvider {
|
||||
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 GarageSlotsOrderProvider {
|
||||
fn op_code() -> u8 {
|
||||
CODE
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@ mod game_mode_config;
|
||||
mod score_multipliers_config;
|
||||
mod player_robot_rank;
|
||||
mod weapon_order;
|
||||
mod garage_slot_limit;
|
||||
mod garage_slot_add;
|
||||
mod garage_slots_order;
|
||||
mod garage_slot_select;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -182,4 +186,8 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(singleplayer_campaigns::singleplayer_complete_campaign_provider(&init_ctx.cubes))
|
||||
.add(polariton_server::operations::Ack::<78, _>::default()) // TODO handle SaveCampaignGameAwardsRequest instead of ignoring it
|
||||
.add(singleplayer_campaigns::singleplayer_save_complete_campaign_provider()) // TODO handle UpdatePlayerCompletedCampaignWaveRequest saving
|
||||
.add(garage_slot_limit::garage_slots_limit(&init_ctx.cubes))
|
||||
.add(garage_slot_add::garage_slot_add_provider())
|
||||
.add(garage_slots_order::garage_slot_order_provider())
|
||||
.add(garage_slot_select::garage_slot_selector())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user