aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-core/src/wire/resp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'games/rstnode/rst-core/src/wire/resp.rs')
-rw-r--r--games/rstnode/rst-core/src/wire/resp.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/games/rstnode/rst-core/src/wire/resp.rs b/games/rstnode/rst-core/src/wire/resp.rs
new file mode 100644
index 000000000000..ef2e192a6044
--- /dev/null
+++ b/games/rstnode/rst-core/src/wire/resp.rs
@@ -0,0 +1,94 @@
+//! 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>),
+}
+
+#[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<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,
+}