SessionLeave can leave player queue
This commit is contained in:
parent
2073b4d1f0
commit
d183f2d1a3
@ -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
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user