|
@@ -52,10 +52,19 @@ type IrcMessage struct {
|
52
|
52
|
Prefix string
|
53
|
53
|
Command string
|
54
|
54
|
Params []string
|
|
55
|
+ forceTrailing bool
|
55
|
56
|
tags map[string]string
|
56
|
57
|
clientOnlyTags map[string]string
|
57
|
58
|
}
|
58
|
59
|
|
|
60
|
+// ForceTrailing ensures that when the message is serialized, the final parameter
|
|
61
|
+// will be encoded as a "trailing parameter" (preceded by a colon). This is
|
|
62
|
+// almost never necessary and should not be used except when having to interact
|
|
63
|
+// with broken implementations that don't correctly interpret IRC messages.
|
|
64
|
+func (msg *IrcMessage) ForceTrailing() {
|
|
65
|
+ msg.forceTrailing = true
|
|
66
|
+}
|
|
67
|
+
|
59
|
68
|
// GetTag returns whether a tag is present, and if so, what its value is.
|
60
|
69
|
func (msg *IrcMessage) GetTag(tagName string) (present bool, value string) {
|
61
|
70
|
if len(tagName) == 0 {
|
|
@@ -321,6 +330,10 @@ func (ircmsg *IrcMessage) LineBytesStrict(fromClient bool, truncateLen int) ([]b
|
321
|
330
|
return ircmsg.line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen)
|
322
|
331
|
}
|
323
|
332
|
|
|
333
|
+func paramRequiresTrailing(param string) bool {
|
|
334
|
+ return len(param) == 0 || strings.IndexByte(param, ' ') != -1 || param[0] == ':'
|
|
335
|
+}
|
|
336
|
+
|
324
|
337
|
// line returns a sendable line created from an IrcMessage.
|
325
|
338
|
func (ircmsg *IrcMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen int) ([]byte, error) {
|
326
|
339
|
if len(ircmsg.Command) < 1 {
|
|
@@ -376,11 +389,12 @@ func (ircmsg *IrcMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD
|
376
|
389
|
|
377
|
390
|
for i, param := range ircmsg.Params {
|
378
|
391
|
buf.WriteByte(' ')
|
379
|
|
- if len(param) < 1 || strings.IndexByte(param, ' ') != -1 || param[0] == ':' {
|
380
|
|
- if i != len(ircmsg.Params)-1 {
|
381
|
|
- return nil, ErrorBadParam
|
382
|
|
- }
|
|
392
|
+ requiresTrailing := paramRequiresTrailing(param)
|
|
393
|
+ lastParam := i == len(ircmsg.Params)-1
|
|
394
|
+ if (requiresTrailing || ircmsg.forceTrailing) && lastParam {
|
383
|
395
|
buf.WriteByte(':')
|
|
396
|
+ } else if requiresTrailing && !lastParam {
|
|
397
|
+ return nil, ErrorBadParam
|
384
|
398
|
}
|
385
|
399
|
buf.WriteString(param)
|
386
|
400
|
}
|