diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-24 16:10:42 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-24 16:10:42 -0700 |
| commit | 46862572ad2977a87baeda0aa8a9e678c533559d (patch) | |
| tree | 6ef94eed133008269972d63c35569df3d9b7e58f /hotline/transaction_handlers.go | |
| parent | 31658ca1e37cb8118a8a081e6d8f6e15e39a1cea (diff) | |
Implement user ban
Diffstat (limited to 'hotline/transaction_handlers.go')
| -rw-r--r-- | hotline/transaction_handlers.go | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 9edecb8..dda2dce 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -1024,12 +1024,48 @@ func HandleDisconnectUser(cc *ClientConn, t *Transaction) (res []Transaction, er return res, err } - if err := clientConn.Connection.Close(); err != nil { - return res, err + // If fieldOptions is set, then the client IP is banned in addition to disconnected. + // 00 01 = temporary ban + // 00 02 = permanent ban + if t.GetField(fieldOptions).Data != nil { + switch t.GetField(fieldOptions).Data[1] { + case 1: + // send message: "You are temporarily banned on this server" + cc.logger.Infow("Disconnect & temporarily ban " + string(clientConn.UserName)) + + res = append(res, *NewTransaction( + tranServerMsg, + clientConn.ID, + NewField(fieldData, []byte("You are temporarily banned on this server")), + NewField(fieldChatOptions, []byte{0, 0}), + )) + + banUntil := time.Now().Add(tempBanDuration) + cc.Server.banList[strings.Split(clientConn.RemoteAddr, ":")[0]] = &banUntil + cc.Server.writeBanList() + case 2: + // send message: "You are permanently banned on this server" + cc.logger.Infow("Disconnect & ban " + string(clientConn.UserName)) + + res = append(res, *NewTransaction( + tranServerMsg, + clientConn.ID, + NewField(fieldData, []byte("You are permanently banned on this server")), + NewField(fieldChatOptions, []byte{0, 0}), + )) + + cc.Server.banList[strings.Split(clientConn.RemoteAddr, ":")[0]] = nil + cc.Server.writeBanList() + } } - res = append(res, cc.NewReply(t)) - return res, err + // TODO: remove this awful hack + go func() { + time.Sleep(1 * time.Second) + clientConn.Disconnect() + }() + + return append(res, cc.NewReply(t)), err } // HandleGetNewsCatNameList returns a list of news categories for a path |