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:
1 parent
5e2a915892
commit
4baa1ef911
23 files changed
+851
-6
No files matched your search
@@ -0,0 +1,22 @@
|
||||
use polariton_server::operations::{Operation, OperationCode};
|
||||
|
||||
pub struct EacChallengeIgnorer;
|
||||
|
||||
impl <C: Send + 'static> Operation<C> for EacChallengeIgnorer {
|
||||
type User = crate::UserTy;
|
||||
|
||||
fn handle(&self, params: polariton::operation::ParameterTable<C>, _: &Self::User) -> polariton::operation::OperationResponse<C> {
|
||||
polariton::operation::OperationResponse {
|
||||
code: 5, // skip the challenge (hopefully)
|
||||
return_code: 0,
|
||||
message: polariton::operation::Typed::Null,
|
||||
params,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OperationCode for EacChallengeIgnorer {
|
||||
fn op_code() -> u8 {
|
||||
4
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
mod more_auth;
|
||||
mod eac;
|
||||
mod no_quit;
|
||||
mod join_queue;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
pub fn handler(_init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy> {
|
||||
OperationsHandler::<crate::UserTy>::new()
|
||||
.modify(oj_rc_core::polariton::OpIdCopy)
|
||||
.add(more_auth::MoreLobbyAuth)
|
||||
//.add(eac::EacChallengeIgnorer)
|
||||
//.add(polariton_server::operations::Ack::<2, _>::default())
|
||||
.add(no_quit::quit_blocker_provider())
|
||||
.add(join_queue::join_queue_provider())
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
use polariton::operation::Typed;
|
||||
use polariton_server::operations::{Operation, OperationCode};
|
||||
|
||||
pub struct MoreLobbyAuth;
|
||||
|
||||
impl MoreLobbyAuth {
|
||||
const AUTH_PAYLOAD_KEY: u8 = 245;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> Operation<C> for MoreLobbyAuth {
|
||||
type User = crate::UserTy;
|
||||
|
||||
async fn handle_async(&self, params: polariton::operation::ParameterTable<C>, user: &Self::User) -> polariton::operation::OperationResponse<C> {
|
||||
let params_dict = params.to_dict();
|
||||
if let Some(Typed::Str(auth_payload)) = params_dict.get(&Self::AUTH_PAYLOAD_KEY) {
|
||||
//let mut write_lock = user.write().unwrap();
|
||||
if user.update_with_auth(&auth_payload.string).await {
|
||||
let mut resp_params = std::collections::HashMap::new();
|
||||
resp_params.insert(Self::AUTH_PAYLOAD_KEY, polariton::operation::Typed::Byte(0));
|
||||
return polariton::operation::OperationResponse {
|
||||
code: Self::op_code(),
|
||||
return_code: 0,
|
||||
message: polariton::operation::Typed::Null,
|
||||
params: resp_params.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
polariton::operation::OperationResponse {
|
||||
code: Self::op_code(),
|
||||
return_code: 120,
|
||||
message: polariton::operation::Typed::Null,
|
||||
params: std::collections::HashMap::new().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OperationCode for MoreLobbyAuth {
|
||||
fn op_code() -> u8 {
|
||||
230
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 3;
|
||||
|
||||
const DID_QUIT_LAST_GAME_PARAM_KEY: u8 = 19; // bool
|
||||
const BLOCK_TIME_PARAM_KEY: u8 = 15; // int
|
||||
|
||||
pub(super) struct QuitterBlockProvider;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for QuitterBlockProvider {
|
||||
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();
|
||||
params.insert(DID_QUIT_LAST_GAME_PARAM_KEY, Typed::Bool(false));
|
||||
params.insert(BLOCK_TIME_PARAM_KEY, Typed::Int(0));
|
||||
Ok(params.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn quit_blocker_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, QuitterBlockProvider> {
|
||||
SimpleOpImpl::new(QuitterBlockProvider)
|
||||
}
|
||||
Reference in new issue
Block a user