use polariton::operation::ParameterTable;
#[cfg_attr(feature = "async", async_trait::async_trait)]
pub trait Event<C: Send + 'static>: Send + Sync {
type User: Sync;
fn handle(&self, params: ParameterTable<C>, user: &Self::User);
#[cfg(feature = "async")]
async fn handle_async(&self, params: ParameterTable<C>, user: &Self::User) {
self.handle(params, user)
}
}
pub trait EventCode {
fn event_code() -> u8;
}
pub trait IntoEvent<C: Send + 'static>: Sized {
const CHANNEL: u8;
const ENCRYPT: bool;
const RELIABLE: bool;
fn into_event(self) -> polariton::operation::Event<C>;
fn into_sendable(self) -> crate::ToSend<C> {
crate::ToSend::Data {
data: polariton::packet::Data::Event(self.into_event()),
encrypt: Self::ENCRYPT,
channel: Self::CHANNEL,
reliable: Self::RELIABLE,
}
}
}
impl <C: Send + 'static> IntoEvent<C> for polariton::operation::Event<C> {
const CHANNEL: u8 = 0;
const ENCRYPT: bool = true;
const RELIABLE: bool = true;
fn into_event(self) -> polariton::operation::Event<C> {
self
}
}