mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Platoons social functionality (#91)
### Description This implements and completes #87 (to the best of my knowledge) ### Game Robocraft ### Please confirm - [x] I am the legal owner or represent the owner of all work submitted - [x] I consent to my submission being added to this FOSS project - [ ] This PR used LLMs to generate some or all of the code changes Reviewed-on: https://git.ngram.ca/OpenJam/rc-servers/pulls/91 Co-authored-by: NG (Graham) <ngniusness@gmail.com> Co-committed-by: NG (Graham) <ngniusness@gmail.com>
This commit is contained in:
52
rc_social_room/src/operations/user_can_be_platooned.rs
Normal file
52
rc_social_room/src/operations/user_can_be_platooned.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(u8)]
|
||||
enum ResponseCode {
|
||||
Ok = 0,
|
||||
InCustomGame = 1,
|
||||
OutstandingCustomInvite = 2,
|
||||
Error = 3,
|
||||
PlayerDoesNotExist = 4,
|
||||
}
|
||||
|
||||
const CODE: u8 = 59;
|
||||
|
||||
const USERNAME_PARAM_KEY: u8 = 65; // str; in
|
||||
const RESPONSE_CODE_PARAM_KEY: u8 = 66; // bool; out
|
||||
|
||||
pub(super) struct UserCanBeInvitedToPlatoonGetter {
|
||||
social: std::sync::Arc<crate::SocialMesh>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SimpleOperation<crate::data::custom::CustomType> for UserCanBeInvitedToPlatoonGetter {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, mut params: ParameterTable<crate::data::custom::CustomType>, user: &Self::User) -> Result<ParameterTable<crate::data::custom::CustomType>, SimpleOpError> {
|
||||
if let Some(Typed::Str(username)) = params.remove(&USERNAME_PARAM_KEY) {
|
||||
let _user_info = user.user()?; // just to validate request is authenticated
|
||||
let mut set = std::collections::HashSet::with_capacity(1);
|
||||
set.insert(username.string.clone());
|
||||
self.social.filter_online_only(&mut set).await;
|
||||
if set.is_empty() {
|
||||
params.insert(RESPONSE_CODE_PARAM_KEY, Typed::Int(ResponseCode::Error as i32));
|
||||
return Ok(params);
|
||||
}
|
||||
/*if self.social.platoon_of_user(&username.string).await.is_some() {
|
||||
params.insert(RESPONSE_CODE_PARAM_KEY, Typed::Int(ResponseCode::OutstandingCustomInvite as i32));
|
||||
return Ok(params);
|
||||
}*/
|
||||
params.insert(RESPONSE_CODE_PARAM_KEY, Typed::Int(ResponseCode::Ok as i32));
|
||||
}
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn can_invite_to_platoon_provider(init_ctx: &crate::InitConfig) -> SimpleOpImpl<crate::data::custom::CustomType, crate::UserTy, UserCanBeInvitedToPlatoonGetter> {
|
||||
SimpleOpImpl::new(UserCanBeInvitedToPlatoonGetter {
|
||||
social: init_ctx.social.clone(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user