diff options
Diffstat (limited to 'src/wire/resp.rs')
-rw-r--r-- | src/wire/resp.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/wire/resp.rs b/src/wire/resp.rs new file mode 100644 index 000000000000..b9f41fbe93e4 --- /dev/null +++ b/src/wire/resp.rs @@ -0,0 +1,89 @@ +//! 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, RoomErr>), + /// A user leaves a game lobby + Leave(Result<(), RoomErr>), + /// Get the new set of ready states + Ready(RoomUpdate), + /// 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>), + +} + +#[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 RoomErr { + /// The requested room is already full + RoomFull, + /// The room id is unknown + NoSuchRoom, + /// Previously not in room + NotInRoom, +} + +#[derive(Serialize, Deserialize)] +pub enum RoomUpdate { + /// 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(Serialize, Deserialize)] +pub enum MatchErr { + /// The provided player wasn't in the match (anymore?) + NotInMatch, + /// The requested match had already ended + MatchAlreadyEnded +} |