Browse Source

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.
tags/v2.3.0-rc1
Hubert Hirtz 3 years ago
parent
commit
f6d5fe812f
4 changed files with 20 additions and 11 deletions
  1. 8
    0
      irc/channelmanager.go
  2. 5
    3
      irc/getters.go
  3. 7
    6
      irc/handlers.go
  4. 0
    2
      irc/numerics.go

+ 8
- 0
irc/channelmanager.go View File

@@ -287,6 +287,14 @@ func (cm *ChannelManager) Rename(name string, newName string) (err error) {
287 287
 	cm.Lock()
288 288
 	defer cm.Unlock()
289 289
 
290
+	if newCfname == cfname {
291
+		entry := cm.chans[cfname]
292
+		if entry == nil || !entry.channel.IsLoaded() {
293
+			return errNoSuchChannel
294
+		}
295
+		entry.channel.Rename(newName, cfname)
296
+		return nil
297
+	}
290 298
 	if cm.chans[newCfname] != nil || cm.registeredChannels.Has(newCfname) {
291 299
 		return errChannelNameInUse
292 300
 	}

+ 5
- 3
irc/getters.go View File

@@ -453,9 +453,11 @@ func (channel *Channel) NameCasefolded() string {
453 453
 func (channel *Channel) Rename(name, nameCasefolded string) {
454 454
 	channel.stateMutex.Lock()
455 455
 	channel.name = name
456
-	channel.nameCasefolded = nameCasefolded
457
-	if channel.registeredFounder != "" {
458
-		channel.registeredTime = time.Now().UTC()
456
+	if channel.nameCasefolded != nameCasefolded {
457
+		channel.nameCasefolded = nameCasefolded
458
+		if channel.registeredFounder != "" {
459
+			channel.registeredTime = time.Now().UTC()
460
+		}
459 461
 	}
460 462
 	channel.stateMutex.Unlock()
461 463
 }

+ 7
- 6
irc/handlers.go View File

@@ -2421,8 +2421,7 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2421 2421
 }
2422 2422
 
2423 2423
 // RENAME <oldchan> <newchan> [<reason>]
2424
-func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
2425
-	result = false
2424
+func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2426 2425
 	oldName, newName := msg.Params[0], msg.Params[1]
2427 2426
 	var reason string
2428 2427
 	if 2 < len(msg.Params) {
@@ -2434,6 +2433,8 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2434 2433
 		rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(oldName), client.t("No such channel"))
2435 2434
 		return false
2436 2435
 	}
2436
+	oldName = channel.Name()
2437
+
2437 2438
 	if !(channel.ClientIsAtLeast(client, modes.ChannelOperator) || client.HasRoleCapabs("chanreg")) {
2438 2439
 		rb.Add(nil, server.name, ERR_CHANOPRIVSNEEDED, client.Nick(), oldName, client.t("You're not a channel operator"))
2439 2440
 		return false
@@ -2441,14 +2442,14 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2441 2442
 
2442 2443
 	founder := channel.Founder()
2443 2444
 	if founder != "" && founder != client.Account() {
2444
-		rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Only channel founders can change registered channels"))
2445
+		rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Only channel founders can change registered channels"))
2445 2446
 		return false
2446 2447
 	}
2447 2448
 
2448 2449
 	config := server.Config()
2449 2450
 	status, _ := channel.historyStatus(config)
2450 2451
 	if status == HistoryPersistent {
2451
-		rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, newName, client.t("Channels with persistent history cannot be renamed"))
2452
+		rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Channels with persistent history cannot be renamed"))
2452 2453
 		return false
2453 2454
 	}
2454 2455
 
@@ -2457,9 +2458,9 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2457 2458
 	if err == errInvalidChannelName {
2458 2459
 		rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error()))
2459 2460
 	} else if err == errChannelNameInUse {
2460
-		rb.Add(nil, server.name, ERR_CHANNAMEINUSE, client.Nick(), utils.SafeErrorParam(newName), client.t(err.Error()))
2461
+		rb.Add(nil, server.name, "FAIL", "RENAME", "CHANNEL_NAME_IN_USE", oldName, utils.SafeErrorParam(newName), client.t(err.Error()))
2461 2462
 	} else if err != nil {
2462
-		rb.Add(nil, server.name, ERR_CANNOTRENAME, client.Nick(), oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel"))
2463
+		rb.Add(nil, server.name, "FAIL", "RENAME", "CANNOT_RENAME", oldName, utils.SafeErrorParam(newName), client.t("Cannot rename channel"))
2463 2464
 	}
2464 2465
 	if err != nil {
2465 2466
 		return false

+ 0
- 2
irc/numerics.go View File

@@ -168,8 +168,6 @@ const (
168 168
 	ERR_CANNOTSENDRP              = "573"
169 169
 	RPL_WHOISSECURE               = "671"
170 170
 	RPL_YOURLANGUAGESARE          = "687"
171
-	ERR_CHANNAMEINUSE             = "692"
172
-	ERR_CANNOTRENAME              = "693"
173 171
 	ERR_INVALIDMODEPARAM          = "696"
174 172
 	ERR_LISTMODEALREADYSET        = "697"
175 173
 	ERR_LISTMODENOTSET            = "698"

Loading…
Cancel
Save