mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
limit the number of channels a client can join
This commit is contained in:
parent
ff7bbc4a9c
commit
eff2571096
@ -294,9 +294,10 @@ type Config struct {
|
||||
Accounts AccountConfig
|
||||
|
||||
Channels struct {
|
||||
DefaultModes *string `yaml:"default-modes"`
|
||||
defaultModes modes.Modes
|
||||
Registration ChannelRegistrationConfig
|
||||
DefaultModes *string `yaml:"default-modes"`
|
||||
defaultModes modes.Modes
|
||||
MaxChannelsPerClient int `yaml:"max-channels-per-client"`
|
||||
Registration ChannelRegistrationConfig
|
||||
}
|
||||
|
||||
OperClasses map[string]*OperClassConfig `yaml:"oper-classes"`
|
||||
@ -790,6 +791,9 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
config.Accounts.Registration.BcryptCost = passwd.DefaultCost
|
||||
}
|
||||
|
||||
if config.Channels.MaxChannelsPerClient == 0 {
|
||||
config.Channels.MaxChannelsPerClient = 100
|
||||
}
|
||||
if config.Channels.Registration.MaxChannelsPerAccount == 0 {
|
||||
config.Channels.Registration.MaxChannelsPerAccount = 10
|
||||
}
|
||||
|
@ -184,6 +184,12 @@ func (client *Client) Channels() (result []*Channel) {
|
||||
return
|
||||
}
|
||||
|
||||
func (client *Client) NumChannels() int {
|
||||
client.stateMutex.RLock()
|
||||
defer client.stateMutex.RUnlock()
|
||||
return len(client.channels)
|
||||
}
|
||||
|
||||
func (client *Client) WhoWas() (result WhoWas) {
|
||||
return client.Details().WhoWas
|
||||
}
|
||||
|
@ -1148,7 +1148,13 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
|
||||
keys = strings.Split(msg.Params[1], ",")
|
||||
}
|
||||
|
||||
config := server.Config()
|
||||
oper := client.Oper()
|
||||
for i, name := range channels {
|
||||
if config.Channels.MaxChannelsPerClient <= client.NumChannels() && oper == nil {
|
||||
rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.Nick(), name, client.t("You have joined too many channels already"))
|
||||
return false
|
||||
}
|
||||
var key string
|
||||
if len(keys) > i {
|
||||
key = keys[i]
|
||||
|
@ -275,6 +275,9 @@ channels:
|
||||
# see /QUOTE HELP cmodes for more channel modes
|
||||
default-modes: +nt
|
||||
|
||||
# how many channels can a client be in at once?
|
||||
max-channels-per-client: 100
|
||||
|
||||
# channel registration - requires an account
|
||||
registration:
|
||||
# can users register new channels?
|
||||
|
Loading…
Reference in New Issue
Block a user