mirror of
				https://github.com/ergochat/ergo.git
				synced 2025-10-31 05:47:22 +01:00 
			
		
		
		
	fix CAP messages
This commit is contained in:
		
							parent
							
								
									f56db354ee
								
							
						
					
					
						commit
						33df043961
					
				| @ -23,7 +23,7 @@ var ( | ||||
| ) | ||||
| 
 | ||||
| const ( | ||||
| 	SEM_VER       = "ergonomadic-1.2.14" | ||||
| 	SEM_VER       = "ergonomadic-1.2.15" | ||||
| 	CRLF          = "\r\n" | ||||
| 	MAX_REPLY_LEN = 512 - len(CRLF) | ||||
| 
 | ||||
|  | ||||
| @ -142,6 +142,10 @@ func RplKill(client *Client, target *Client, comment string) string { | ||||
| 		"%s :%s", target.Nick(), comment) | ||||
| } | ||||
| 
 | ||||
| func RplCap(client *Client, subCommand CapSubCommand, arg interface{}) string { | ||||
| 	return NewStringReply(nil, CAP, "%s %s :%s", client.Nick(), subCommand, arg) | ||||
| } | ||||
| 
 | ||||
| // numeric replies | ||||
| 
 | ||||
| func (target *Client) RplWelcome() { | ||||
|  | ||||
| @ -270,36 +270,28 @@ func (msg *CapCommand) HandleRegServer(server *Server) { | ||||
| 	switch msg.subCommand { | ||||
| 	case CAP_LS: | ||||
| 		client.capState = CapNegotiating | ||||
| 		client.Reply("CAP LS * :%s", SupportedCapabilities) | ||||
| 		client.Reply(RplCap(client, CAP_LS, SupportedCapabilities)) | ||||
| 
 | ||||
| 	case CAP_LIST: | ||||
| 		client.Reply("CAP LIST * :%s", client.capabilities) | ||||
| 		client.Reply(RplCap(client, CAP_LIST, client.capabilities)) | ||||
| 
 | ||||
| 	case CAP_REQ: | ||||
| 		client.capState = CapNegotiating | ||||
| 		for capability := range msg.capabilities { | ||||
| 			if !SupportedCapabilities[capability] { | ||||
| 				client.Reply("CAP NAK * :%s", msg.capabilities) | ||||
| 				client.Reply(RplCap(client, CAP_NAK, msg.capabilities)) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		for capability := range msg.capabilities { | ||||
| 			client.capabilities[capability] = true | ||||
| 		} | ||||
| 		client.Reply("CAP ACK * :%s", msg.capabilities) | ||||
| 		client.Reply(RplCap(client, CAP_ACK, msg.capabilities)) | ||||
| 
 | ||||
| 	case CAP_CLEAR: | ||||
| 		format := strings.TrimRight( | ||||
| 			strings.Repeat("%s%s ", len(client.capabilities)), " ") | ||||
| 		args := make([]interface{}, len(client.capabilities)) | ||||
| 		index := 0 | ||||
| 		for capability := range client.capabilities { | ||||
| 			args[index] = Disable | ||||
| 			args[index+1] = capability | ||||
| 			index += 2 | ||||
| 			delete(client.capabilities, capability) | ||||
| 		} | ||||
| 		client.Reply("CAP ACK * :"+format, args...) | ||||
| 		reply := RplCap(client, CAP_ACK, client.capabilities.DisableString()) | ||||
| 		client.capabilities = make(CapabilitySet) | ||||
| 		client.Reply(reply) | ||||
| 
 | ||||
| 	case CAP_END: | ||||
| 		client.capState = CapNegotiated | ||||
|  | ||||
							
								
								
									
										14
									
								
								irc/types.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								irc/types.go
									
									
									
									
									
								
							| @ -14,6 +14,10 @@ type CapSubCommand string | ||||
| 
 | ||||
| type Capability string | ||||
| 
 | ||||
| func (capability Capability) String() string { | ||||
| 	return string(capability) | ||||
| } | ||||
| 
 | ||||
| type CapModifier rune | ||||
| 
 | ||||
| func (mod CapModifier) String() string { | ||||
| @ -34,6 +38,16 @@ func (set CapabilitySet) String() string { | ||||
| 	return strings.Join(strs, " ") | ||||
| } | ||||
| 
 | ||||
| func (set CapabilitySet) DisableString() string { | ||||
| 	parts := make([]string, len(set)) | ||||
| 	index := 0 | ||||
| 	for capability := range set { | ||||
| 		parts[index] = Disable.String() + capability.String() | ||||
| 		index += 1 | ||||
| 	} | ||||
| 	return strings.Join(parts, " ") | ||||
| } | ||||
| 
 | ||||
| // a string with wildcards | ||||
| type Mask string | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jeremy Latt
						Jeremy Latt