mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add minimum matchmaking lobby server
This commit is contained in:
47
rc_lobby_room/src/operations/join_queue.rs
Normal file
47
rc_lobby_room/src/operations/join_queue.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
|
||||
#[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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(params.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn join_queue_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, QueueJoinProvider> {
|
||||
SimpleOpImpl::new(QueueJoinProvider)
|
||||
}
|
||||
Reference in New Issue
Block a user