Fix case where client could disconnect but still be handling a note
This commit is contained in:
parent
b0d4595cd3
commit
d83f6d6be8
|
@ -306,13 +306,19 @@ func (r *Room) HandleConn(playerID uuid.UUID, nickname string, c *websocket.Conn
|
||||||
_ = g.Wait()
|
_ = g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errMissingPlayer = errors.New("missing player during handleNote")
|
||||||
|
|
||||||
func (r *Room) handleNote(playerID game.PlayerID, note *protocol.ClientNote) error {
|
func (r *Room) handleNote(playerID game.PlayerID, note *protocol.ClientNote) error {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
// The client's version was wrong; reject and send them the current state.
|
// The client's version was wrong; reject and send them the current state.
|
||||||
if note.Version != r.room.Version {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,5 +661,4 @@ func (r *Room) changeHideBomb(HideBomb bool) {
|
||||||
|
|
||||||
r.hideBomb = HideBomb
|
r.hideBomb = HideBomb
|
||||||
r.room.Version++
|
r.room.Version++
|
||||||
r.sendAll()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue