2019-08-24 14:18:07 -07:00
|
|
|
use libpso::PacketParseError;
|
2019-07-17 23:17:57 -07:00
|
|
|
use libpso::crypto::PSOCipher;
|
|
|
|
|
2019-09-04 09:17:22 -07:00
|
|
|
pub type ClientId = usize;
|
2019-07-17 23:17:57 -07:00
|
|
|
|
2019-08-24 14:18:07 -07:00
|
|
|
pub enum OnConnect<S: SendServerPacket> {
|
|
|
|
Packet(S),
|
2019-09-04 09:17:22 -07:00
|
|
|
Cipher((Box<dyn PSOCipher + Send>, Box<dyn PSOCipher + Send>)),
|
2019-07-17 23:17:57 -07:00
|
|
|
}
|
|
|
|
|
2019-08-24 14:18:07 -07:00
|
|
|
pub trait RecvServerPacket: Sized {
|
2019-09-04 09:17:22 -07:00
|
|
|
fn from_bytes(data: &[u8]) -> Result<Self, PacketParseError>;
|
2019-07-17 23:17:57 -07:00
|
|
|
}
|
|
|
|
|
2019-08-24 14:18:07 -07:00
|
|
|
pub trait SendServerPacket: Sized {
|
|
|
|
fn as_bytes(&self) -> Vec<u8>;
|
|
|
|
}
|
|
|
|
|
2019-07-17 23:17:57 -07:00
|
|
|
pub trait ServerState {
|
2019-08-24 14:18:07 -07:00
|
|
|
type SendPacket: SendServerPacket;
|
|
|
|
type RecvPacket: RecvServerPacket;
|
2019-07-17 23:17:57 -07:00
|
|
|
type PacketError;
|
|
|
|
|
2019-08-24 14:18:07 -07:00
|
|
|
fn on_connect(&mut self) -> Vec<OnConnect<Self::SendPacket>>;
|
2019-09-04 09:17:22 -07:00
|
|
|
fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket) -> Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>>;
|
2019-07-17 23:17:57 -07:00
|
|
|
}
|
|
|
|
|