diff --git a/pkg/commands.go b/pkg/commands.go index e9160eb..c702eeb 100644 --- a/pkg/commands.go +++ b/pkg/commands.go @@ -152,7 +152,8 @@ func (s *Server) KickCommand(words []string, sub *Subscriber) { other.SendJSON(messages.Message{ Action: messages.ActionKick, }) - s.DeleteSubscriber(other) + other.authenticated = false + other.Username = "" sub.ChatServer("%s has been kicked from the room", username) // Broadcast it to everyone. @@ -200,7 +201,8 @@ func (s *Server) KickAllCommand() { continue } - s.DeleteSubscriber(sub) + sub.authenticated = false + sub.Username = "" } } @@ -245,7 +247,8 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) { other.SendJSON(messages.Message{ Action: messages.ActionKick, }) - s.DeleteSubscriber(other) + other.authenticated = false + other.Username = "" sub.ChatServer("%s has been banned from the room for %d hours.", username, duration/time.Hour) } } diff --git a/pkg/handlers.go b/pkg/handlers.go index b74debb..e4bf0d1 100644 --- a/pkg/handlers.go +++ b/pkg/handlers.go @@ -62,7 +62,8 @@ func (s *Server) OnLogin(sub *Subscriber, msg messages.Message) { other.SendJSON(messages.Message{ Action: messages.ActionKick, }) - s.DeleteSubscriber(other) + other.authenticated = false + other.Username = "" } // They will take over their original username. diff --git a/pkg/websocket.go b/pkg/websocket.go index f1f07f3..211f235 100644 --- a/pkg/websocket.go +++ b/pkg/websocket.go @@ -229,7 +229,7 @@ func (s *Server) WebSocket() http.HandlerFunc { var token string if sub.JWTClaims != nil { if jwt, err := sub.JWTClaims.ReSign(); err != nil { - log.Error("ReSign JWT token for %s: %s", sub.Username, err) + log.Error("ReSign JWT token for %s#%d: %s", sub.Username, sub.ID, err) } else { token = jwt } @@ -279,6 +279,7 @@ func (s *Server) DeleteSubscriber(sub *Subscriber) { // Cancel its context to clean up the for-loop goroutine. if sub.cancel != nil { + log.Info("Calling sub.cancel() on subscriber: %s#%d", sub.Username, sub.ID) sub.cancel() } diff --git a/src/App.vue b/src/App.vue index 152cae4..d2e3e50 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1283,7 +1283,7 @@ export default { } if (!this.disconnect) { - if (ev.code !== 1001) { + if (ev.code !== 1001 && ev.code !== 1000) { this.ChatClient("Reconnecting in 5s"); setTimeout(this.dial, 5000); } @@ -1376,7 +1376,10 @@ export default { }); break; case "disconnect": + this.onWho({ whoList: [] }); this.disconnect = true; + this.ws.connected = false; + this.ws.conn.close(1000, "server asked to close the connection"); break; case "ping": // New JWT token?