Pārlūkot izejas kodu

Split isupport to its' own subpackage

tags/v0.9.2-beta
Daniel Oaks 6 gadus atpakaļ
vecāks
revīzija
4aa52956e5
5 mainītis faili ar 35 papildinājumiem un 29 dzēšanām
  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 Parādīt failu

@@ -494,6 +494,14 @@ func (client *Client) LoggedIntoAccount() bool {
494 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 505
 // Quit sends the given quit message to the client (but does not destroy them).
498 506
 func (client *Client) Quit(message string) {
499 507
 	client.quitMutex.Lock()

+ 3
- 1
irc/getters.go Parādīt failu

@@ -3,7 +3,9 @@
3 3
 
4 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 9
 	server.configurableStateMutex.RLock()
8 10
 	defer server.configurableStateMutex.RUnlock()
9 11
 	return server.isupport

irc/isupport.go → irc/isupport/list.go Parādīt failu

@@ -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
-}

irc/isupport_test.go → irc/isupport/list_test.go Parādīt failu

@@ -1,7 +1,7 @@
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 (
7 7
 	"reflect"
@@ -10,7 +10,7 @@ import (
10 10
 
11 11
 func TestISUPPORT(t *testing.T) {
12 12
 	// create first list
13
-	tList1 := NewISupportList()
13
+	tList1 := NewList()
14 14
 	tList1.Add("SASL", "yes")
15 15
 	tList1.Add("CASEMAPPING", "rfc1459-strict")
16 16
 	tList1.Add("INVEX", "i")
@@ -24,7 +24,7 @@ func TestISUPPORT(t *testing.T) {
24 24
 	}
25 25
 
26 26
 	// create second list
27
-	tList2 := NewISupportList()
27
+	tList2 := NewList()
28 28
 	tList2.Add("SASL", "yes")
29 29
 	tList2.Add("CASEMAPPING", "ascii")
30 30
 	tList2.AddNoValue("INVEX")

+ 3
- 2
irc/server.go Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt