use libpso::PacketParseError; use libpso::crypto::PSOCipher; #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)] pub struct ClientId(pub usize); pub enum OnConnect { Packet(S), Cipher(C, C), //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: Clone { type SendPacket: SendServerPacket; type RecvPacket: RecvServerPacket; type Cipher: PSOCipher; type PacketError; async fn on_connect(&mut self, id: ClientId) -> Result>, Self::PacketError>; async fn handle(&mut self, id: ClientId, pkt: Self::RecvPacket) -> Result, Self::PacketError>; //-> Result>, Self::PacketError>; async fn on_disconnect(&mut self, id: ClientId) -> Result, Self::PacketError>; }