//! Response values that the server can reply with use super::{Lobby, LobbyId, User, UserId}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; /// A response values from the server #[derive(Serialize, Deserialize)] pub enum Response { /// Response to the register request Register(Result), /// Response to login request Login(Result), /// Response to login request Logout(Result<(), AuthErr>), /// Get a list of available pairs Rooms(Vec<(String, LobbyId)>), /// A user joins a game lobby Join(Result), /// A user leaves a game lobby Leave(Result<(), LobbyErr>), /// Get the new set of ready states Ready(LobbyUpdate), /// Receiving a start request time StartReq(DateTime), /// Response to the action with the state update GameUpdate(UpdateState), /// Leave the match (forfeit) LeaveGame(Result<(), MatchErr>), } #[derive(Serialize, Deserialize)] pub enum RegErr { /// The password is way too bad BadPassword, /// THe username is already taken UsernameTaken, /// Other internal error, try again? OtherError, } #[derive(Serialize, Deserialize)] pub enum AuthErr { /// Wrong password for the user WrongPassword, /// The requested user doesn't exist UserNotFound, /// No session currently exists NoSossion, /// Other internal error, try again? OtherError, } #[derive(Serialize, Deserialize)] pub enum LobbyErr { /// The requested room is already full RoomFull, /// The room id is unknown NoSuchRoom, /// Previously not in room NotInRoom, /// Not everybody was ready NotAllReady, /// A request was sent by someone who isn't authorised NotAuthorized, /// Other internal error, try again? OtherError, } #[derive(Serialize, Deserialize)] pub enum LobbyUpdate { /// The set of ready users Ready(Vec), } /// The way the update was applied #[derive(Serialize, Deserialize)] pub enum UpdateState { /// The update was applied seamlessly Success, /// The update was inserted, but had to be re-ordered with another update Reordered, /// The sent request was invalid and was not applied Invalid, } /// An error that can occur in a match #[derive(Serialize, Deserialize)] pub enum MatchErr { /// The provided player wasn't in the match (anymore?) NotInMatch, /// The requested match had already ended MatchAlreadyEnded, }