mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-31 11:13:05 -07:00
modes: Limit length of beI mode lists
This commit is contained in:
@@ -136,6 +136,7 @@ type Config struct {
|
||||
TopicLen uint `yaml:"topiclen"`
|
||||
WhowasEntries uint `yaml:"whowas-entries"`
|
||||
MonitorEntries uint `yaml:"monitor-entries"`
|
||||
ChanListModes uint `yaml:"chan-list-modes"`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -404,6 +404,9 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
changes = append(changes, &change)
|
||||
}
|
||||
|
||||
// so we only output one warning for each list type when full
|
||||
listFullWarned := make(map[ChannelMode]bool)
|
||||
|
||||
for _, change := range changes {
|
||||
switch change.mode {
|
||||
case BanMask, ExceptMask, InviteMask:
|
||||
@@ -428,6 +431,14 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
|
||||
switch change.op {
|
||||
case Add:
|
||||
if len(list.masks) >= server.limits.ChanListModes {
|
||||
if !listFullWarned[change.mode] {
|
||||
client.Send(nil, server.name, ERR_BANLISTFULL, client.nick, channel.name, change.mode.String(), "Channel list is full")
|
||||
listFullWarned[change.mode] = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
list.Add(mask)
|
||||
applied = append(applied, change)
|
||||
|
||||
|
||||
+4
-1
@@ -39,6 +39,7 @@ type Limits struct {
|
||||
MonitorEntries int
|
||||
NickLen int
|
||||
TopicLen int
|
||||
ChanListModes int
|
||||
}
|
||||
|
||||
// ListenerInterface represents an interface for a listener.
|
||||
@@ -166,6 +167,7 @@ func NewServer(configFilename string, config *Config) *Server {
|
||||
MonitorEntries: int(config.Limits.MonitorEntries),
|
||||
NickLen: int(config.Limits.NickLen),
|
||||
TopicLen: int(config.Limits.TopicLen),
|
||||
ChanListModes: int(config.Limits.ChanListModes),
|
||||
},
|
||||
listeners: make(map[string]ListenerInterface),
|
||||
monitoring: make(map[string][]Client),
|
||||
@@ -266,7 +268,7 @@ func (server *Server) setISupport() {
|
||||
server.isupport.Add("EXCEPTS", "")
|
||||
server.isupport.Add("INVEX", "")
|
||||
server.isupport.Add("KICKLEN", strconv.Itoa(server.limits.KickLen))
|
||||
// server.isupport.Add("MAXLIST", "") //TODO(dan): Support max list length?
|
||||
server.isupport.Add("MAXLIST", fmt.Sprintf("beI:%s", strconv.Itoa(server.limits.ChanListModes)))
|
||||
// server.isupport.Add("MODES", "") //TODO(dan): Support max modes?
|
||||
server.isupport.Add("MONITOR", strconv.Itoa(server.limits.MonitorEntries))
|
||||
server.isupport.Add("NETWORK", server.networkName)
|
||||
@@ -1056,6 +1058,7 @@ func (server *Server) rehash() error {
|
||||
MonitorEntries: int(config.Limits.MonitorEntries),
|
||||
NickLen: int(config.Limits.NickLen),
|
||||
TopicLen: int(config.Limits.TopicLen),
|
||||
ChanListModes: int(config.Limits.ChanListModes),
|
||||
}
|
||||
server.operclasses = *operclasses
|
||||
server.operators = opers
|
||||
|
||||
Reference in New Issue
Block a user