34 lines
1.3 KiB
Rust
34 lines
1.3 KiB
Rust
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<S: SendServerPacket, C: PSOCipher> {
|
|
Packet(S),
|
|
Cipher(C, C),
|
|
//Cipher((Box<dyn PSOCipher + Send + Sync>, Box<dyn PSOCipher + Send + Sync>)),
|
|
}
|
|
|
|
pub trait RecvServerPacket: Sized + Sync {
|
|
fn from_bytes(data: &[u8]) -> Result<Self, PacketParseError>;
|
|
}
|
|
|
|
pub trait SendServerPacket: Sized + Sync {
|
|
fn as_bytes(&self) -> Vec<u8>;
|
|
}
|
|
|
|
// 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<Vec<OnConnect<Self::SendPacket, Self::Cipher>>, Self::PacketError>;
|
|
async fn handle(&mut self, id: ClientId, pkt: Self::RecvPacket) -> Result<Vec<(ClientId, Self::SendPacket)>, Self::PacketError>;
|
|
//-> Result<Box<dyn Iterator<Item = (ClientId, Self::SendPacket)>>, Self::PacketError>;
|
|
async fn on_disconnect(&mut self, id: ClientId) -> Result<Vec<(ClientId, Self::SendPacket)>, Self::PacketError>;
|
|
}
|