mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Move chat system into core, merge configs, save to database
This commit is contained in:
85
rc_core/src/data/channel.rs
Normal file
85
rc_core/src/data/channel.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use polariton::operation::{Typed, Arr};
|
||||
|
||||
pub struct ChatChannelInfo {
|
||||
pub channel_name: String,
|
||||
pub members: Vec<ChatChannelMember>,
|
||||
pub channel_ty: ChatChannelType,
|
||||
}
|
||||
|
||||
impl ChatChannelInfo {
|
||||
pub fn as_transmissible(&self) -> Typed {
|
||||
Typed::HashMap(vec![
|
||||
(Typed::Str("channelName".into()), Typed::Str(self.channel_name.clone().into())),
|
||||
(Typed::Str("members".into()), Typed::Arr(Arr {
|
||||
ty: polariton::serdes::TypePrefix::HashMap, // hashtable
|
||||
items: self.members.iter().map(|x| x.as_transmissible()).collect(),
|
||||
})),
|
||||
(Typed::Str("channelType".into()), Typed::Int(self.channel_ty as _)),
|
||||
].into())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChatChannelMember {
|
||||
pub name: String,
|
||||
pub use_custom_avatar: bool,
|
||||
pub state: ChatPlayerState,
|
||||
pub custom_avatar: Vec<u8>, // always PNG?
|
||||
pub avatar_id: i32,
|
||||
}
|
||||
|
||||
impl ChatChannelMember {
|
||||
pub fn as_transmissible(&self) -> Typed {
|
||||
Typed::HashMap(vec![
|
||||
(Typed::Str("name".into()), Typed::Str(self.name.clone().into())),
|
||||
(Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())),
|
||||
(Typed::Str("state".into()), Typed::Int(self.state as _)),
|
||||
if self.use_custom_avatar {
|
||||
(Typed::Str("customAvatar".into()), Typed::Bytes(self.custom_avatar.clone().into()))
|
||||
} else {
|
||||
(Typed::Str("avatarId".into()), Typed::Int(self.avatar_id))
|
||||
},
|
||||
].into())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
|
||||
pub enum ChatChannelType {
|
||||
None = 0,
|
||||
Public = 1,
|
||||
Battle = 2,
|
||||
BattleTeam = 3,
|
||||
Platoon = 4,
|
||||
Custom = 5,
|
||||
Clan = 6,
|
||||
Private = 7,
|
||||
CustomGame = 8,
|
||||
}
|
||||
|
||||
impl ChatChannelType {
|
||||
pub fn from_u8(num: u8) -> Result<Self, i16> {
|
||||
match num {
|
||||
0 => Ok(Self::None),
|
||||
1 => Ok(Self::Public),
|
||||
2 => Ok(Self::Battle),
|
||||
3 => Ok(Self::BattleTeam),
|
||||
4 => Ok(Self::Platoon),
|
||||
5 => Ok(Self::Custom),
|
||||
6 => Ok(Self::Clan),
|
||||
7 => Ok(Self::Private),
|
||||
8 => Ok(Self::CustomGame),
|
||||
_ => Err(crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum ChatPlayerState {
|
||||
Idk0 = 0,
|
||||
Idk1 = 1,
|
||||
Idk2 = 2,
|
||||
// FIXME
|
||||
}
|
||||
@@ -11,6 +11,7 @@ pub mod voting;
|
||||
pub mod weapon_list;
|
||||
pub mod weapon_upgrade;
|
||||
pub mod crf;
|
||||
pub mod channel;
|
||||
|
||||
pub mod error_codes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user