Browse Source

Split isupport to its' own subpackage

tags/v0.9.2-beta
Daniel Oaks 6 years ago
parent
commit
4aa52956e5
5 changed files with 35 additions and 29 deletions
  1. 8
    0
      irc/client.go
  2. 3
    1
      irc/getters.go
  3. 18
    23
      irc/isupport/list.go
  4. 3
    3
      irc/isupport/list_test.go
  5. 3
    2
      irc/server.go

+ 8
- 0
irc/client.go View File

494
 	return client.account != nil && client.account != &NoAccount
494
 	return client.account != nil && client.account != &NoAccount
495
 }
495
 }
496
 
496
 
497
+// RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses.
498
+func (client *Client) RplISupport() {
499
+	for _, tokenline := range client.server.getISupport().CachedReply {
500
+		// ugly trickery ahead
501
+		client.Send(nil, client.server.name, RPL_ISUPPORT, append([]string{client.nick}, tokenline...)...)
502
+	}
503
+}
504
+
497
 // Quit sends the given quit message to the client (but does not destroy them).
505
 // Quit sends the given quit message to the client (but does not destroy them).
498
 func (client *Client) Quit(message string) {
506
 func (client *Client) Quit(message string) {
499
 	client.quitMutex.Lock()
507
 	client.quitMutex.Lock()

+ 3
- 1
irc/getters.go View File

3
 
3
 
4
 package irc
4
 package irc
5
 
5
 
6
-func (server *Server) getISupport() *ISupportList {
6
+import "github.com/oragono/oragono/irc/isupport"
7
+
8
+func (server *Server) getISupport() *isupport.List {
7
 	server.configurableStateMutex.RLock()
9
 	server.configurableStateMutex.RLock()
8
 	defer server.configurableStateMutex.RUnlock()
10
 	defer server.configurableStateMutex.RUnlock()
9
 	return server.isupport
11
 	return server.isupport

irc/isupport.go → irc/isupport/list.go View File

1
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
1
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
2
 // released under the MIT license
2
 // released under the MIT license
3
 
3
 
4
-package irc
4
+package isupport
5
 
5
 
6
 import "fmt"
6
 import "fmt"
7
 import "sort"
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
 	Tokens      map[string]*string
16
 	Tokens      map[string]*string
14
 	CachedReply [][]string
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
 	il.Tokens = make(map[string]*string)
23
 	il.Tokens = make(map[string]*string)
21
 	il.CachedReply = make([][]string, 0)
24
 	il.CachedReply = make([][]string, 0)
22
 	return &il
25
 	return &il
23
 }
26
 }
24
 
27
 
25
 // Add adds an RPL_ISUPPORT token to our internal list
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
 	il.Tokens[name] = &value
30
 	il.Tokens[name] = &value
28
 }
31
 }
29
 
32
 
30
 // AddNoValue adds an RPL_ISUPPORT token that does not have a value
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
 	il.Tokens[name] = nil
35
 	il.Tokens[name] = nil
33
 }
36
 }
34
 
37
 
41
 }
44
 }
42
 
45
 
43
 // GetDifference returns the difference between two token lists.
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
 	var outTokens sort.StringSlice
48
 	var outTokens sort.StringSlice
46
 
49
 
47
 	// append removed tokens
50
 	// append removed tokens
86
 		}
89
 		}
87
 
90
 
88
 		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
91
 		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
89
-			cache = append(cache, isupportSupportedString)
92
+			cache = append(cache, supportedString)
90
 			replies = append(replies, cache)
93
 			replies = append(replies, cache)
91
 			cache = make([]string, 0)
94
 			cache = make([]string, 0)
92
 			length = 0
95
 			length = 0
94
 	}
97
 	}
95
 
98
 
96
 	if len(cache) > 0 {
99
 	if len(cache) > 0 {
97
-		cache = append(cache, isupportSupportedString)
100
+		cache = append(cache, supportedString)
98
 		replies = append(replies, cache)
101
 		replies = append(replies, cache)
99
 	}
102
 	}
100
 
103
 
102
 }
105
 }
103
 
106
 
104
 // RegenerateCachedReply regenerates the cached RPL_ISUPPORT reply
107
 // RegenerateCachedReply regenerates the cached RPL_ISUPPORT reply
105
-func (il *ISupportList) RegenerateCachedReply() {
108
+func (il *List) RegenerateCachedReply() {
106
 	il.CachedReply = make([][]string, 0)
109
 	il.CachedReply = make([][]string, 0)
107
 	var length int     // Length of the current cache
110
 	var length int     // Length of the current cache
108
 	var cache []string // Token list cache
111
 	var cache []string // Token list cache
127
 		}
130
 		}
128
 
131
 
129
 		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
