mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add singleplayer and campaign rewards screens #70
This commit is contained in:
46
rc_services_room/src/operations/campaign_save_result.rs
Normal file
46
rc_services_room/src/operations/campaign_save_result.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const GAME_RESULT_PARAM_KEY: u8 = 82; // bytes; in
|
||||
const CAMPAIGN_ID_PARAM_KEY: u8 = 22; // string; in
|
||||
const DIFFICULTY_PARAM_KEY: u8 = 23; // int; in
|
||||
const LONG_PLAY_PARAM_KEY: u8 = 84; // float; in
|
||||
const GUID_PARAM_KEY: u8 = 85; // string; in
|
||||
|
||||
const CODE: u8 = 78;
|
||||
|
||||
// SaveCampaignGameAwardsRequest
|
||||
pub(super) struct CampaignGameAwardsSaver;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for CampaignGameAwardsSaver {
|
||||
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::Bytes(game_result)) = params.remove(&GAME_RESULT_PARAM_KEY) {
|
||||
let mut result_cursor = std::io::Cursor::new(game_result.vec);
|
||||
let game_result = oj_rc_core::data::game_result::GameResult::parse(&mut result_cursor)
|
||||
.map_err(|e| SimpleOpError::with_message(
|
||||
oj_rc_core::data::error_codes::SingleplayerErrorCode::UnexpectedError as i16,
|
||||
format!("Bad game result serialization: {}", e),
|
||||
))?;
|
||||
if let Some(Typed::Float(_long_play)) = params.remove(&LONG_PLAY_PARAM_KEY) {
|
||||
if let Some(Typed::Str(_campaign_id)) = params.remove(&CAMPAIGN_ID_PARAM_KEY) {
|
||||
if let Some(Typed::Int(_difficulty)) = params.remove(&DIFFICULTY_PARAM_KEY) {
|
||||
if let Some(Typed::Str(game_guid)) = params.remove(&GUID_PARAM_KEY) {
|
||||
let user_info = user.user()?;
|
||||
user_info.save_game_result(&game_guid.string, game_result).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ParameterTable::with_capacity(1)) // parameter-less response
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn campaign_save_awards_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, CampaignGameAwardsSaver> {
|
||||
SimpleOpImpl::new(CampaignGameAwardsSaver)
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ mod garage_slot_set_customisations;
|
||||
mod garage_slot_name;
|
||||
mod garage_slot_copy;
|
||||
mod steam_promo;
|
||||
mod campaign_save_result;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -199,7 +200,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.add(player_robot_rank::player_robot_rank_provider())
|
||||
.add(validate_machine::validate_campaign_robot_provider())
|
||||
.add(singleplayer_campaigns::singleplayer_complete_campaign_provider(init_ctx))
|
||||
.add(polariton_server::operations::Ack::<78, _>::default()) // TODO handle SaveCampaignGameAwardsRequest instead of ignoring it
|
||||
.add(campaign_save_result::campaign_save_awards_provider())
|
||||
.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())
|
||||
|
||||
Reference in New Issue
Block a user