pub trait GameServer<C, S>where
Self: Actor + Handler<EventWrapper<S>> + Handler<EventWrapper<Connect<C>>> + Handler<EventWrapper<Disconnect>> + Handler<EventWrapper<Join>> + Handler<EventWrapper<Leave>>,
C: Actor,{
// 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§
Sourcefn connect(&mut self, id: SocketID, addr: Addr<C>)
fn connect(&mut self, id: SocketID, addr: Addr<C>)
Inserts an Addr and its id into the SocketsMap
Sourcefn disconnect(&mut self, id: &SocketID)
fn disconnect(&mut self, id: &SocketID)
Removes an Addr from the SocketsMap
Sourcefn new_game(&mut self, game_id: GameID)
fn new_game(&mut self, game_id: GameID)
Creates a new game by adding a new game key to the GamesMap
Sourcefn end_game(&mut self, game_id: &GameID)
fn end_game(&mut self, game_id: &GameID)
Ends and removes a game by removing it from the GamesMap
Sourcefn join_game(&mut self, id: SocketID, event: Join)
fn join_game(&mut self, id: SocketID, event: Join)
Associates a SocketID with a game in the GamesMap
Sourcefn leave_game(&mut self, id: &SocketID, event: Leave)
fn leave_game(&mut self, id: &SocketID, event: Leave)
Disassociates a SocketID with a game in the GamesMap
Sourcefn emit(&self, event: EventWrapper<S>)
fn emit(&self, event: EventWrapper<S>)
Matches the event.to: EventTarget and emits the event to the correct destination
Sourcefn emit_to_game(&self, game_id: &GameID, event: EventWrapper<S>)
fn emit_to_game(&self, game_id: &GameID, event: EventWrapper<S>)
Emits an event to all sockets in a particular game
Sourcefn emit_to_socket(&self, id: &SocketID, event: EventWrapper<S>)
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.