use libpso::PacketParseError; use libpso::crypto::PSOCipher; #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ClientId(pub usize); pub enum OnConnect { Packet(S), Cipher((Box, Box)), } pub trait RecvServerPacket: Sized + Sync { fn from_bytes(data: &[u8]) -> Result; } pub trait SendServerPacket: Sized + Sync { fn as_bytes(&self) -> Vec; } // TODO: rename this trait, this isn't the state but the actionability of the state re: the client #[async_trait::async_trait] pub trait ServerState { type SendPacket: SendServerPacket; type RecvPacket: RecvServerPacket; type PacketError; async fn on_connect(&mut self, id: ClientId) -> Result>, Self::PacketError>; async fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket) -> Result + Send>, Self::PacketError>; async fn on_disconnect(&mut self, id: ClientId) -> Result, Self::PacketError>; }