Trait ServerContext

Source
pub trait ServerContext: Send + Sync {
    // Required methods
    fn emit_event<'life0, 'async_trait>(
        &'life0 self,
        namespace: EventNamespace,
        event: Box<dyn GameEvent>,
    ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn region_id(&self) -> RegionId;
    fn get_players<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Player>, ServerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_player<'life0, 'async_trait>(
        &'life0 self,
        id: PlayerId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Player>, ServerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send_to_player<'life0, 'life1, 'async_trait>(
        &'life0 self,
        player_id: PlayerId,
        message: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn broadcast_to_region<'life0, 'life1, 'async_trait>(
        &'life0 self,
        message: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn log(&self, level: LogLevel, message: &str);
}
Expand description

Server context provided to plugins

Required Methods§

Source

fn emit_event<'life0, 'async_trait>( &'life0 self, namespace: EventNamespace, event: Box<dyn GameEvent>, ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Emit an event to the event system

Source

fn region_id(&self) -> RegionId

Get current region ID

Source

fn get_players<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Player>, ServerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all players in the region

Source

fn get_player<'life0, 'async_trait>( &'life0 self, id: PlayerId, ) -> Pin<Box<dyn Future<Output = Result<Option<Player>, ServerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get specific player by ID

Source

fn send_to_player<'life0, 'life1, 'async_trait>( &'life0 self, player_id: PlayerId, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send message to specific player

Source

fn broadcast_to_region<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), ServerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Broadcast message to all players in region

Source

fn log(&self, level: LogLevel, message: &str)

Log message (for debugging/monitoring)

Implementors§