Daniel Oaks 7 лет назад
Родитель
Сommit
22216d4d60
7 измененных файлов: 39 добавлений и 24 удалений
  1. 5
    5
      irc/accounts.go
  2. 5
    12
      irc/capability.go
  3. 1
    0
      irc/channel.go
  4. 5
    4
      irc/client.go
  5. 21
    2
      irc/config.go
  6. 1
    0
      irc/net.go
  7. 1
    1
      irc/whowas.go

+ 5
- 5
irc/accounts.go Просмотреть файл

@@ -318,12 +318,12 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value
318 318
 }
319 319
 
320 320
 // successfulSaslAuth means that a SASL auth attempt completed successfully, and is used to dispatch messages.
321
-func (c *Client) successfulSaslAuth() {
322
-	c.Send(nil, c.server.name, RPL_LOGGEDIN, c.nick, c.nickMaskString, c.account.Name, fmt.Sprintf("You are now logged in as %s", c.account.Name))
323
-	c.Send(nil, c.server.name, RPL_SASLSUCCESS, c.nick, "SASL authentication successful")
321
+func (client *Client) successfulSaslAuth() {
322
+	client.Send(nil, client.server.name, RPL_LOGGEDIN, client.nick, client.nickMaskString, client.account.Name, fmt.Sprintf("You are now logged in as %s", client.account.Name))
323
+	client.Send(nil, client.server.name, RPL_SASLSUCCESS, client.nick, "SASL authentication successful")
324 324
 
325 325
 	// dispatch account-notify
326
-	for friend := range c.Friends(AccountNotify) {
327
-		friend.Send(nil, c.nickMaskString, "ACCOUNT", c.account.Name)
326
+	for friend := range client.Friends(AccountNotify) {
327
+		friend.Send(nil, client.nickMaskString, "ACCOUNT", client.account.Name)
328 328
 	}
329 329
 }

+ 5
- 12
irc/capability.go Просмотреть файл

@@ -66,9 +66,12 @@ func (capability Capability) String() string {
66 66
 type CapState uint
67 67
 
68 68
 const (
69
-	CapNone        CapState = iota
69
+	// CapNone means CAP hasn't been negotiated at all.
70
+	CapNone CapState = iota
71
+	// CapNegotiating means CAP is being negotiated and registration should be paused.
70 72
 	CapNegotiating CapState = iota
71
-	CapNegotiated  CapState = iota
73
+	// CapNegotiated means CAP negotiation has been successfully ended and reg should complete.
74
+	CapNegotiated CapState = iota
72 75
 )
73 76
 
74 77
 // CapVersion is used to select which max version of CAP the client supports.
@@ -101,16 +104,6 @@ func (set CapabilitySet) String(version CapVersion) string {
101 104
 	return strings.Join(strs, " ")
102 105
 }
103 106
 
104
-func (set CapabilitySet) DisableString() string {
105
-	parts := make([]string, len(set))
106
-	index := 0
107
-	for capability := range set {
108
-		parts[index] = "-" + capability.String()
109
-		index++
110
-	}
111
-	return strings.Join(parts, " ")
112
-}
113
-
114 107
 // CAP <subcmd> [<caps>]
115 108
 func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
116 109
 	subCommand := strings.ToUpper(msg.Params[0])

+ 1
- 0
irc/channel.go Просмотреть файл

@@ -17,6 +17,7 @@ import (
17 17
 	"github.com/tidwall/buntdb"
18 18
 )
19 19
 
20
+// Channel represents a channel that clients can join.
20 21
 type Channel struct {
21 22
 	flags          ModeSet
22 23
 	lists          map[Mode]*UserMaskSet

+ 5
- 4
irc/client.go Просмотреть файл

@@ -283,7 +283,7 @@ func (client *Client) HasNick() bool {
283 283
 	return client.nick != "" && client.nick != "*"
284 284
 }
285 285
 
286
-// HasNick returns true if the client's username is set (used in registration).
286
+// HasUsername returns true if the client's username is set (used in registration).
287 287
 func (client *Client) HasUsername() bool {
288 288
 	return client.username != "" && client.username != "*"
289 289
 }
@@ -303,11 +303,11 @@ func (client *Client) HasCapabs(capabs ...string) bool {
303 303
 	return true
304 304
 }
305 305
 
306
-// <mode>
307
-func (c *Client) ModeString() (str string) {
306
+// ModeString returns the mode string for this client.
307
+func (client *Client) ModeString() (str string) {
308 308
 	str = "+"
309 309
 
310
-	for flag := range c.flags {
310
+	for flag := range client.flags {
311 311
 		str += flag.String()
312 312
 	}
313 313
 
@@ -433,6 +433,7 @@ func (client *Client) ChangeNickname(nickname string) error {
433 433
 	return err
434 434
 }
435 435
 
436
+// Quit sends the given quit message to the client (but does not destroy them).
436 437
 func (client *Client) Quit(message string) {
437 438
 	if !client.quitMessageSent {
438 439
 		client.Send(nil, client.nickMaskString, "QUIT", message)

+ 21
- 2
irc/config.go Просмотреть файл

@@ -21,17 +21,18 @@ import (
21 21
 	"gopkg.in/yaml.v2"
22 22
 )
23 23
 
24
+// PassConfig holds the connection password.
24 25
 type PassConfig struct {
25 26
 	Password string
26 27
 }
27 28
 
28
-// TLSListenConfig defines configuration options for listening on TLS
29
+// TLSListenConfig defines configuration options for listening on TLS.
29 30
 type TLSListenConfig struct {
30 31
 	Cert string
31 32
 	Key  string
32 33
 }
33 34
 
34
-// Certificate returns the TLS certificate assicated with this TLSListenConfig
35
+// Config returns the TLS contiguration assicated with this TLSListenConfig.
35 36
 func (conf *TLSListenConfig) Config() (*tls.Config, error) {
36 37
 	cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
37 38
 	if err != nil {
@@ -43,6 +44,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
43 44
 	}, err
44 45
 }
45 46
 
47
+// PasswordBytes returns the bytes represented by the password hash.
46 48
 func (conf *PassConfig) PasswordBytes() []byte {
47 49
 	bytes, err := DecodePasswordHash(conf.Password)
48 50
 	if err != nil {
@@ -51,6 +53,7 @@ func (conf *PassConfig) PasswordBytes() []byte {
51 53
 	return bytes
52 54
 }
53 55
 
56
+// AccountRegistrationConfig controls account registration.
54 57
 type AccountRegistrationConfig struct {
55 58
 	Enabled          bool
56 59
 	EnabledCallbacks []string `yaml:"enabled-callbacks"`
@@ -72,10 +75,12 @@ type AccountRegistrationConfig struct {
72 75
 	}
73 76
 }
74 77
 
78
+// ChannelRegistrationConfig controls channel registration.
75 79
 type ChannelRegistrationConfig struct {
76 80
 	Enabled bool
77 81
 }
78 82
 
83
+// OperClassConfig defines a specific operator class.
79 84
 type OperClassConfig struct {
80 85
 	Title        string
81 86
 	WhoisLine    string
@@ -83,6 +88,7 @@ type OperClassConfig struct {
83 88
 	Capabilities []string
84 89
 }
85 90
 
91
+// OperConfig defines a specific operator's configuration.
86 92
 type OperConfig struct {
87 93
 	Class     string
88 94
 	Vhost     string
@@ -98,11 +104,13 @@ func (conf *OperConfig) PasswordBytes() []byte {
98 104
 	return bytes
99 105
 }
100 106
 
107
+// RestAPIConfig controls the integrated REST API.
101 108
 type RestAPIConfig struct {
102 109
 	Enabled bool
103 110
 	Listen  string
104 111
 }
105 112
 
113
+// ConnectionLimitsConfig controls the automated connection limits.
106 114
 type ConnectionLimitsConfig struct {
107 115
 	Enabled     bool
108 116
 	CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
@@ -111,6 +119,7 @@ type ConnectionLimitsConfig struct {
111 119
 	Exempted    []string
112 120
 }
113 121
 
122
+// ConnectionThrottleConfig controls the automated connection throttling.
114 123
 type ConnectionThrottleConfig struct {
115 124
 	Enabled            bool
116 125
 	CidrLenIPv4        int           `yaml:"cidr-len-ipv4"`
@@ -124,6 +133,7 @@ type ConnectionThrottleConfig struct {
124 133
 	Exempted           []string
125 134
 }
126 135
 
136
+// LoggingConfig controls a single logging method.
127 137
 type LoggingConfig struct {
128 138
 	Method        string
129 139
 	MethodStderr  bool
@@ -136,11 +146,13 @@ type LoggingConfig struct {
136 146
 	Level         logger.Level `yaml:"level-real"`
137 147
 }
138 148
 
149
+// LineLenConfig controls line lengths.
139 150
 type LineLenConfig struct {
140 151
 	Tags int
141 152
 	Rest int
142 153
 }
143 154
 
155
+// STSConfig controls the STS configuration/
144 156
 type STSConfig struct {
145 157
 	Enabled        bool
146 158
 	Duration       time.Duration `yaml:"duration-real"`
@@ -161,6 +173,7 @@ func (sts *STSConfig) Value() string {
161 173
 	return val
162 174
 }
163 175
 
176
+// Config defines the overall configuration.
164 177
 type Config struct {
165 178
 	Network struct {
166 179
 		Name string
@@ -215,12 +228,14 @@ type Config struct {
215 228
 	}
216 229
 }
217 230
 
231
+// OperClass defines an assembled operator class.
218 232
 type OperClass struct {
219 233
 	Title        string
220 234
 	WhoisLine    string          `yaml:"whois-line"`
221 235
 	Capabilities map[string]bool // map to make lookups much easier
222 236
 }
223 237
 
238
+// OperatorClasses returns a map of assembled operator classes from the given config.
224 239
 func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
225 240
 	ocs := make(map[string]OperClass)
226 241
 
@@ -290,6 +305,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
290 305
 	return &ocs, nil
291 306
 }
292 307
 
308
+// Oper represents a single assembled operator's config.
293 309
 type Oper struct {
294 310
 	Class     *OperClass
295 311
 	WhoisLine string
@@ -297,6 +313,7 @@ type Oper struct {
297 313
 	Pass      []byte
298 314
 }
299 315
 
316
+// Operators returns a map of operator configs from the given OperClass and config.
300 317
 func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) {
301 318
 	operators := make(map[string]Oper)
302 319
 	for name, opConf := range conf.Opers {
@@ -327,6 +344,7 @@ func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error)
327 344
 	return operators, nil
328 345
 }
329 346
 
347
+// TLSListeners returns a list of TLS listeners and their configs.
330 348
 func (conf *Config) TLSListeners() map[string]*tls.Config {
331 349
 	tlsListeners := make(map[string]*tls.Config)
332 350
 	for s, tlsListenersConf := range conf.Server.TLSListeners {
@@ -344,6 +362,7 @@ func (conf *Config) TLSListeners() map[string]*tls.Config {
344 362
 	return tlsListeners
345 363
 }
346 364
 
365
+// LoadConfig loads the given YAML configuration file.
347 366
 func LoadConfig(filename string) (config *Config, err error) {
348 367
 	data, err := ioutil.ReadFile(filename)
349 368
 	if err != nil {

+ 1
- 0
irc/net.go Просмотреть файл

@@ -9,6 +9,7 @@ import (
9 9
 	"strings"
10 10
 )
11 11
 
12
+// IPString returns a simple IP string from the given net.Addr.
12 13
 func IPString(addr net.Addr) string {
13 14
 	addrStr := addr.String()
14 15
 	ipaddr, _, err := net.SplitHostPort(addrStr)

+ 1
- 1
irc/whowas.go Просмотреть файл

@@ -59,7 +59,7 @@ func (list *WhoWasList) Find(nickname string, limit int64) []*WhoWas {
59 59
 }
60 60
 
61 61
 func (list *WhoWasList) prev(index int) int {
62
-	index -= 1
62
+	index--
63 63
 	if index < 0 {
64 64
 		index += len(list.buffer)
65 65
 	}

Загрузка…
Отмена
Сохранить