Browse Source

MONITOR: Fix display of long lists

tags/v0.4.0
Daniel Oaks 7 years ago
parent
commit
1092caa190
5 changed files with 56 additions and 11 deletions
  1. 1
    0
      CHANGELOG.md
  2. 4
    0
      irc/constants.go
  3. 6
    7
      irc/isupport.go
  4. 10
    4
      irc/monitor.go
  5. 35
    0
      irc/util.go

+ 1
- 0
CHANGELOG.md View File

@@ -20,6 +20,7 @@ New release of Oragono!
20 20
 
21 21
 ### Fixed
22 22
 * Fixed bug where `HELP` wouldn't correctly display for operators, and added more help topics.
23
+* Fixed display of large `MONITOR` lists.
23 24
 
24 25
 
25 26
 ## [0.3.0] - 2016-10-23

+ 4
- 0
irc/constants.go View File

@@ -15,4 +15,8 @@ const (
15 15
 var (
16 16
 	// Ver is the full version of Oragono, used in responses to clients.
17 17
 	Ver = fmt.Sprintf("oragono-%s", SemVer)
18
+
19
+	// maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit.
20
+	// for instance, in MONITOR lists, RPL_ISUPPORT lists, etc.
21
+	maxLastArgLength = 400
18 22
 )

+ 6
- 7
irc/isupport.go View File

@@ -6,7 +6,6 @@ package irc
6 6
 import "fmt"
7 7
 
8 8
 const isupportSupportedString = "are supported by this server"
9
-const maxISupportLength = 400 // Max length of a single ISUPPORT token line
10 9
 
11 10
 // ISupportList holds a list of ISUPPORT tokens
12 11
 type ISupportList struct {
@@ -55,7 +54,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
55 54
 
56 55
 		token := fmt.Sprintf("-%s", name)
57 56
 
58
-		if len(token)+length <= maxISupportLength {
57
+		if len(token)+length <= maxLastArgLength {
59 58
 			// account for the space separating tokens
60 59
 			if len(cache) > 0 {
61 60
 				length++
@@ -64,7 +63,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
64 63
 			length += len(token)
65 64
 		}
66 65
 
67
-		if len(cache) == 13 || len(token)+length >= maxISupportLength {
66
+		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
68 67
 			cache = append(cache, isupportSupportedString)
69 68
 			replies = append(replies, cache)
70 69
 			cache = make([]string, 0)
@@ -81,7 +80,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
81 80
 
82 81
 		token := getTokenString(name, value)
83 82
 
84
-		if len(token)+length <= maxISupportLength {
83
+		if len(token)+length <= maxLastArgLength {
85 84
 			// account for the space separating tokens
86 85
 			if len(cache) > 0 {
87 86
 				length++
@@ -90,7 +89,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
90 89
 			length += len(token)
91 90
 		}
92 91
 
93
-		if len(cache) == 13 || len(token)+length >= maxISupportLength {
92
+		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
94 93
 			cache = append(cache, isupportSupportedString)
95 94
 			replies = append(replies, cache)
96 95
 			cache = make([]string, 0)
@@ -115,7 +114,7 @@ func (il *ISupportList) RegenerateCachedReply() {
115 114
 	for name, value := range il.Tokens {
116 115
 		token := getTokenString(name, value)
117 116
 
118
-		if len(token)+length <= maxISupportLength {
117
+		if len(token)+length <= maxLastArgLength {
119 118
 			// account for the space separating tokens
120 119
 			if len(cache) > 0 {
121 120
 				length++
@@ -124,7 +123,7 @@ func (il *ISupportList) RegenerateCachedReply() {
124 123
 			length += len(token)
125 124
 		}
126 125
 
127
-		if len(cache) == 13 || len(token)+length >= maxISupportLength {
126
+		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
128 127
 			cache = append(cache, isupportSupportedString)
129 128
 			il.CachedReply = append(il.CachedReply, cache)
130 129
 			cache = make([]string, 0)

+ 10
- 4
irc/monitor.go View File

@@ -116,7 +116,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
116 116
 	targets := strings.Split(msg.Params[1], ",")
117 117
 	for len(targets) > 0 {
118 118
 		// check name length
119
-		if len(targets[0]) < 1 {
119
+		if len(targets[0]) < 1 || len(targets[0]) > server.limits.NickLen {
120 120
 			targets = targets[1:]
121 121
 			continue
122 122
 		}
@@ -176,7 +176,9 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
176 176
 		monitorList = append(monitorList, name)
177 177
 	}
178 178
 
179
-	client.Send(nil, server.name, RPL_MONLIST, client.nick, strings.Join(monitorList, ","))
179
+	for _, line := range argsToStrings(maxLastArgLength, monitorList, ",") {
180
+		client.Send(nil, server.name, RPL_MONLIST, client.nick, line)
181
+	}
180 182
 
181 183
 	return false
182 184
 }
@@ -195,10 +197,14 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
195 197
 	}
196 198
 
197 199
 	if len(online) > 0 {
198
-		client.Send(nil, server.name, RPL_MONONLINE, client.nick, strings.Join(online, ","))
200
+		for _, line := range argsToStrings(maxLastArgLength, online, ",") {
201
+			client.Send(nil, server.name, RPL_MONONLINE, client.nick, line)
202
+		}
199 203
 	}
200 204
 	if len(offline) > 0 {
201
-		client.Send(nil, server.name, RPL_MONOFFLINE, client.nick, strings.Join(offline, ","))
205
+		for _, line := range argsToStrings(maxLastArgLength, offline, ",") {
206
+			client.Send(nil, server.name, RPL_MONOFFLINE, client.nick, line)
207
+		}
202 208
 	}
203 209
 
204 210
 	return false

+ 35
- 0
irc/util.go View File

@@ -0,0 +1,35 @@
1
+// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
2
+// released under the MIT license
3
+
4
+package irc
5
+
6
+// argsToStrings takes the arguments and splits them into a series of strings,
7
+// each argument separated by delim and each string bounded by maxLength.
8
+func argsToStrings(maxLength int, arguments []string, delim string) []string {
9
+	var messages []string
10
+
11
+	var buffer string
12
+	for {
13
+		if len(arguments) < 1 {
14
+			break
15
+		}
16
+
17
+		if len(buffer) > 0 && maxLength < len(buffer)+len(delim)+len(arguments[0]) {
18
+			messages = append(messages, buffer)
19
+			buffer = ""
20
+			continue
21
+		}
22
+
23
+		if len(buffer) > 1 {
24
+			buffer += delim
25
+		}
26
+		buffer += arguments[0]
27
+		arguments = arguments[1:]
28
+	}
29
+
30
+	if len(buffer) > 0 {
31
+		messages = append(messages, buffer)
32
+	}
33
+
34
+	return messages
35
+}

Loading…
Cancel
Save