You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.7 KiB
49 lines
1.7 KiB
//! 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};
|
|
|
|
/// The main game interface implemented by the server and client
|
|
#[async_trait]
|
|
pub trait GameIf {
|
|
/// Register a new user on a game server
|
|
async fn register(self: Arc<Self>, name: String, pw: String) -> Result<UserId, RegErr>;
|
|
|
|
/// Login for an existing user
|
|
async fn login(self: Arc<Self>, name: String, pw: String) -> Result<User, AuthErr>;
|
|
|
|
/// End a user session (go offline)
|
|
async fn logout(self: Arc<Self>, user: User) -> Result<(), AuthErr>;
|
|
|
|
/// Register as an anonymous player
|
|
async fn anonymous(self: Arc<Self>, name: String) -> Result<User, AuthErr>;
|
|
|
|
/// Join a match-making lobby
|
|
async fn join(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<Lobby, LobbyErr>;
|
|
|
|
/// Leave a match-making lobby
|
|
async fn leave(self: Arc<Self>, user: User, lobby: LobbyId) -> Result<(), LobbyErr>;
|
|
|
|
/// Set the player's ready state
|
|
async fn ready(
|
|
self: Arc<Self>,
|
|
user: User,
|
|
lobby: LobbyId,
|
|
ready: bool,
|
|
) -> Result<LobbyUpdate, LobbyErr>;
|
|
|
|
/// Send a start request (as lobby admin)
|
|
async fn start_req(self: Arc<Self>, user: UserId, lobby: LobbyId) -> Result<DateTime<Utc>, LobbyErr>;
|
|
|
|
/// Perform a game action as a user
|
|
async fn perform_action(self: Arc<Self>, user: User, mtch: MatchId, act: Action)
|
|
-> UpdateState;
|
|
|
|
/// Leave a match
|
|
async fn leave_match(self: Arc<Self>, user: User, mtch: MatchId) -> Result<(), MatchErr>;
|
|
}
|
|
|