mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +01:00
commit
64bf4a10c6
@ -28,15 +28,15 @@ var (
|
|||||||
errCallbackFailed = errors.New("Account verification could not be sent")
|
errCallbackFailed = errors.New("Account verification could not be sent")
|
||||||
errCertfpAlreadyExists = errors.New(`An account already exists for your certificate fingerprint`)
|
errCertfpAlreadyExists = errors.New(`An account already exists for your certificate fingerprint`)
|
||||||
errChannelAlreadyRegistered = errors.New("Channel is already registered")
|
errChannelAlreadyRegistered = errors.New("Channel is already registered")
|
||||||
errChannelNameInUse = errors.New("Channel name in use")
|
errChannelNameInUse = errors.New(`Channel name in use`)
|
||||||
errInvalidChannelName = errors.New("Invalid channel name")
|
errInvalidChannelName = errors.New(`Invalid channel name`)
|
||||||
errMonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
errMonitorLimitExceeded = errors.New("Monitor limit exceeded")
|
||||||
errNickMissing = errors.New("nick missing")
|
errNickMissing = errors.New("nick missing")
|
||||||
errNicknameInUse = errors.New("nickname in use")
|
errNicknameInUse = errors.New("nickname in use")
|
||||||
errNicknameReserved = errors.New("nickname is reserved")
|
errNicknameReserved = errors.New("nickname is reserved")
|
||||||
errNoExistingBan = errors.New("Ban does not exist")
|
errNoExistingBan = errors.New("Ban does not exist")
|
||||||
errNoSuchChannel = errors.New("No such channel")
|
errNoSuchChannel = errors.New(`No such channel`)
|
||||||
errRenamePrivsNeeded = errors.New("Only chanops can rename channels")
|
errRenamePrivsNeeded = errors.New(`Only chanops can rename channels`)
|
||||||
errInsufficientPrivs = errors.New("Insufficient privileges")
|
errInsufficientPrivs = errors.New("Insufficient privileges")
|
||||||
errSaslFail = errors.New("SASL failed")
|
errSaslFail = errors.New("SASL failed")
|
||||||
errResumeTokenAlreadySet = errors.New("Client was already assigned a resume token")
|
errResumeTokenAlreadySet = errors.New("Client was already assigned a resume token")
|
||||||
|
@ -2208,65 +2208,43 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
|
|||||||
// RENAME <oldchan> <newchan> [<reason>]
|
// RENAME <oldchan> <newchan> [<reason>]
|
||||||
func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
|
func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
|
||||||
result = false
|
result = false
|
||||||
|
oldName, newName := msg.Params[0], msg.Params[1]
|
||||||
errorResponse := func(err error, name string) {
|
if newName == "" {
|
||||||
// TODO: send correct error codes, e.g., ERR_CANNOTRENAME, ERR_CHANNAMEINUSE
|
newName = "<empty>" // intentionally invalid channel name, will error as expected
|
||||||
var code string
|
|
||||||
switch err {
|
|
||||||
case errNoSuchChannel:
|
|
||||||
code = ERR_NOSUCHCHANNEL
|
|
||||||
case errRenamePrivsNeeded:
|
|
||||||
code = ERR_CHANOPRIVSNEEDED
|
|
||||||
case errInvalidChannelName:
|
|
||||||
code = ERR_UNKNOWNERROR
|
|
||||||
case errChannelNameInUse:
|
|
||||||
code = ERR_UNKNOWNERROR
|
|
||||||
default:
|
|
||||||
code = ERR_UNKNOWNERROR
|
|
||||||
}
|
|
||||||
rb.Add(nil, server.name, code, client.Nick(), "RENAME", name, err.Error())
|
|
||||||
}
|
}
|
||||||
|
var reason string
|
||||||
oldName := strings.TrimSpace(msg.Params[0])
|
|
||||||
newName := strings.TrimSpace(msg.Params[1])
|
|
||||||
if oldName == "" || newName == "" {
|
|
||||||
errorResponse(errInvalidChannelName, "<empty>")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
casefoldedOldName, err := CasefoldChannel(oldName)
|
|
||||||
if err != nil {
|
|
||||||
errorResponse(errInvalidChannelName, oldName)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
reason := "No reason"
|
|
||||||
if 2 < len(msg.Params) {
|
if 2 < len(msg.Params) {
|
||||||
reason = msg.Params[2]
|
reason = msg.Params[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := server.channels.Get(oldName)
|
channel := server.channels.Get(oldName)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
errorResponse(errNoSuchChannel, oldName)
|
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), oldName, client.t("No such channel"))
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
//TODO(dan): allow IRCops to do this?
|
casefoldedOldName := channel.NameCasefolded()
|
||||||
if !channel.ClientIsAtLeast(client, modes.Operator) {
|
if !(channel.ClientIsAtLeast(client, modes.Operator) || client.HasRoleCapabs("chanreg")) {
|
||||||
errorResponse(errRenamePrivsNeeded, oldName)
|
rb.Add(nil, server.name, ERR_CHANOPRIVSNEEDED, client.Nick(), oldName, client.t("You're not a channel operator"))
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
founder := channel.Founder()
|
founder := channel.Founder()
|
||||||
if founder != "" && founder != client.Account() {
|
if founder != "" && founder != client.Account() {
|
||||||
//TODO(dan): Change this to ERR_CANNOTRENAME
|
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Only channel founders can change registered channels"))
|
||||||
rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.nick, "RENAME", oldName, client.t("Only channel founders can change registered channels"))
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform the channel rename
|
// perform the channel rename
|
||||||
err = server.channels.Rename(oldName, newName)
|
err := server.channels.Rename(oldName, newName)
|
||||||
|
if err == errInvalidChannelName {
|
||||||
|
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), newName, client.t(err.Error()))
|
||||||
|
} else if err == errChannelNameInUse {
|
||||||
|
rb.Add(nil, server.name, ERR_CHANNAMEINUSE, client.Nick(), newName, client.t(err.Error()))
|
||||||
|
} else if err != nil {
|
||||||
|
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Cannot rename channel"))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResponse(err, newName)
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rename succeeded, persist it
|
// rename succeeded, persist it
|
||||||
@ -2274,15 +2252,33 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
|
|||||||
|
|
||||||
// send RENAME messages
|
// send RENAME messages
|
||||||
for _, mcl := range channel.Members() {
|
for _, mcl := range channel.Members() {
|
||||||
|
targetRb := rb
|
||||||
|
if mcl != client {
|
||||||
|
targetRb = NewResponseBuffer(mcl)
|
||||||
|
}
|
||||||
|
prefix := mcl.NickMaskString()
|
||||||
if mcl.capabilities.Has(caps.Rename) {
|
if mcl.capabilities.Has(caps.Rename) {
|
||||||
mcl.Send(nil, client.nickMaskString, "RENAME", oldName, newName, reason)
|
if reason != "" {
|
||||||
} else {
|
targetRb.Add(nil, prefix, "RENAME", oldName, newName, reason)
|
||||||
mcl.Send(nil, mcl.nickMaskString, "PART", oldName, fmt.Sprintf(mcl.t("Channel renamed: %s"), reason))
|
|
||||||
if mcl.capabilities.Has(caps.ExtendedJoin) {
|
|
||||||
mcl.Send(nil, mcl.nickMaskString, "JOIN", newName, mcl.AccountName(), mcl.realname)
|
|
||||||
} else {
|
} else {
|
||||||
mcl.Send(nil, mcl.nickMaskString, "JOIN", newName)
|
targetRb.Add(nil, prefix, "RENAME", oldName, newName)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if reason != "" {
|
||||||
|
targetRb.Add(nil, prefix, "PART", oldName, fmt.Sprintf(mcl.t("Channel renamed: %s"), reason))
|
||||||
|
} else {
|
||||||
|
targetRb.Add(nil, prefix, "PART", oldName, fmt.Sprintf(mcl.t("Channel renamed")))
|
||||||
|
}
|
||||||
|
if mcl.capabilities.Has(caps.ExtendedJoin) {
|
||||||
|
targetRb.Add(nil, prefix, "JOIN", newName, mcl.AccountName(), mcl.Realname())
|
||||||
|
} else {
|
||||||
|
targetRb.Add(nil, prefix, "JOIN", newName)
|
||||||
|
}
|
||||||
|
channel.SendTopic(mcl, targetRb, false)
|
||||||
|
channel.Names(mcl, targetRb)
|
||||||
|
}
|
||||||
|
if mcl != client {
|
||||||
|
targetRb.Send(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,8 @@ const (
|
|||||||
RPL_WHOISSECURE = "671"
|
RPL_WHOISSECURE = "671"
|
||||||
RPL_YOURLANGUAGESARE = "687"
|
RPL_YOURLANGUAGESARE = "687"
|
||||||
RPL_WHOISLANGUAGE = "690"
|
RPL_WHOISLANGUAGE = "690"
|
||||||
|
ERR_CHANNAMEINUSE = "692"
|
||||||
|
ERR_CANNOTRENAME = "693"
|
||||||
RPL_HELPSTART = "704"
|
RPL_HELPSTART = "704"
|
||||||
RPL_HELPTXT = "705"
|
RPL_HELPTXT = "705"
|
||||||
RPL_ENDOFHELP = "706"
|
RPL_ENDOFHELP = "706"
|
||||||
|
Loading…
Reference in New Issue
Block a user