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:
@@ -194,4 +194,22 @@ impl MapVisibility {
|
||||
Self::Bad => oj_rc_database::schema::multiplayer_game::MapVisibility::Bad,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_u8(num: u8) -> Option<Self> {
|
||||
match num {
|
||||
0 => Some(Self::Good),
|
||||
1 => Some(Self::Poor),
|
||||
2 => Some(Self::Bad),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Good => "Good",
|
||||
Self::Poor => "Poor",
|
||||
Self::Bad => "VeryPoor",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,3 +112,16 @@ impl PlayerDatas {
|
||||
Typed::Bytes(buf.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AvatarInfo {
|
||||
pub avatar_id: Option<i32>,
|
||||
}
|
||||
|
||||
impl AvatarInfo {
|
||||
pub fn as_transmissible<C>(&self) -> Typed<C> {
|
||||
Typed::HashMap(vec![
|
||||
(Typed::Str("useCustomAvatar".into()), Typed::Bool(self.avatar_id.is_none())),
|
||||
(Typed::Str("avatarId".into()), Typed::Int(self.avatar_id.unwrap_or(0))),
|
||||
].into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1331,6 +1331,37 @@ impl <C: Clone + Send> super::User<C> for UserData {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_avatar_info(&self, public_ids: &[String]) -> Result<Vec<super::SocialInfo>, polariton_server::operations::SimpleOpError> {
|
||||
let users = self.db.users_by_public_id(public_ids.iter()).await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to retrieve friend avatars for user {} : {}", self.account.id, e);
|
||||
polariton_server::operations::SimpleOpError::with_message(
|
||||
crate::data::error_codes::WebServicesError::DatabaseError as i16,
|
||||
format!("Failed to retrieve friend avatars: {}", e),
|
||||
)
|
||||
})?;
|
||||
let user_ids = users.iter().map(|user| user.id);
|
||||
let user_avatars = self.db.user_auxs_by_user_ids_and_descriptor(user_ids, oj_rc_database::schema::user_aux::Descriptor::AvatarId).await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to retrieve friend avatars for user {} : {}", self.account.id, e);
|
||||
polariton_server::operations::SimpleOpError::with_message(
|
||||
crate::data::error_codes::WebServicesError::DatabaseError as i16,
|
||||
format!("Failed to retrieve friend avatars: {}", e),
|
||||
)
|
||||
})?;
|
||||
let avatar_map: std::collections::HashMap<i32, u32> = user_avatars.iter()
|
||||
.filter_map(|avatar| avatar.data.parse().ok().map(|avatar_id| (avatar.user_id, avatar_id)))
|
||||
.collect();
|
||||
Ok(users.iter()
|
||||
.map(|user| super::SocialInfo {
|
||||
public_id: user.public_id.clone(),
|
||||
display_name: user.display_name.clone(),
|
||||
avatar_id: avatar_map.get(&user.id).and_then(|&avatar_id| if avatar_id == u32::MAX { None } else { Some(avatar_id as i32) }),
|
||||
})
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
fn current_game_event_setter(&self) -> Box<dyn super::GameEventSetter> {
|
||||
Box::new(GameEventSetterImpl {
|
||||
db: self.db.clone(),
|
||||
|
||||
@@ -95,6 +95,7 @@ pub trait User<C>: ChatUser + SocialUser + SocialUserC<C> + LobbyUser + Multipla
|
||||
async fn last_seen(&self) -> Result<u64, i16>;
|
||||
async fn get_avatar_info(&self) -> Result<GetAvatarInfo<C>, i16>;
|
||||
async fn set_avatar_info(&self, info: AvatarInfo) -> Result<(), i16>;
|
||||
async fn list_avatar_info(&self, public_ids: &[String]) -> Result<Vec<SocialInfo>, polariton_server::operations::SimpleOpError>;
|
||||
fn current_game_event_setter(&self) -> Box<dyn GameEventSetter>;
|
||||
async fn apply_purchase(&self, action: &crate::persist::config::ShopAction) -> Result<PurchaseResult, polariton_server::operations::SimpleOpError>;
|
||||
async fn currency_debit(&self, ty: CurrencyType, to_sub: u64) -> Result<(), polariton_server::operations::SimpleOpError>;
|
||||
|
||||
Reference in New Issue
Block a user