132
 		if len(cache) == 13 || len(token)+length >= maxLastArgLength {
130
-			cache = append(cache, isupportSupportedString)
133
+			cache = append(cache, supportedString)
131
 			il.CachedReply = append(il.CachedReply, cache)
134
 			il.CachedReply = append(il.CachedReply, cache)
132
 			cache = make([]string, 0)
135
 			cache = make([]string, 0)
133
 			length = 0
136
 			length = 0
135
 	}
138
 	}
136
 
139
 
137
 	if len(cache) > 0 {
140
 	if len(cache) > 0 {
138
-		cache = append(cache, isupportSupportedString)
141
+		cache = append(cache, supportedString)
139
 		il.CachedReply = append(il.CachedReply, cache)
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
-}

irc/isupport_test.go → irc/isupport/list_test.go View File

1
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
1
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
2
 // released under the MIT license
2
 // released under the MIT license
3
 
3
 
4
-package irc
4
+package isupport
5
 
5
 
6
 import (
6
 import (
7
 	"reflect"
7
 	"reflect"
10
 
10
 
11
 func TestISUPPORT(t *testing.T) {
11
 func TestISUPPORT(t *testing.T) {
12
 	// create first list
12
 	// create first list
13
-	tList1 := NewISupportList()
13
+	tList1 := NewList()
14
 	tList1.Add("SASL", "yes")
14
 	tList1.Add("SASL", "yes")
15
 	tList1.Add("CASEMAPPING", "rfc1459-strict")
15
 	tList1.Add("CASEMAPPING", "rfc1459-strict")
16
 	tList1.Add("INVEX", "i")
16
 	tList1.Add("INVEX", "i")
24
 	}
24
 	}
25
 
25
 
26
 	// create second list
26
 	// create second list
27
-	tList2 := NewISupportList()
27
+	tList2 := NewList()
28
 	tList2.Add("SASL", "yes")
28
 	tList2.Add("SASL", "yes")
29
 	tList2.Add("CASEMAPPING", "ascii")
29
 	tList2.Add("CASEMAPPING", "ascii")
30
 	tList2.AddNoValue("INVEX")
30
 	tList2.AddNoValue("INVEX")

+ 3
- 2
irc/server.go View File

24
 	"github.com/goshuirc/irc-go/ircfmt"
24
 	"github.com/goshuirc/irc-go/ircfmt"
25
 	"github.com/goshuirc/irc-go/ircmsg"
25
 	"github.com/goshuirc/irc-go/ircmsg"
26
 	"github.com/oragono/oragono/irc/caps"
26
 	"github.com/oragono/oragono/irc/caps"
27
+	"github.com/oragono/oragono/irc/isupport"
27
 	"github.com/oragono/oragono/irc/logger"
28
 	"github.com/oragono/oragono/irc/logger"
28
 	"github.com/oragono/oragono/irc/sno"
29
 	"github.com/oragono/oragono/irc/sno"
29
 	"github.com/tidwall/buntdb"
30
 	"github.com/tidwall/buntdb"
91
 	defaultChannelModes          Modes
92
 	defaultChannelModes          Modes
92
 	dlines                       *DLineManager
93
 	dlines                       *DLineManager
93
 	loggingRawIO                 bool
94
 	loggingRawIO                 bool
94
-	isupport                     *ISupportList
95
+	isupport                     *isupport.List
95
 	klines                       *KLineManager
96
 	klines                       *KLineManager
96
 	limits                       Limits
97
 	limits                       Limits
97
 	listeners                    map[string]*ListenerWrapper
98
 	listeners                    map[string]*ListenerWrapper
175
 	server.configurableStateMutex.RLock()
176
 	server.configurableStateMutex.RLock()
176
 
177
 
177
 	// add RPL_ISUPPORT tokens
178
 	// add RPL_ISUPPORT tokens
178
-	isupport := NewISupportList()
179
+	isupport := isupport.NewList()
179
 	isupport.Add("AWAYLEN", strconv.Itoa(server.limits.AwayLen))
180
 	isupport.Add("AWAYLEN", strconv.Itoa(server.limits.AwayLen))
180
 	isupport.Add("CASEMAPPING", casemappingName)
181
 	isupport.Add("CASEMAPPING", casemappingName)
181
 	isupport.Add("CHANMODES", strings.Join([]string{Modes{BanMask, ExceptMask, InviteMask}.String(), "", Modes{UserLimit, Key}.String(), Modes{InviteOnly, Moderated, NoOutside, OpOnlyTopic, ChanRoleplaying, Secret}.String()}, ","))
182
 	isupport.Add("CHANMODES", strings.Join([]string{Modes{BanMask, ExceptMask, InviteMask}.String(), "", Modes{UserLimit, Key}.String(), Modes{InviteOnly, Moderated, NoOutside, OpOnlyTopic, ChanRoleplaying, Secret}.String()}, ","))

Loading…
Cancel
Save