1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00
Files
ojrc/rc_lobby_room/src/operations/join_queue.rs

65 lines
3.2 KiB
Rust

use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
use polariton::operation::{ParameterTable, Typed};
const CODE: u8 = 0;
const GROUP_ID_PARAM_KEY: u8 = 2; // str; in
const GARAGE_SLOT_PARAM_KEY: u8 = 3; // int; in
const GROUP_SIZE_PARAM_KEY: u8 = 4; // int; in
const IS_GROUP_LEADER_PARAM_KEY: u8 = 14; // bool; in
const LOBBY_TY_PARAM_KEY: u8 = 30; // int; in
const EVENT_TO_JOIN_PARAM_KEY: u8 = 41; // str; in
const ESTIMATED_QUEUE_TIME_PARAM_KEY: u8 = 13; // int (seconds); out
const PERSONAL_RANKING_PARAM_KEY: u8 = 17; // double; out
pub(super) struct QueueJoinProvider {
queue_handler: std::sync::Arc<crate::QueueHandler>,
}
#[async_trait::async_trait]
impl <C: Send + 'static> SimpleOperation<C> for QueueJoinProvider {
type User = crate::UserTy;
const CODE: u8 = CODE;
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
let mut params = params.to_dict();
if let Some(Typed::Str(group_id)) = params.remove(&GROUP_ID_PARAM_KEY) {
if let Some(Typed::Int(slot_id)) = params.remove(&GARAGE_SLOT_PARAM_KEY) {
if let Some(Typed::Int(group_size)) = params.remove(&GROUP_SIZE_PARAM_KEY) {
if let Some(Typed::Bool(is_leader)) = params.remove(&IS_GROUP_LEADER_PARAM_KEY) {
if let Some(Typed::Int(lobby_ty)) = params.remove(&LOBBY_TY_PARAM_KEY) {
let lobby_ty = oj_rc_core::data::lobby::LobbyType::from_int(lobby_ty)?;
if let Some(Typed::Str(event_to_join)) = params.remove(&EVENT_TO_JOIN_PARAM_KEY) {
log::debug!("Got lobby join queue request of platoon {} ({} players, is_leader:{}) slot {} lobby {:?} event {}", group_id.string, group_size, is_leader, slot_id, lobby_ty, event_to_join.string);
params.insert(ESTIMATED_QUEUE_TIME_PARAM_KEY, Typed::Int(42));
params.insert(PERSONAL_RANKING_PARAM_KEY, Typed::Double(42.0));
let events = user.event_sender();
let user_info = user.user()?;
if let Some(current_lobby) = user_info.current_game_event_setter().get_multiplayer().await {
self.queue_handler.join_queue(
current_lobby.map,
current_lobby.mode,
current_lobby.visibility,
current_lobby.auto_heal,
user_info.as_ref().as_ref(),
events.to_owned(),
).await;
}
}
}
}
}
}
}
Ok(params.into())
}
}
pub(super) fn join_queue_provider<C: Send + 'static>(queue_handler: &std::sync::Arc<crate::QueueHandler>) -> SimpleOpImpl<C, crate::UserTy, QueueJoinProvider> {
SimpleOpImpl::new(QueueJoinProvider {
queue_handler: queue_handler.to_owned(),
})
}