use wincode::{ SchemaWrite, SchemaRead };
use crate::
{
role::Role,
network::schema::
{
Offer,
BoxedOffer,
Reply,
BoxedReply,
},
};
#[derive(SchemaWrite, SchemaRead, Clone)]
pub enum PacketCode {
Message
{
text: String,
username: Option<String>,
id: Option<usize>,
colors: MessageColors,
},
KeyExchangeOffer
{
#[wincode(with = "BoxedOffer")]
offer: Box<Offer>,
},
KeyExchangeReply
{
#[wincode(with = "BoxedReply")]
reply: Box<Reply>,
},
Welcome
{
min_pass: u64,
max_uname: u64,
min_uname: u64,
server_name: String,
server_uname: String,
git_hash: String,
},
Accept
{
id: usize,
role: Role,
},
Leave
{
username: String,
id: usize,
},
PrivateMessage
{
text: String,
username: Option<String>,
id: usize,
},
PrivateMessageBack
{
text: String,
username: String,
id: usize,
},
VoiceJoin
{
username: String,
id: usize,
},
VoiceLeave
{
id: usize,
},
Upload
{
hash: [u8; 32],
token: Option<[u8; 32]>,
uid: Option<u64>,
},
Download
{
id: Option<usize>,
file_id: Option<usize>,
token: Option<[u8; 32]>,
},
Image
{
hash: [u8; 32],
filename: String,
token: Option<[u8; 32]>,
uid: Option<u64>,
username_color: Option<u8>,
},
ImageDisplay
{
username: String,
filename: String,
hash: [u8; 32],
data: Option<Vec<u8>>,
username_color: Option<u8>,
},
ImageData
{
hash: [u8; 32],
data: Option<Vec<u8>>,
},
Uploaded
{
filename: String,
username: String,
},
Attach
{
id: Option<usize>,
username: Option<String>,
token: Option<[u8; 32]>,
},
ServerBans
{
users: Option<Vec<BanEntry>>,
ips: Option<Vec<BanEntry>>,
},
ServerRole
{
id: usize, role: Role, username: Option<String>, },
ServerSettings
{
settings: Option<Vec<ServerSetting>>,
save: bool,
},
Version { version: Option<String> }, Username { username: Option<String> }, PasswordL { password: Option<String> }, PasswordR { password: Option<String> }, History { messages: Vec<StoredMessage> }, Channel { channel: Option<String> }, ChannelCreated { name: String }, ChannelDestroyed { name: String }, VoiceClients { clients: Vec<(usize, String)> }, Files { users: Option<Vec<UserFile>> }, Screens { users: Option<Vec<UserScreen>> }, Deattach { username: Option<String> }, Attached { username: String }, Deattached { username: String }, Screen { token: Option<[u8; 32]> }, Screenshare { username: String }, ScreenshareEnd { username: String }, Voice { token: Option<[u8; 32]> }, Join { username: String }, List { users: Option<Vec<OnlineUser>> }, ServerKick { id: usize }, ServerMute { id: usize }, ServerBan { id: usize }, ServerBanIp { id: usize }, ServerPardon { id: usize }, ServerPardonIp { id: usize }, ServerSay { message: String },
FirstUser, Rekey, Disconnect, SpamWarning, RegisterDisabled, UploadLimit, Muted, InvalidUsage, InvalidFeature, KeepAlive, ServerRestart, }
impl PacketCode
{
pub fn name(&self) -> &'static str
{
match self
{
Self::Message { .. } => "Message",
Self::KeyExchangeOffer { .. } => "KeyExchangeOffer",
Self::KeyExchangeReply { .. } => "KeyExchangeReply",
Self::Welcome { .. } => "Welcome",
Self::Accept { .. } => "Accept",
Self::Leave { .. } => "Leave",
Self::PrivateMessage { .. } => "PrivateMessage",
Self::PrivateMessageBack { .. } => "PrivateMessageBack",
Self::VoiceJoin { .. } => "VoiceJoin",
Self::VoiceLeave { .. } => "VoiceLeave",
Self::Upload { .. } => "Upload",
Self::Download { .. } => "Download",
Self::Image { .. } => "Image",
Self::ImageDisplay { .. } => "ImageDisplay",
Self::ImageData { .. } => "ImageData",
Self::Uploaded { .. } => "Uploaded",
Self::Attach { .. } => "Attach",
Self::ServerBans { .. } => "ServerBans",
Self::ServerRole { .. } => "ServerRole",
Self::ServerSettings { .. } => "ServerSettings",
Self::Version { .. } => "Version",
Self::Username { .. } => "Username",
Self::PasswordL { .. } => "PasswordL",
Self::PasswordR { .. } => "PasswordR",
Self::History { .. } => "History",
Self::Channel { .. } => "Channel",
Self::ChannelCreated { .. } => "ChannelCreated",
Self::ChannelDestroyed { .. } => "ChannelDestroyed",
Self::VoiceClients { .. } => "VoiceClients",
Self::Files { .. } => "Files",
Self::Screens { .. } => "Screens",
Self::Deattach { .. } => "Deattach",
Self::Attached { .. } => "Attached",
Self::Deattached { .. } => "Deattached",
Self::Screen { .. } => "Screen",
Self::Screenshare { .. } => "Screenshare",
Self::ScreenshareEnd { .. } => "ScreenshareEnd",
Self::Voice { .. } => "Voice",
Self::Join { .. } => "Join",
Self::List { .. } => "List",
Self::ServerKick { .. } => "ServerKick",
Self::ServerMute { .. } => "ServerMute",
Self::ServerBan { .. } => "ServerBan",
Self::ServerBanIp { .. } => "ServerBanIp",
Self::ServerPardon { .. } => "ServerPardon",
Self::ServerPardonIp { .. } => "ServerPardonIp",
Self::ServerSay { .. } => "ServerSay",
Self::FirstUser { .. } => "FirstUser",
Self::Rekey { .. } => "Rekey",
Self::Disconnect { .. } => "Disconnect",
Self::SpamWarning { .. } => "SpamWarning",
Self::RegisterDisabled { .. } => "RegisterDisabled",
Self::UploadLimit { .. } => "UploadLimit",
Self::Muted { .. } => "Muted",
Self::InvalidUsage { .. } => "InvalidUsage",
Self::InvalidFeature { .. } => "InvalidFeature",
Self::KeepAlive { .. } => "KeepAlive",
Self::ServerRestart { .. } => "ServerRestart",
}
}
}
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct ServerSetting
{
pub key: String,
pub value: SettingValue,
pub section: String, pub description: String, pub restart: bool, }
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub enum SettingValue
{
Toggle(bool),
Number(i64),
Text(String),
}
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct StoredMessage
{
pub username: String,
pub text: String, pub colors: MessageColors,
pub image: Option<[u8; 32]>, }
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct MessageColors {
pub username_color: Option<u8>, pub message_color: Option<u8>, }
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct UserFile {
pub username: String,
pub id: usize,
pub upload: Vec<(String, usize)>,
}
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct UserScreen {
pub username: String,
pub id: usize,
}
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct BanEntry {
pub id: usize,
pub subject: String,
}
#[derive(SchemaWrite, SchemaRead, Clone, PartialEq)]
pub struct OnlineUser {
pub username: String,
pub id: usize,
pub channel: Option<String>,
}