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:
parent
ff7bbc4a9c
commit
eff2571096
@ -294,9 +294,10 @@ type Config struct {
|
|||||||
Accounts AccountConfig
|
Accounts AccountConfig
|
||||||
|
|
||||||
Channels struct {
|
Channels struct {
|
||||||
DefaultModes *string `yaml:"default-modes"`
|
DefaultModes *string `yaml:"default-modes"`
|
||||||
defaultModes modes.Modes
|
defaultModes modes.Modes
|
||||||
Registration ChannelRegistrationConfig
|
MaxChannelsPerClient int `yaml:"max-channels-per-client"`
|
||||||
|
Registration ChannelRegistrationConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
OperClasses map[string]*OperClassConfig `yaml:"oper-classes"`
|
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
|
config.Accounts.Registration.BcryptCost = passwd.DefaultCost
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Channels.MaxChannelsPerClient == 0 {
|
||||||
|
config.Channels.MaxChannelsPerClient = 100
|
||||||
|
}
|
||||||
if config.Channels.Registration.MaxChannelsPerAccount == 0 {
|
if config.Channels.Registration.MaxChannelsPerAccount == 0 {
|
||||||
config.Channels.Registration.MaxChannelsPerAccount = 10
|
config.Channels.Registration.MaxChannelsPerAccount = 10
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,12 @@ func (client *Client) Channels() (result []*Channel) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) NumChannels() int {
|
||||||
|
client.stateMutex.RLock()
|
||||||
|
defer client.stateMutex.RUnlock()
|
||||||
|
return len(client.channels)
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) WhoWas() (result WhoWas) {
|
func (client *Client) WhoWas() (result WhoWas) {
|
||||||
return client.Details().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], ",")
|
keys = strings.Split(msg.Params[1], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config := server.Config()
|
||||||
|
oper := client.Oper()
|
||||||
for i, name := range channels {
|
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
|
var key string
|
||||||
if len(keys) > i {
|
if len(keys) > i {
|
||||||
key = keys[i]
|
key = keys[i]
|
||||||
|
@ -275,6 +275,9 @@ channels:
|
|||||||
# see /QUOTE HELP cmodes for more channel modes
|
# see /QUOTE HELP cmodes for more channel modes
|
||||||
default-modes: +nt
|
default-modes: +nt
|
||||||
|
|
||||||
|
# how many channels can a client be in at once?
|
||||||
|
max-channels-per-client: 100
|
||||||
|
|
||||||
# channel registration - requires an account
|
# channel registration - requires an account
|
||||||
registration:
|
registration:
|
||||||
# can users register new channels?
|
# can users register new channels?
|
||||||
|
Loading…
Reference in New Issue
Block a user