3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

limit the number of channels a client can join

This commit is contained in:
Shivaram Lingamneni 2019-02-06 04:55:05 -05:00
parent ff7bbc4a9c
commit eff2571096
4 changed files with 22 additions and 3 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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]

View File

@ -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?