Fix case where client could disconnect but still be handling a note

This commit is contained in:
zikaeroh 2020-06-09 20:20:17 -07:00
parent b0d4595cd3
commit d83f6d6be8
1 changed files with 7 additions and 2 deletions

View File

@ -306,13 +306,19 @@ func (r *Room) HandleConn(playerID uuid.UUID, nickname string, c *websocket.Conn
_ = g.Wait()
}
var errMissingPlayer = errors.New("missing player during handleNote")
func (r *Room) handleNote(playerID game.PlayerID, note *protocol.ClientNote) error {
r.mu.Lock()
defer r.mu.Unlock()
// The client's version was wrong; reject and send them the current state.
if note.Version != r.room.Version {
r.sendOne(playerID, r.players[playerID])
p := r.players[playerID]
if p == nil {
return errMissingPlayer
}
r.sendOne(playerID, p)
return nil
}
@ -655,5 +661,4 @@ func (r *Room) changeHideBomb(HideBomb bool) {
r.hideBomb = HideBomb
r.room.Version++
r.sendAll()
}