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,
},
ChannelJoin
{
username: String,
id: usize,
},
ChannelLeave
{
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]>,
},
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> }, Screen { token: Option<[u8; 32]> }, 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, }
#[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,
}
#[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>,
}