|
@@ -1,34 +1,37 @@
|
1
|
1
|
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
|
2
|
2
|
// released under the MIT license
|
3
|
3
|
|
4
|
|
-package irc
|
|
4
|
+package isupport
|
5
|
5
|
|
6
|
6
|
import "fmt"
|
7
|
7
|
import "sort"
|
8
|
8
|
|
9
|
|
-const isupportSupportedString = "are supported by this server"
|
|
9
|
+const (
|
|
10
|
+ maxLastArgLength = 400
|
|
11
|
+ supportedString = "are supported by this server"
|
|
12
|
+)
|
10
|
13
|
|
11
|
|
-// ISupportList holds a list of ISUPPORT tokens
|
12
|
|
-type ISupportList struct {
|
|
14
|
+// List holds a list of ISUPPORT tokens
|
|
15
|
+type List struct {
|
13
|
16
|
Tokens map[string]*string
|
14
|
17
|
CachedReply [][]string
|
15
|
18
|
}
|
16
|
19
|
|
17
|
|
-// NewISupportList returns a new ISupportList
|
18
|
|
-func NewISupportList() *ISupportList {
|
19
|
|
- var il ISupportList
|
|
20
|
+// NewList returns a new List
|
|
21
|
+func NewList() *List {
|
|
22
|
+ var il List
|
20
|
23
|
il.Tokens = make(map[string]*string)
|
21
|
24
|
il.CachedReply = make([][]string, 0)
|
22
|
25
|
return &il
|
23
|
26
|
}
|
24
|
27
|
|
25
|
28
|
// Add adds an RPL_ISUPPORT token to our internal list
|
26
|
|
-func (il *ISupportList) Add(name string, value string) {
|
|
29
|
+func (il *List) Add(name string, value string) {
|
27
|
30
|
il.Tokens[name] = &value
|
28
|
31
|
}
|
29
|
32
|
|
30
|
33
|
// AddNoValue adds an RPL_ISUPPORT token that does not have a value
|
31
|
|
-func (il *ISupportList) AddNoValue(name string) {
|
|
34
|
+func (il *List) AddNoValue(name string) {
|
32
|
35
|
il.Tokens[name] = nil
|
33
|
36
|
}
|
34
|
37
|
|
|
@@ -41,7 +44,7 @@ func getTokenString(name string, value *string) string {
|
41
|
44
|
}
|
42
|
45
|
|
43
|
46
|
// GetDifference returns the difference between two token lists.
|
44
|
|
-func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
|
47
|
+func (il *List) GetDifference(newil *List) [][]string {
|
45
|
48
|
var outTokens sort.StringSlice
|
46
|
49
|
|
47
|
50
|
// append removed tokens
|
|
@@ -86,7 +89,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
86
|
89
|
}
|
87
|
90
|
|
88
|
91
|
if len(cache) == 13 || len(token)+length >= maxLastArgLength {
|
89
|
|
- cache = append(cache, isupportSupportedString)
|
|
92
|
+ cache = append(cache, supportedString)
|
90
|
93
|
replies = append(replies, cache)
|
91
|
94
|
cache = make([]string, 0)
|
92
|
95
|
length = 0
|
|
@@ -94,7 +97,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
94
|
97
|
}
|
95
|
98
|
|
96
|
99
|
if len(cache) > 0 {
|
97
|
|
- cache = append(cache, isupportSupportedString)
|
|
100
|
+ cache = append(cache, supportedString)
|
98
|
101
|
replies = append(replies, cache)
|
99
|
102
|
}
|
100
|
103
|
|
|
@@ -102,7 +105,7 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
102
|
105
|
}
|
103
|
106
|
|
104
|
107
|
// RegenerateCachedReply regenerates the cached RPL_ISUPPORT reply
|
105
|
|
-func (il *ISupportList) RegenerateCachedReply() {
|
|
108
|
+func (il *List) RegenerateCachedReply() {
|
106
|
109
|
il.CachedReply = make([][]string, 0)
|
107
|
110
|
var length int // Length of the current cache
|
108
|
111
|
var cache []string // Token list cache
|
|
@@ -127,7 +130,7 @@ func (il *ISupportList) RegenerateCachedReply() {
|
127
|
130
|
}
|
128
|
131
|
|
129
|
132
|
if len(cache) == 13 || len(token)+length >= maxLastArgLength {
|
130
|
|
- cache = append(cache, isupportSupportedString)
|
|
133
|
+ cache = append(cache, supportedString)
|
131
|
134
|
il.CachedReply = append(il.CachedReply, cache)
|
132
|
135
|
cache = make([]string, 0)
|
133
|
136
|
length = 0
|
|
@@ -135,15 +138,7 @@ func (il *ISupportList) RegenerateCachedReply() {
|
135
|
138
|
}
|
136
|
139
|
|
137
|
140
|
if len(cache) > 0 {
|
138
|
|
- cache = append(cache, isupportSupportedString)
|
|
141
|
+ cache = append(cache, supportedString)
|
139
|
142
|
il.CachedReply = append(il.CachedReply, cache)
|
140
|
143
|
}
|
141
|
144
|
}
|
142
|
|
-
|
143
|
|
-// RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses.
|
144
|
|
-func (client *Client) RplISupport() {
|
145
|
|
- for _, tokenline := range client.server.getISupport().CachedReply {
|
146
|
|
- // ugly trickery ahead
|
147
|
|
- client.Send(nil, client.server.name, RPL_ISUPPORT, append([]string{client.nick}, tokenline...)...)
|
148
|
|
- }
|
149
|
|
-}
|