[−][src]Trait victorem::Game
Game to use with server must implement this trait.
Required methods
fn handle_command(
&mut self,
delta_time: Duration,
commands: Vec<Vec<u8>>,
from: SocketAddr
) -> ContinueRunning
&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. Commands ordered and with some guarantees.
fn draw(&mut self, delta_time: Duration) -> Vec<u8>
Gets new state to send to client.
delta_time: time elapsed throw last call.
Returns bytes with new game state for client.
Called once in about 30 milliseconds.
Sends state only to clients connected to server.
Ordered and without some guarantees.
If returns empty Vec
Provided methods
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.
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.
fn add_client(&mut self) -> Option<SocketAddr>
Client to add to recv state from server. 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.
fn remove_client(&mut self) -> Option<SocketAddr>
Disconnect this client from server and don't send new state to them. Usually don't implement this method. Use default implementation.