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.
96 lines
2.6 KiB
96 lines
2.6 KiB
//! 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<UserId, RegErr>),
|
|
/// Response to login request
|
|
Login(Result<User, AuthErr>),
|
|
/// Response to login request
|
|
Logout(Result<(), AuthErr>),
|
|
/// Get a list of available <name-room> pairs
|
|
Rooms(Vec<(String, LobbyId)>),
|
|
/// A user joins a game lobby
|
|
Join(Result<Lobby, LobbyErr>),
|
|
/// 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<Utc>),
|
|
/// Response to the action with the state update
|
|
GameUpdate(UpdateState),
|
|
/// Leave the match (forfeit)
|
|
LeaveGame(Result<(), MatchErr>),
|
|
/// The given request was entirely invalid
|
|
Invalid,
|
|
}
|
|
|
|
#[derive(Debug, Clone, 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(Debug, Clone, 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(Debug, Clone, 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<UserId>),
|
|
}
|
|
|
|
/// 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(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum MatchErr {
|
|
/// The provided player wasn't in the match (anymore?)
|
|
NotInMatch,
|
|
/// The requested match had already ended
|
|
MatchAlreadyEnded,
|
|
}
|
|
|