SessionLeave can leave player queue

This commit is contained in:
stryan 2021-09-29 16:40:17 -04:00
parent 2073b4d1f0
commit d183f2d1a3
2 changed files with 9 additions and 15 deletions

View File

@ -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. 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 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. 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

View File

@ -76,14 +76,15 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
} }
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) {
return &SessionCommandResult{ m.Leave(cmd.ID)
ID: cmd.ID, } else {
MatchID: uuid.Nil, for k, _ := range c.PlayerPool {
Result: SessionRespLeft, if k.Id == m.ID {
delete(c.PlayerPool, k)
}
} }
} }
m.Leave(cmd.ID)
return &SessionCommandResult{ return &SessionCommandResult{
ID: cmd.ID, ID: cmd.ID,
MatchID: uuid.Nil, MatchID: uuid.Nil,
@ -91,17 +92,10 @@ func (c *Coordinator) Coordinate(cmd *SessionCommand) *SessionCommandResult {
} }
case SessionCmdPlay: case SessionCmdPlay:
m, exists := c.Matches[cmd.MatchID] m, exists := c.Matches[cmd.MatchID]
if !exists || !m.PlayerIn(cmd.ID) { if !exists || !m.PlayerIn(cmd.ID) || m.Game == nil {
return &SessionCommandResult{ return &SessionCommandResult{
ID: cmd.ID, ID: cmd.ID,
MatchID: uuid.Nil, MatchID: uuid.Nil,
Result: SessionRespLeft,
}
}
if m.Game == nil {
return &SessionCommandResult{
ID: cmd.ID,
MatchID: m.ID,
Result: SessionRespError, Result: SessionRespError,
} }
} }