From a5911ad14c9250cb5d5f584f0ef02a37ee8a1a6f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Fri, 12 Aug 2016 22:20:32 +1000 Subject: [PATCH] server: Add configurable NICKLEN and CHANNELLEN --- irc/config.go | 8 ++++++++ irc/server.go | 9 +++++++-- irc/strings.go | 6 ++++-- oragono.yaml | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/irc/config.go b/irc/config.go index f191f574..4524c726 100644 --- a/irc/config.go +++ b/irc/config.go @@ -66,6 +66,11 @@ type Config struct { Operator map[string]*PassConfig Theater map[string]*PassConfig + + Limits struct { + NickLen int `yaml:"nicklen"` + ChannelLen int `yaml:"channellen"` + } } func (conf *Config) Operators() map[Name][]byte { @@ -131,5 +136,8 @@ 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 { + 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 a692dca6..43e4a694 100644 --- a/irc/server.go +++ b/irc/server.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "os/signal" + "regexp" "strconv" "strings" "syscall" @@ -94,6 +95,10 @@ func NewServer(config *Config) *Server { } } + //TODO(dan): Hot damn this is an ugly hack. Fix it properly at some point. + ChannelNameExpr = regexp.MustCompile(fmt.Sprintf(`^[&!#+][\pL\pN]{1,%d}$`, config.Limits.ChannelLen)) + NicknameExpr = regexp.MustCompile(fmt.Sprintf("^[\\pL\\pN\\pP\\pS]{1,%d}$", config.Limits.NickLen)) + if config.Server.Password != "" { server.password = config.Server.PasswordBytes() } @@ -114,7 +119,7 @@ func NewServer(config *Config) *Server { server.isupport = NewISupportList() server.isupport.Add("CASEMAPPING", "ascii") // server.isupport.Add("CHANMODES", "") //TODO(dan): Channel mode list here - // server.isupport.Add("CHANNELLEN", "") //TODO(dan): Support channel length + server.isupport.Add("CHANNELLEN", strconv.Itoa(config.Limits.ChannelLen)) server.isupport.Add("CHANTYPES", "#") server.isupport.Add("EXCEPTS", "") server.isupport.Add("INVEX", "") @@ -122,7 +127,7 @@ func NewServer(config *Config) *Server { // 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) - // server.isupport.Add("NICKLEN", "") //TODO(dan): Support nick length + server.isupport.Add("NICKLEN", strconv.Itoa(config.Limits.NickLen)) server.isupport.Add("PREFIX", "(qaohv)~&@%+") // server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Autogenerate based on PREFIXes, support STATUSMSG // server.isupport.Add("TARGMAX", "") //TODO(dan): Support this diff --git a/irc/strings.go b/irc/strings.go index 160997cc..6b67ac8c 100644 --- a/irc/strings.go +++ b/irc/strings.go @@ -14,8 +14,10 @@ import ( var ( // regexps - ChannelNameExpr = regexp.MustCompile(`^[&!#+][\pL\pN]{1,63}$`) - NicknameExpr = regexp.MustCompile("^[\\pL\\pN\\pP\\pS]{1,32}$") + // these get replaced with real regexes at server load time + + ChannelNameExpr = regexp.MustCompile("^$") + NicknameExpr = regexp.MustCompile("^$") ) // Names are normalized and canonicalized to remove formatting marks diff --git a/oragono.yaml b/oragono.yaml index 98e9d7b7..54808407 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -56,3 +56,11 @@ operator: # password to login with /OPER command # generated using "oragono genpasswd" password: JDJhJDA0JE1vZmwxZC9YTXBhZ3RWT2xBbkNwZnV3R2N6VFUwQUI0RUJRVXRBRHliZVVoa0VYMnlIaGsu + +# limits - these need to be the same across the network +limits: + # nicklen is the max nick length allowed + nicklen: 32 + + # channellen is the max channel length allowed + channellen: 64