Browse Source

Merge remote-tracking branch 'origin/master' into user-mask

Conflicts:
	irc/types.go
tags/v0.1.0
Jeremy Latt 10 years ago
parent
commit
465313c9ac
4 changed files with 26 additions and 16 deletions
  1. 1
    1
      irc/constants.go
  2. 4
    0
      irc/reply.go
  3. 7
    15
      irc/server.go
  4. 14
    0
      irc/types.go

+ 1
- 1
irc/constants.go View File

23
 )
23
 )
24
 
24
 
25
 const (
25
 const (
26
-	SEM_VER       = "ergonomadic-1.2.14"
26
+	SEM_VER       = "ergonomadic-1.2.15"
27
 	CRLF          = "\r\n"
27
 	CRLF          = "\r\n"
28
 	MAX_REPLY_LEN = 512 - len(CRLF)
28
 	MAX_REPLY_LEN = 512 - len(CRLF)
29
 
29
 

+ 4
- 0
irc/reply.go View File

142
 		"%s :%s", target.Nick(), comment)
142
 		"%s :%s", target.Nick(), comment)
143
 }
143
 }
144
 
144
 
145
+func RplCap(client *Client, subCommand CapSubCommand, arg interface{}) string {
146
+	return NewStringReply(nil, CAP, "%s %s :%s", client.Nick(), subCommand, arg)
147
+}
148
+
145
 // numeric replies
149
 // numeric replies
146
 
150
 
147
 func (target *Client) RplWelcome() {
151
 func (target *Client) RplWelcome() {

+ 7
- 15
irc/server.go View File

285
 	switch msg.subCommand {
285
 	switch msg.subCommand {
286
 	case CAP_LS:
286
 	case CAP_LS:
287
 		client.capState = CapNegotiating
287
 		client.capState = CapNegotiating
288
-		client.Reply("CAP LS * :%s", SupportedCapabilities)
288
+		client.Reply(RplCap(client, CAP_LS, SupportedCapabilities))
289
 
289
 
290
 	case CAP_LIST:
290
 	case CAP_LIST:
291
-		client.Reply("CAP LIST * :%s", client.capabilities)
291
+		client.Reply(RplCap(client, CAP_LIST, client.capabilities))
292
 
292
 
293
 	case CAP_REQ:
293
 	case CAP_REQ:
294
 		client.capState = CapNegotiating
294
 		client.capState = CapNegotiating
295
 		for capability := range msg.capabilities {
295
 		for capability := range msg.capabilities {
296
 			if !SupportedCapabilities[capability] {
296
 			if !SupportedCapabilities[capability] {
297
-				client.Reply("CAP NAK * :%s", msg.capabilities)
297
+				client.Reply(RplCap(client, CAP_NAK, msg.capabilities))
298
 				return
298
 				return
299
 			}
299
 			}
300
 		}
300
 		}
301
 		for capability := range msg.capabilities {
301
 		for capability := range msg.capabilities {
302
 			client.capabilities[capability] = true
302
 			client.capabilities[capability] = true
303
 		}
303
 		}
304
-		client.Reply("CAP ACK * :%s", msg.capabilities)
304
+		client.Reply(RplCap(client, CAP_ACK, msg.capabilities))
305
 
305
 
306
 	case CAP_CLEAR:
306
 	case CAP_CLEAR:
307
-		format := strings.TrimRight(
308
-			strings.Repeat("%s%s ", len(client.capabilities)), " ")
309
-		args := make([]interface{}, len(client.capabilities))
310
-		index := 0
311
-		for capability := range client.capabilities {
312
-			args[index] = Disable
313
-			args[index+1] = capability
314
-			index += 2
315
-			delete(client.capabilities, capability)
316
-		}
317
-		client.Reply("CAP ACK * :"+format, args...)
307
+		reply := RplCap(client, CAP_ACK, client.capabilities.DisableString())
308
+		client.capabilities = make(CapabilitySet)
309
+		client.Reply(reply)
318
 
310
 
319
 	case CAP_END:
311
 	case CAP_END:
320
 		client.capState = CapNegotiated
312
 		client.capState = CapNegotiated

+ 14
- 0
irc/types.go View File

13
 
13
 
14
 type Capability string
14
 type Capability string
15
 
15
 
16
+func (capability Capability) String() string {
17
+	return string(capability)
18
+}
19
+
16
 type CapModifier rune
20
 type CapModifier rune
17
 
21
 
18
 func (mod CapModifier) String() string {
22
 func (mod CapModifier) String() string {
33
 	return strings.Join(strs, " ")
37
 	return strings.Join(strs, " ")
34
 }
38
 }
35
 
39
 
40
+func (set CapabilitySet) DisableString() string {
41
+	parts := make([]string, len(set))
42
+	index := 0
43
+	for capability := range set {
44
+		parts[index] = Disable.String() + capability.String()
45
+		index += 1
46
+	}
47
+	return strings.Join(parts, " ")
48
+}
49
+
36
 // add, remove, list modes
50
 // add, remove, list modes
37
 type ModeOp rune
51
 type ModeOp rune
38
 
52
 

Loading…
Cancel
Save