GameServer

Trait GameServer 

Source
pub trait GameServer<C, S>{
    // Required methods
    fn new() -> Self;
    fn connect(&mut self, id: SocketID, addr: Addr<C>);
    fn disconnect(&mut self, id: &SocketID);
    fn new_game(&mut self, game_id: GameID);
    fn end_game(&mut self, game_id: &GameID);
    fn join_game(&mut self, id: SocketID, event: Join);
    fn leave_game(&mut self, id: &SocketID, event: Leave);
    fn emit(&self, event: EventWrapper<S>);
    fn emit_to_game(&self, game_id: &GameID, event: EventWrapper<S>);
    fn emit_to_socket(&self, id: &SocketID, event: EventWrapper<S>);
}
Expand description

A generic game server that can be implemented and extended to fit any game’s needs

A struct that implements GameServer should have a bare minimum of two fields: sockets: SocketsMap<SomeSocket> and games: GamesMap

Required Methods§

Source

fn new() -> Self

Creates a new instance of GameServer

Source

fn connect(&mut self, id: SocketID, addr: Addr<C>)

Inserts an Addr and its id into the SocketsMap

Source

fn disconnect(&mut self, id: &SocketID)

Removes an Addr from the SocketsMap

Source

fn new_game(&mut self, game_id: GameID)

Creates a new game by adding a new game key to the GamesMap

Source

fn end_game(&mut self, game_id: &GameID)

Ends and removes a game by removing it from the GamesMap

Source

fn join_game(&mut self, id: SocketID, event: Join)

Associates a SocketID with a game in the GamesMap

Source

fn leave_game(&mut self, id: &SocketID, event: Leave)

Disassociates a SocketID with a game in the GamesMap

Source

fn emit(&self, event: EventWrapper<S>)

Matches the event.to: EventTarget and emits the event to the correct destination

Source

fn emit_to_game(&self, game_id: &GameID, event: EventWrapper<S>)

Emits an event to all sockets in a particular game

Source

fn emit_to_socket(&self, id: &SocketID, event: EventWrapper<S>)

Emits an event to a particular socket

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§