Browse Source

server: Add configurable NICKLEN and CHANNELLEN

tags/v0.1.0
Daniel Oaks 7 years ago
parent
commit
a5911ad14c
4 changed files with 27 additions and 4 deletions
  1. 8
    0
      irc/config.go
  2. 7
    2
      irc/server.go
  3. 4
    2
      irc/strings.go
  4. 8
    0
      oragono.yaml

+ 8
- 0
irc/config.go View File

@@ -66,6 +66,11 @@ type Config struct {
66 66
 	Operator map[string]*PassConfig
67 67
 
68 68
 	Theater map[string]*PassConfig
69
+
70
+	Limits struct {
71
+		NickLen    int `yaml:"nicklen"`
72
+		ChannelLen int `yaml:"channellen"`
73
+	}
69 74
 }
70 75
 
71 76
 func (conf *Config) Operators() map[Name][]byte {
@@ -131,5 +136,8 @@ func LoadConfig(filename string) (config *Config, err error) {
131 136
 	if len(config.Server.Listen) == 0 {
132 137
 		return nil, errors.New("Server listening addresses missing")
133 138
 	}
139
+	if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 {
140
+		return nil, errors.New("Limits aren't setup properly, check them and make them sane")
141
+	}
134 142
 	return config, nil
135 143
 }

+ 7
- 2
irc/server.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"net/http"
16 16
 	"os"
17 17
 	"os/signal"
18
+	"regexp"
18 19
 	"strconv"
19 20
 	"strings"
20 21
 	"syscall"
@@ -94,6 +95,10 @@ func NewServer(config *Config) *Server {
94 95
 		}
95 96
 	}
96 97
 
98
+	//TODO(dan): Hot damn this is an ugly hack. Fix it properly at some point.
99
+	ChannelNameExpr = regexp.MustCompile(fmt.Sprintf(`^[&!#+][\pL\pN]{1,%d}$`, config.Limits.ChannelLen))
100
+	NicknameExpr = regexp.MustCompile(fmt.Sprintf("^[\\pL\\pN\\pP\\pS]{1,%d}$", config.Limits.NickLen))
101
+
97 102
 	if config.Server.Password != "" {
98 103
 		server.password = config.Server.PasswordBytes()
99 104
 	}
@@ -114,7 +119,7 @@ func NewServer(config *Config) *Server {
114 119
 	server.isupport = NewISupportList()
115 120
 	server.isupport.Add("CASEMAPPING", "ascii")
116 121
 	// server.isupport.Add("CHANMODES", "")  //TODO(dan): Channel mode list here
117
-	// server.isupport.Add("CHANNELLEN", "") //TODO(dan): Support channel length
122
+	server.isupport.Add("CHANNELLEN", strconv.Itoa(config.Limits.ChannelLen))
118 123
 	server.isupport.Add("CHANTYPES", "#")
119 124
 	server.isupport.Add("EXCEPTS", "")
120 125
 	server.isupport.Add("INVEX", "")
@@ -122,7 +127,7 @@ func NewServer(config *Config) *Server {
122 127
 	// server.isupport.Add("MAXLIST", "") //TODO(dan): Support max list length?
123 128
 	// server.isupport.Add("MODES", "")   //TODO(dan): Support max modes?
124 129
 	server.isupport.Add("NETWORK", config.Network.Name)
125
-	// server.isupport.Add("NICKLEN", "") //TODO(dan): Support nick length
130
+	server.isupport.Add("NICKLEN", strconv.Itoa(config.Limits.NickLen))
126 131
 	server.isupport.Add("PREFIX", "(qaohv)~&@%+")
127 132
 	// server.isupport.Add("STATUSMSG", "@+") //TODO(dan): Autogenerate based on PREFIXes, support STATUSMSG
128 133
 	// server.isupport.Add("TARGMAX", "")  //TODO(dan): Support this

+ 4
- 2
irc/strings.go View File

@@ -14,8 +14,10 @@ import (
14 14
 
15 15
 var (
16 16
 	// regexps
17
-	ChannelNameExpr = regexp.MustCompile(`^[&!#+][\pL\pN]{1,63}$`)
18
-	NicknameExpr    = regexp.MustCompile("^[\\pL\\pN\\pP\\pS]{1,32}$")
17
+	// these get replaced with real regexes at server load time
18
+
19
+	ChannelNameExpr = regexp.MustCompile("^$")
20
+	NicknameExpr    = regexp.MustCompile("^$")
19 21
 )
20 22
 
21 23
 // Names are normalized and canonicalized to remove formatting marks

+ 8
- 0
oragono.yaml View File

@@ -56,3 +56,11 @@ operator:
56 56
         # password to login with /OPER command
57 57
         # generated using  "oragono genpasswd"
58 58
         password: JDJhJDA0JE1vZmwxZC9YTXBhZ3RWT2xBbkNwZnV3R2N6VFUwQUI0RUJRVXRBRHliZVVoa0VYMnlIaGsu
59
+
60
+# limits - these need to be the same across the network
61
+limits:
62
+    # nicklen is the max nick length allowed
63
+    nicklen: 32
64
+
65
+    # channellen is the max channel length allowed
66
+    channellen: 64

Loading…
Cancel
Save