diff --git a/controllers/chat.go b/controllers/chat.go index 45a11738d..0f0263be9 100644 --- a/controllers/chat.go +++ b/controllers/chat.go @@ -25,7 +25,7 @@ func GetChatMessages(w http.ResponseWriter, r *http.Request) { messages := chat.GetChatHistory() if err := json.NewEncoder(w).Encode(messages); err != nil { - log.Errorln(err) + log.Debugln(err) } default: w.WriteHeader(http.StatusNotImplemented) diff --git a/core/chat/chatclient.go b/core/chat/chatclient.go index 12af7e75e..2cd1d67de 100644 --- a/core/chat/chatclient.go +++ b/core/chat/chatclient.go @@ -155,7 +155,7 @@ func (c *ChatClient) close() { log.Traceln("client closed:", c.User.DisplayName, c.id, c.ipAddress) c.conn.Close() - c.server.unregister <- c + c.server.unregister <- c.id if c.send != nil { close(c.send) c.send = nil diff --git a/core/chat/server.go b/core/chat/server.go index 240f32d3f..d79ca9817 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -32,7 +32,7 @@ type ChatServer struct { inbound chan chatClientEvent // unregister requests from clients. - unregister chan *ChatClient + unregister chan uint // the ChatClient id } func NewChat() *ChatServer { @@ -40,7 +40,7 @@ func NewChat() *ChatServer { clients: map[uint]*ChatClient{}, outbound: make(chan []byte), inbound: make(chan chatClientEvent), - unregister: make(chan *ChatClient), + unregister: make(chan uint), maxClientCount: handleMaxConnectionCount(), } @@ -50,10 +50,10 @@ func NewChat() *ChatServer { func (s *ChatServer) Run() { for { select { - case client := <-s.unregister: - if _, ok := s.clients[client.id]; ok { + case clientId := <-s.unregister: + if _, ok := s.clients[clientId]; ok { s.mu.Lock() - delete(s.clients, client.id) + delete(s.clients, clientId) s.mu.Unlock() }