add ready checking at session level

This commit is contained in:
stryan 2021-09-30 21:00:49 -04:00
parent d183f2d1a3
commit 89a94ca081
3 changed files with 26 additions and 0 deletions

View File

@ -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. 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. poll: Check if the server has any "broadcast" responses. Opts into polling.
play: Attempt to run the attached GameCommand 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. 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") "joined p2": The client was succesful in joining the game as Player 2 ("Scourge")
"left": The client was succesful in leaving the game "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 "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. "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. 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.

View File

@ -74,6 +74,28 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
MatchID: m.ID, MatchID: m.ID,
Result: resp, 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: case SessionCmdLeave:
m, exists := c.Matches[cmd.MatchID] m, exists := c.Matches[cmd.MatchID]
if exists && m.PlayerIn(cmd.ID) { if exists && m.PlayerIn(cmd.ID) {

View File

@ -17,12 +17,14 @@ const (
SessionCmdLeave = "leave" SessionCmdLeave = "leave"
SessionCmdPlay = "play" SessionCmdPlay = "play"
SessionCmdPoll = "poll" SessionCmdPoll = "poll"
SessionCmdReady = "ready"
) )
const ( const (
SessionRespFound SessionResp = "found" SessionRespFound SessionResp = "found"
SessionRespJoined1 = "joined p1" SessionRespJoined1 = "joined p1"
SessionRespJoined2 = "joined p2" SessionRespJoined2 = "joined p2"
SessionRespReady = "game ready"
SessionRespJoinError = "join error" SessionRespJoinError = "join error"
SessionRespLeft = "left" SessionRespLeft = "left"
SessionRespPlayed = "played" SessionRespPlayed = "played"