From d83f6d6be8f7609cbaa64ab1190c31cfeed395d4 Mon Sep 17 00:00:00 2001 From: zikaeroh <48577114+zikaeroh@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:20:17 -0700 Subject: [PATCH] Fix case where client could disconnect but still be handling a note --- internal/server/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 7002654..dd96867 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -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() }