From 79d831bbb77ce4bdef36979d2c918d8583049508 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 12 Sep 2016 12:22:50 +1000 Subject: [PATCH] channel: Add KICKLEN and TOPICLEN --- irc/channel.go | 8 ++++++++ irc/config.go | 4 +++- irc/server.go | 29 ++++++++++++++++++++--------- oragono.yaml | 6 ++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index ab45dd57..55b2e637 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -270,6 +270,10 @@ func (channel *Channel) SetTopic(client *Client, topic string) { return } + if len(topic) > client.server.limits.Topic { + topic = topic[:client.server.limits.Topic] + } + channel.topic = topic channel.topicSetBy = client.nickString channel.topicSetTime = time.Now() @@ -478,6 +482,10 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) { return } + if len(comment) > client.server.limits.Kick { + comment = comment[:client.server.limits.Kick] + } + for member := range channel.members { member.Send(nil, client.nickMaskString, "KICK", channel.nameString, target.nickString, comment) } diff --git a/irc/config.go b/irc/config.go index 5ada6740..7b51ec54 100644 --- a/irc/config.go +++ b/irc/config.go @@ -99,6 +99,8 @@ type Config struct { Limits struct { NickLen int `yaml:"nicklen"` ChannelLen int `yaml:"channellen"` + KickLen int `yaml:"kicklen"` + TopicLen int `yaml:"topiclen"` WhowasEntries uint `yaml:"whowas-entries"` } } @@ -169,7 +171,7 @@ func LoadConfig(filename string) (config *Config, err error) { if len(config.Server.Listen) == 0 { return nil, errors.New("Server listening addresses missing") } - if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 { + if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.TopicLen < 1 { return nil, errors.New("Limits aren't setup properly, check them and make them sane") } return config, nil diff --git a/irc/server.go b/irc/server.go index 266d52a7..efb7814f 100644 --- a/irc/server.go +++ b/irc/server.go @@ -26,6 +26,12 @@ import ( "github.com/tidwall/buntdb" ) +// Limits holds the maximum limits for various things such as topic lengths +type Limits struct { + Kick int + Topic int +} + type Server struct { accounts map[string]*ClientAccount channels ChannelNameMap @@ -35,6 +41,7 @@ type Server struct { db *sql.DB store buntdb.DB idle chan *Client + limits Limits motdLines []string name Name nameString string // cache for server name string since it's used with almost every reply @@ -67,13 +74,17 @@ type clientConn struct { func NewServer(config *Config) *Server { server := &Server{ - accounts: make(map[string]*ClientAccount), - channels: make(ChannelNameMap), - clients: NewClientLookupSet(), - commands: make(chan Command), - ctime: time.Now(), - db: OpenDB(config.Datastore.SQLitePath), - idle: make(chan *Client), + accounts: make(map[string]*ClientAccount), + channels: make(ChannelNameMap), + clients: NewClientLookupSet(), + commands: make(chan Command), + ctime: time.Now(), + db: OpenDB(config.Datastore.SQLitePath), + idle: make(chan *Client), + limits: Limits{ + Kick: config.Limits.KickLen, + Topic: config.Limits.TopicLen, + }, name: NewName(config.Server.Name), nameString: NewName(config.Server.Name).String(), newConns: make(chan clientConn), @@ -166,7 +177,7 @@ func NewServer(config *Config) *Server { server.isupport.Add("CHANTYPES", "#") server.isupport.Add("EXCEPTS", "") server.isupport.Add("INVEX", "") - // server.isupport.Add("KICKLEN", "") //TODO(dan): Support kick length? + server.isupport.Add("KICKLEN", strconv.Itoa(server.limits.Kick)) // server.isupport.Add("MAXLIST", "") //TODO(dan): Support max list length? // server.isupport.Add("MODES", "") //TODO(dan): Support max modes? server.isupport.Add("NETWORK", config.Network.Name) @@ -174,7 +185,7 @@ func NewServer(config *Config) *Server { server.isupport.Add("PREFIX", "(qaohv)~&@%+") // server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Support STATUSMSG // server.isupport.Add("TARGMAX", "") //TODO(dan): Support this - // server.isupport.Add("TOPICLEN", "") //TODO(dan): Support topic length + server.isupport.Add("TOPICLEN", strconv.Itoa(server.limits.Topic)) // account registration if server.accountRegistration.Enabled { diff --git a/oragono.yaml b/oragono.yaml index c9b3cd48..81da4b81 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -87,5 +87,11 @@ limits: # channellen is the max channel length allowed channellen: 64 + # kicklen is the maximum length of a kick message + kicklen: 390 + + # topiclen is the maximum length of a channel topic + topiclen: 390 + # whowas entries to store whowas-entries: 100