//! A common trait interface between the server and the client use crate::wire::{ Action, AuthErr, Lobby, LobbyErr, LobbyId, LobbyUpdate, MatchErr, MatchId, RegErr, UpdateState, User, UserId, }; use async_std::sync::Arc; use async_trait::async_trait; use chrono::{DateTime, Utc}; /// Main game interface implemented by the server and client /// /// The client implementation simply translates requests to network /// requests that are sent to the server. The server implementation /// consists of two parts: the network layer listening loop, and the /// game server state which then implements the actual game logic. #[async_trait] pub trait GameIf { /// Register a new user on a game server async fn register(self: Arc, name: String, pw: String) -> Result; /// Login for an existing user async fn login(self: Arc, name: String, pw: String) -> Result; /// End a user session (go offline) async fn logout(self: Arc, user: User) -> Result<(), AuthErr>; /// Register as an anonymous player async fn anonymous(self: Arc, name: String) -> Result; /// Join a match-making lobby async fn join(self: Arc, user: User, lobby: LobbyId) -> Result; /// Leave a match-making lobby async fn leave(self: Arc, user: User, lobby: LobbyId) -> Result<(), LobbyErr>; /// Set the player's ready state async fn ready( self: Arc, user: User, lobby: LobbyId, ready: bool, ) -> Result; /// Send a start request (as lobby admin) async fn start_req( self: Arc, user: UserId, lobby: LobbyId, ) -> Result, LobbyErr>; /// Perform a game action as a user async fn perform_action(self: Arc, user: User, mtch: MatchId, act: Action) -> UpdateState; /// Leave a match async fn leave_match(self: Arc, user: User, mtch: MatchId) -> Result<(), MatchErr>; }