From ac86fc1ef58a74723f6218570c319b321a3698bf Mon Sep 17 00:00:00 2001 From: J3vb Date: Thu, 2 Apr 2026 13:16:06 +0200 Subject: [PATCH] fix: immediately disconnect banned user's WebSocket connection (BUG-113) BroadcastMemberBan now calls DisconnectUser after broadcasting, which sends an error message and kicks the client. Previously banned users retained WS access until the periodic 30s session sweep or 10-message recheck triggered. --- Server/ws/hub.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Server/ws/hub.go b/Server/ws/hub.go index a453a84c..b17e9277 100644 --- a/Server/ws/hub.go +++ b/Server/ws/hub.go @@ -391,9 +391,25 @@ func (h *Hub) BroadcastChannelDelete(channelID int64) { h.BroadcastToAll(buildChannelDelete(channelID)) } -// BroadcastMemberBan sends a member_ban message to all connected clients. +// BroadcastMemberBan sends a member_ban message to all connected clients +// and immediately disconnects the banned user's WebSocket connection (BUG-113). func (h *Hub) BroadcastMemberBan(userID int64) { h.BroadcastToAll(buildMemberBan(userID)) + h.DisconnectUser(userID) +} + +// DisconnectUser forcibly disconnects the client identified by userID. +// No-op if the user is not currently connected. +func (h *Hub) DisconnectUser(userID int64) { + h.mu.RLock() + c, ok := h.clients[userID] + h.mu.RUnlock() + if !ok { + return + } + slog.Info("hub: disconnecting user", "user_id", userID) + c.sendMsg(buildErrorMsg(ErrCodeBanned, "you are banned")) + h.kickClient(c) } // BroadcastMemberUpdate sends a member_update message to all connected clients.