From 89a94ca08177e4627550e8da0f19c739a0e8c4e3 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 30 Sep 2021 21:00:49 -0400 Subject: [PATCH] add ready checking at session level --- PROTOCOL.md | 2 ++ internal/coordinator/coordinator.go | 22 ++++++++++++++++++++++ internal/coordinator/session.go | 2 ++ 3 files changed, 26 insertions(+) diff --git a/PROTOCOL.md b/PROTOCOL.md index 62e16d9..cca79d1 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -116,6 +116,7 @@ Command is a string representing a command from the following list: leave: Attempt to leave the game with the attached MatchID. If no game is found and the player is queueing, remove from queue. Always succeeds. poll: Check if the server has any "broadcast" responses. Opts into polling. play: Attempt to run the attached GameCommand + ready: Check if both players have joined the game with attached MatchID GameCommand is a game command following the conventions described above. @@ -147,6 +148,7 @@ Result is a string representing the result of the SessionCommand. The following "joined p2": The client was succesful in joining the game as Player 2 ("Scourge") "left": The client was succesful in leaving the game "played": The server recognized a game command was sent. This does NOT mean the command was succesful; the client should check the GameResult for that information + "game ready": Both players have joined the game and game commands can be sent "generic error": An error has occured. The following Results are called "Broadcasts" and are sent by the server to ease the work done by the clients. None of them are required to be handled, but it will most likely be useful for clients to handle at least some of them. diff --git a/internal/coordinator/coordinator.go b/internal/coordinator/coordinator.go index e0adc2d..9763960 100644 --- a/internal/coordinator/coordinator.go +++ b/internal/coordinator/coordinator.go @@ -74,6 +74,28 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult { MatchID: m.ID, Result: resp, } + case SessionCmdReady: + m, exists := c.Matches[cmd.MatchID] + if !exists { + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: uuid.Nil, + Result: SessionRespError, + } + } + if m.p1 != uuid.Nil && m.p2 != uuid.Nil { + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: m.ID, + Result: SessionRespReady, + } + } else { + return &SessionCommandResult{ + ID: cmd.ID, + MatchID: uuid.Nil, + Result: SessionRespError, + } + } case SessionCmdLeave: m, exists := c.Matches[cmd.MatchID] if exists && m.PlayerIn(cmd.ID) { diff --git a/internal/coordinator/session.go b/internal/coordinator/session.go index 3d34372..fd17d82 100644 --- a/internal/coordinator/session.go +++ b/internal/coordinator/session.go @@ -17,12 +17,14 @@ const ( SessionCmdLeave = "leave" SessionCmdPlay = "play" SessionCmdPoll = "poll" + SessionCmdReady = "ready" ) const ( SessionRespFound SessionResp = "found" SessionRespJoined1 = "joined p1" SessionRespJoined2 = "joined p2" + SessionRespReady = "game ready" SessionRespJoinError = "join error" SessionRespLeft = "left" SessionRespPlayed = "played"