Add support for IP-based bans (#1703)

* Add support for IP-based bans. Closes #1534

* Linter cleanup
This commit is contained in:
Gabe Kangas
2022-03-06 20:34:49 -08:00
committed by GitHub
parent 78c27ddbdd
commit 19b9a8bdf6
21 changed files with 488 additions and 98 deletions
+2 -3
View File
@@ -22,7 +22,7 @@ type Client struct {
conn *websocket.Conn
User *user.User `json:"user"`
server *Server
ipAddress string `json:"-"`
IPAddress string `json:"-"`
// Buffered channel of outbound messages.
send chan []byte
rateLimiter *rate.Limiter
@@ -94,7 +94,6 @@ func (c *Client) readPump() {
c.conn.SetPongHandler(func(string) error { _ = c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
for {
_, message, err := c.conn.ReadMessage()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
c.close()
@@ -176,7 +175,7 @@ func (c *Client) handleEvent(data []byte) {
}
func (c *Client) close() {
log.Traceln("client closed:", c.User.DisplayName, c.id, c.ipAddress)
log.Traceln("client closed:", c.User.DisplayName, c.id, c.IPAddress)
_ = c.conn.Close()
c.server.unregister <- c.id