mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Merge remote-tracking branch 'origin/master' into user-mask
Conflicts: irc/types.go
This commit is contained in:
commit
465313c9ac
@ -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() {
|
||||
|
@ -285,36 +285,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
@ -13,6 +13,10 @@ type CapSubCommand string
|
||||
|
||||
type Capability string
|
||||
|
||||
func (capability Capability) String() string {
|
||||
return string(capability)
|
||||
}
|
||||
|
||||
type CapModifier rune
|
||||
|
||||
func (mod CapModifier) String() string {
|
||||
@ -33,6 +37,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, " ")
|
||||
}
|
||||
|
||||
// add, remove, list modes
|
||||
type ModeOp rune
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user