pub trait Game {
fn handle_command(
&mut self,
delta_time: Duration,
commands: Vec<Vec<u8>>,
from: SocketAddr
) -> ContinueRunning;
fn draw(&mut self, delta_time: Duration) -> Vec<u8>;
fn allow_connect(&mut self, _from: &SocketAddr) -> bool { ... }
fn handle_server_event(&mut self, _event: ServerEvent) -> ContinueRunning { ... }
fn add_client(&mut self) -> Option<SocketAddr> { ... }
fn remove_client(&mut self) -> Option<SocketAddr> { ... }
}
Expand description
Game to use with server must implement this trait
Required Methods
sourcefn handle_command(
&mut self,
delta_time: Duration,
commands: Vec<Vec<u8>>,
from: SocketAddr
) -> ContinueRunning
fn handle_command(
&mut self,
delta_time: Duration,
commands: Vec<Vec<u8>>,
from: SocketAddr
) -> ContinueRunning
delta_time: time elapsed from last call command: ordered commands commands from server from: Address of command sender returns bool value indicating should server continue running if false stops server called only when new commands come to server
Provided Methods
sourcefn allow_connect(&mut self, _from: &SocketAddr) -> bool
fn allow_connect(&mut self, _from: &SocketAddr) -> bool
allow client with this IP Address work with server if false server don’t send new state to this client usually don’t implement this method. Use default implementation
sourcefn handle_server_event(&mut self, _event: ServerEvent) -> ContinueRunning
fn handle_server_event(&mut self, _event: ServerEvent) -> ContinueRunning
Handles events from server returns bool value if returns false stops server usually don’t implement this method. Use default implementation
sourcefn add_client(&mut self) -> Option<SocketAddr>
fn add_client(&mut self) -> Option<SocketAddr>
Client to add to recv state from serve if returns not None then servers on draw sends new state to this client if client with this IP Address already connected then nothing happens usually don’t implement this method. Use default implementation
sourcefn remove_client(&mut self) -> Option<SocketAddr>
fn remove_client(&mut self) -> Option<SocketAddr>
Disconnect this client from server and don’t send new state to them