3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-03 16:42:38 +01:00

Update draft/rename implementation

Link to the new draft PR:
<https://github.com/ircv3/ircv3-specifications/pull/420>

Changes in the spec:

- Use standard replies instead of numerics:
  <https://github.com/ircv3/ircv3-specifications/pull/420/files#diff-70e90beef48dc9cf5d784d1e179ea822R44>
- Allow RENAME to a different case:
  <https://github.com/ircv3/ircv3-specifications/pull/420/files#diff-70e90beef48dc9cf5d784d1e179ea822R42>

This commit makes oragono send the PART-JOIN fallback even on case-only
changes. This is so that clients don't have to worry about oragono's
UTF8 casefolding. See the following comments for further info:
<https://github.com/ircv3/ircv3-specifications/pull/420#issuecomment-668770837>

Misc fixes:

- Remove unused variable,
- Add missing calls to utils.SafeErrorParam,
- Don't fill replies with the user-provided "oldName", for the same
  reason as sending the PART-JOIN fallback.
This commit is contained in:
Hubert Hirtz 2020-08-04 16:13:29 +02:00
parent daefa40b75
commit f6d5fe812f
4 changed files with 20 additions and 11 deletions

View File

@ -287,6 +287,14 @@ func (cm *ChannelManager) Rename(name string, newName string) (err error) {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
if newCfname == cfname {
entry := cm.chans[cfname]
if entry == nil || !entry.channel.IsLoaded() {
return errNoSuchChannel
}
entry.channel.Rename(newName, cfname)
return nil
}
if cm.chans[newCfname] != nil || cm.registeredChannels.Has(newCfname) { if cm.chans[newCfname] != nil || cm.registeredChannels.Has(newCfname) {
return errChannelNameInUse return errChannelNameInUse
} }

View File

@ -453,10 +453,12 @@ func (channel *Channel) NameCasefolded() string {
func (channel *Channel) Rename(name, nameCasefolded string) { func (channel *Channel) Rename(name, nameCasefolded string) {
channel.stateMutex.Lock() channel.stateMutex.Lock()
channel.name = name channel.name = name
if channel.nameCasefolded != nameCasefolded {
channel.nameCasefolded = nameCasefolded channel.nameCasefolded = nameCasefolded
if channel.registeredFounder != "" { if channel.registeredFounder != "" {
channel.registeredTime = time.Now().UTC() channel.registeredTime = time.Now().UTC()
} }
}
channel.stateMutex.Unlock() channel.stateMutex.Unlock()
} }

View File

@ -2421,8 +2421,7 @@ 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) bool {
result = false
oldName, newName := msg.Params[0], msg.Params[1] oldName, newName := msg.Params[0], msg.Params[1]
var reason string var reason string
if 2 < len(msg.Params) { if 2 < len(msg.Params) {
@ -2434,6 +2433,8 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(oldName), client.t("No such channel")) rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(oldName), client.t("No such channel"))
return false return false
} }
oldName = channel.Name()
if !(channel.ClientIsAtLeast(client, modes.ChannelOperator) || client.HasRoleCapabs("chanreg")) { if !(channel.ClientIsAtLeast(client, modes.ChannelOperator) || client.HasRoleCapabs("chanreg")) {
rb.Add(nil, server.name, ERR_CHANOPRIVSNEEDED, client.Nick(), oldName, client.t("You're not a channel operator")) rb.Add(nil, server.name, ERR_CHANOPRIVSNEEDED, client.Nick(), oldName, client.t("You're not a channel operator"))
return false return false
@ -2441,14 +2442,14 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
founder := channel.Founder() founder := channel.Founder()
if founder != "" && founder != client.Account() { if founder != "" && founder != client.Account() {
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, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Only channel founders can change registered channels"))
return false return false
} }
config := server.Config() config := server.Config()
status, _ := channel.historyStatus(config) status, _ := channel.historyStatus(config)
if status == HistoryPersistent { if status == HistoryPersistent {
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Channels with persistent history cannot be renamed")) rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Channels with persistent history cannot be renamed"))
return false return false
} }
@ -2457,9 +2458,9 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
if err == errInvalidChannelName { if err == errInvalidChannelName {
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error())) rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error()))
} else if err == errChannelNameInUse { } else if err == errChannelNameInUse {
rb.Add(nil, server.name, ERR_CHANNAMEINUSE, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error())) rb.Add(nil, server.name, "FAIL", "RENAME", "CHANNEL_NAME_IN_USE", oldName, utils.SafeErrorParam(newName), client.t(err.Error()))
} else if err != nil { } else if err != nil {
rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel")) rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel"))
} }
if err != nil { if err != nil {
return false return false

View File

@ -168,8 +168,6 @@ const (
ERR_CANNOTSENDRP = "573" ERR_CANNOTSENDRP = "573"
RPL_WHOISSECURE = "671" RPL_WHOISSECURE = "671"
RPL_YOURLANGUAGESARE = "687" RPL_YOURLANGUAGESARE = "687"
ERR_CHANNAMEINUSE = "692"
ERR_CANNOTRENAME = "693"
ERR_INVALIDMODEPARAM = "696" ERR_INVALIDMODEPARAM = "696"
ERR_LISTMODEALREADYSET = "697" ERR_LISTMODEALREADYSET = "697"
ERR_LISTMODENOTSET = "698" ERR_LISTMODENOTSET = "698"