2023-01-31 20:16:23 -06:00
|
|
|
use bincode::{Encode, Decode};
|
2023-02-03 12:36:52 -06:00
|
|
|
use crate::common::ClientId;
|
2023-01-31 20:16:23 -06:00
|
|
|
|
2023-02-12 18:53:55 -06:00
|
|
|
pub trait Message: Encode + Decode + Clone {}
|
|
|
|
impl<T: Encode + Decode + Clone> Message for T {}
|
|
|
|
|
2023-01-31 20:16:23 -06:00
|
|
|
#[repr(u8)]
|
|
|
|
#[derive(Encode, Decode)]
|
2023-02-12 18:53:55 -06:00
|
|
|
pub enum ClientPacket<T> where T: Message {
|
|
|
|
Connect {
|
|
|
|
inner_protocol: u16,
|
|
|
|
user_protocol: u16,
|
|
|
|
}, //should always stay 0!
|
2023-02-01 18:54:12 -06:00
|
|
|
Data(T),
|
2023-01-31 20:16:23 -06:00
|
|
|
Disconnect,
|
|
|
|
Heartbeat,
|
2023-02-01 18:54:12 -06:00
|
|
|
}
|
|
|
|
|
2023-02-03 12:36:52 -06:00
|
|
|
#[derive(Encode, Decode)]
|
2023-02-12 18:53:55 -06:00
|
|
|
pub struct IdClientPacket<T: Message>(pub Option<ClientId>, pub ClientPacket<T>);
|
2023-02-03 12:36:52 -06:00
|
|
|
|
2023-02-01 18:54:12 -06:00
|
|
|
#[repr(u8)]
|
|
|
|
#[derive(Encode, Decode)]
|
2023-02-12 18:53:55 -06:00
|
|
|
pub enum ServerPacket<T> where T: Message {
|
|
|
|
ProtoDisconnect = 0,
|
2023-02-01 18:54:12 -06:00
|
|
|
Data(T),
|
2023-02-04 15:20:19 -06:00
|
|
|
Disconnected(String),
|
2023-02-12 18:53:55 -06:00
|
|
|
Connected(ClientId),
|
|
|
|
Heartbeat,
|
2023-01-31 20:16:23 -06:00
|
|
|
}
|
2023-02-03 19:47:09 -06:00
|
|
|
|
|
|
|
#[derive(Encode, Decode)]
|
2023-02-12 18:53:55 -06:00
|
|
|
pub struct IdServerPacket<T: Message>(pub Option<ClientId>, pub ServerPacket<T>);
|