Skip to content

Commit cdfb7be

Browse files
committed
avoid crash
1 parent c7f76da commit cdfb7be

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

internal/lobbyServer/lobby.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/sha256"
55
"encoding/hex"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"math"
109
"net"
@@ -292,11 +291,11 @@ func (s *LobbyServer) wsHandler(w http.ResponseWriter, r *http.Request) {
292291
var receivedMessage SocketMessage
293292
err := ws.ReadJSON(&receivedMessage)
294293
if err != nil {
295-
if errors.Is(err, err.(*websocket.CloseError)) {
294+
if e, ok := err.(*websocket.CloseError); ok {
296295
for i, v := range s.GameServers {
297296
for k, w := range v.Players {
298297
if w.Socket == ws {
299-
v.Logger.Info("Player has left lobby", "player", k, "address", ws.RemoteAddr())
298+
v.Logger.Info("Player has left lobby", "closeCode", e.Text, "player", k, "address", ws.RemoteAddr())
300299

301300
v.PlayersMutex.Lock() // any player can modify this, which would be in a different thread
302301
if !v.Running {

0 commit comments

Comments
 (0)