mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement non-multiplayer parts of custom games
This commit is contained in:
1 parent
6ce456a739
commit
af04c4093c
34 files changed
+1751
-78
No files matched your search
@@ -36,6 +36,7 @@ mod clan_invite_decline_all;
|
||||
mod clan_invite_cancel;
|
||||
mod clan_member_rerank;
|
||||
mod clan_experience_poll;
|
||||
mod user_can_be_custom_gamed;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -66,6 +67,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy,
|
||||
.add(friend_remove::friend_remove_provider(init_ctx))
|
||||
.add(platoon_invite_to::platoon_invite_provider(init_ctx))
|
||||
.add(user_can_be_platooned::can_invite_to_platoon_provider(init_ctx))
|
||||
.add(user_can_be_custom_gamed::can_invite_to_custom_game_provider(init_ctx))
|
||||
.add(platoon_invite_accept::platoon_accepter_provider(init_ctx))
|
||||
.add(platoon_invite_decline::platoon_decliner_provider(init_ctx))
|
||||
.add(platoon_leave::platoon_leave_provider(init_ctx))
|
||||
|
||||
@@ -96,25 +96,26 @@ impl SimpleOperation<crate::data::custom::CustomType> for PlatoonInviter {
|
||||
}
|
||||
} else {
|
||||
// create new platoon
|
||||
let platoon_id = format!("{}-{}", user_info.public_id(), chrono::Utc::now().timestamp());
|
||||
log::debug!("Creating new platoon {} for user {} to invite {}", platoon_id, user_info.public_id(), username.string);
|
||||
let social_infos = user_info.list_social_info(&[
|
||||
username.string.clone(),
|
||||
user_info.public_id().to_owned(),
|
||||
]).await?;
|
||||
if social_infos.len() != 2 {
|
||||
log::debug!("User {} info could not be retrieved while creating platoon {}", username.string, platoon_id);
|
||||
log::debug!("User {} info could not be retrieved while creating new platoon", username.string);
|
||||
return Err(SimpleOpError::with_message(
|
||||
oj_rc_core::data::error_codes::SocialErrorCode::UserDoesNotExist as i16,
|
||||
"User's info could not be retrieved".to_owned(),
|
||||
));
|
||||
}
|
||||
if self.social.create_platoon(&platoon_id, user_info.public_id()).await.is_none() {
|
||||
let platoon_id = if let Some((_, platoon_key)) = self.social.create_platoon(user_info.public_id()).await {
|
||||
log::debug!("Created new platoon {} for user {} to invite {}", platoon_key, user_info.public_id(), username.string);
|
||||
platoon_key
|
||||
} else {
|
||||
return Err(SimpleOpError::with_message(
|
||||
oj_rc_core::data::error_codes::SocialErrorCode::UserNotInPlatoon as i16,
|
||||
"Failed to create platoon".to_owned(),
|
||||
));
|
||||
}
|
||||
};
|
||||
if let Some(timestamp) = self.social.add_user_to_platoon(&username.string, &platoon_id, crate::data::platoon::MemberStatus::Invited).await {
|
||||
(platoon_id, social_infos, timestamp)
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 58;
|
||||
|
||||
const USERNAME_PARAM_KEY: u8 = 65; // str; in
|
||||
const RESPONSE_CODE_PARAM_KEY: u8 = 66; // bool; out
|
||||
|
||||
pub(super) struct UserCanBeInvitedToCustoGameGetter {
|
||||
social: std::sync::Arc<crate::SocialMesh>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SimpleOperation<crate::data::custom::CustomType> for UserCanBeInvitedToCustoGameGetter {
|
||||
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::Bool(false));
|
||||
return Ok(params);
|
||||
}
|
||||
if self.social.platoon_of_user(&username.string).await.is_some() {
|
||||
params.insert(RESPONSE_CODE_PARAM_KEY, Typed::Bool(false));
|
||||
return Ok(params);
|
||||
}
|
||||
params.insert(RESPONSE_CODE_PARAM_KEY, Typed::Bool(true));
|
||||
}
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn can_invite_to_custom_game_provider(init_ctx: &crate::InitConfig) -> SimpleOpImpl<crate::data::custom::CustomType, crate::UserTy, UserCanBeInvitedToCustoGameGetter> {
|
||||
SimpleOpImpl::new(UserCanBeInvitedToCustoGameGetter {
|
||||
social: init_ctx.social.clone(),
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user