From d183f2d1a30ddcce03fef281589fafcbbba9c95d Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 29 Sep 2021 16:40:17 -0400 Subject: [PATCH] SessionLeave can leave player queue --- PROTOCOL.md | 2 +- internal/coordinator/coordinator.go | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index 8991d08..62e16d9 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -113,7 +113,7 @@ Command is a string representing a command from the following list: query: Tell the server you are looking for a game. Blocks until the server responds with a found game. join: Attempt to join the game with the attached MatchID - leave: Attempt to leave the game with the attached MatchID. 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. play: Attempt to run the attached GameCommand diff --git a/internal/coordinator/coordinator.go b/internal/coordinator/coordinator.go index 664ee6d..e0adc2d 100644 --- a/internal/coordinator/coordinator.go +++ b/internal/coordinator/coordinator.go @@ -76,14 +76,15 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult { } case SessionCmdLeave: m, exists := c.Matches[cmd.MatchID] - if !exists || !m.PlayerIn(cmd.ID) { - return &SessionCommandResult{ - ID: cmd.ID, - MatchID: uuid.Nil, - Result: SessionRespLeft, + if exists && m.PlayerIn(cmd.ID) { + m.Leave(cmd.ID) + } else { + for k, _ := range c.PlayerPool { + if k.Id == m.ID { + delete(c.PlayerPool, k) + } } } - m.Leave(cmd.ID) return &SessionCommandResult{ ID: cmd.ID, MatchID: uuid.Nil, @@ -91,17 +92,10 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult { } case SessionCmdPlay: m, exists := c.Matches[cmd.MatchID] - if !exists || !m.PlayerIn(cmd.ID) { + if !exists || !m.PlayerIn(cmd.ID) || m.Game == nil { return &SessionCommandResult{ ID: cmd.ID, MatchID: uuid.Nil, - Result: SessionRespLeft, - } - } - if m.Game == nil { - return &SessionCommandResult{ - ID: cmd.ID, - MatchID: m.ID, Result: SessionRespError, } }