mt-multiserver-proxy/moderation.go

43 lines
901 B
Go
Raw Normal View History

2021-09-11 01:09:55 -07:00
package proxy
2021-09-11 03:25:50 -07:00
import (
"net"
"github.com/anon55555/mt"
)
2021-09-11 01:09:55 -07:00
2021-11-13 03:32:44 -08:00
// Kick sends mt.ToCltKick with the specified custom reason
2021-09-11 01:09:55 -07:00
// and closes the ClientConn.
func (cc *ClientConn) Kick(reason string) {
2021-09-11 01:25:59 -07:00
go func() {
2021-11-13 03:32:44 -08:00
ack, _ := cc.SendCmd(&mt.ToCltKick{
2021-09-11 01:25:59 -07:00
Reason: mt.Custom,
Custom: reason,
})
2021-09-11 01:09:55 -07:00
2021-09-11 01:25:59 -07:00
select {
case <-cc.Closed():
case <-ack:
cc.Close()
}
}()
2021-09-11 01:09:55 -07:00
}
2021-09-11 02:45:25 -07:00
// Ban disconnects the ClientConn and prevents the underlying
// network address from connecting again.
func (cc *ClientConn) Ban() error {
cc.Kick("Banned by proxy.")
2021-09-11 03:25:50 -07:00
return authIface.Ban(cc.RemoteAddr().(*net.UDPAddr).IP.String(), cc.name)
2021-09-11 02:45:25 -07:00
}
// Unban removes a player from the ban list. It accepts both
// network addresses and player names.
func Unban(id string) error {
return authIface.Unban(id)
}
2021-09-11 03:25:50 -07:00
// Banned reports whether a network address is banned.
func Banned(addr *net.UDPAddr) bool {
return authIface.Banned(addr)
}