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,7 +23,7 @@ var (
23 23
 )
24 24
 
25 25
 const (
26
-	SEM_VER       = "ergonomadic-1.2.14"
26
+	SEM_VER       = "ergonomadic-1.2.15"
27 27
 	CRLF          = "\r\n"
28 28
 	MAX_REPLY_LEN = 512 - len(CRLF)
29 29
 

+ 4
- 0
irc/reply.go View File

@@ -142,6 +142,10 @@ func RplKill(client *Client, target *Client, comment string) string {
142 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 149
 // numeric replies
146 150
 
147 151
 func (target *Client) RplWelcome() {

+ 7
- 15
irc/server.go View File

@@ -285,36 +285,28 @@ func (msg *CapCommand) HandleRegServer(server *Server) {
285 285
 	switch msg.subCommand {
286 286
 	case CAP_LS:
287 287
 		client.capState = CapNegotiating
288
-		client.Reply("CAP LS * :%s", SupportedCapabilities)
288
+		client.Reply(RplCap(client, CAP_LS, SupportedCapabilities))
289 289
 
290 290
 	case CAP_LIST:
291
-		client.Reply("CAP LIST * :%s", client.capabilities)
291
+		client.Reply(RplCap(client, CAP_LIST, client.capabilities))
292 292
 
293 293
 	case CAP_REQ:
294 294
 		client.capState = CapNegotiating
295 295
 		for capability := range msg.capabilities {
296 296
 			if !SupportedCapabilities[capability] {
297
-				client.Reply("CAP NAK * :%s", msg.capabilities)
297
+				client.Reply(RplCap(client, CAP_NAK, msg.capabilities))
298 298
 				return
299 299
 			}
300 300
 		}
301 301
 		for capability := range msg.capabilities {
302 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 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 311
 	case CAP_END:
320 312
 		client.capState = CapNegotiated

+ 14
- 0
irc/types.go View File

@@ -13,6 +13,10 @@ type CapSubCommand string
13 13
 
14 14
 type Capability string
15 15
 
16
+func (capability Capability) String() string {
17
+	return string(capability)
18
+}
19
+
16 20
 type CapModifier rune
17 21
 
18 22
 func (mod CapModifier) String() string {
@@ -33,6 +37,16 @@ func (set CapabilitySet) String() string {
33 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 50
 // add, remove, list modes
37 51
 type ModeOp rune
38 52
 

Loading…
Cancel
Save