From 16568c5ab7b6e037aca229c2409396eb1964431c Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 8 Jun 2025 16:33:39 -0400 Subject: [PATCH] fix #2270 REGISTER should strip the guest format when applicable, same as NS REGISTER. --- default.yaml | 2 +- irc/handlers.go | 17 ++++++++++++++--- traditional.yaml | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/default.yaml b/default.yaml index 000cbd89..f0342204 100644 --- a/default.yaml +++ b/default.yaml @@ -522,7 +522,7 @@ accounts: # 1. these nicknames cannot be registered or reserved # 2. if a client is automatically renamed by the server, # this is the template that will be used (e.g., Guest-nccj6rgmt97cg) - # 3. if enforce-guest-format (see below) is enabled, clients without + # 3. if force-guest-format (see below) is enabled, clients without # a registered account will have this template applied to their # nicknames (e.g., 'katie' will become 'Guest-katie') guest-nickname-format: "Guest-*" diff --git a/irc/handlers.go b/irc/handlers.go index 2b6c23c6..c606637f 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2907,11 +2907,23 @@ func quitHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respons // REGISTER < account | * > < email | * > func registerHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) (exiting bool) { - accountName := client.Nick() - if accountName == "*" { + var accountName string + if client.registered { + accountName = client.Nick() + } else { accountName = client.preregNick } + config := server.Config() + if client.registered && config.Accounts.NickReservation.ForceGuestFormat { + matches := config.Accounts.NickReservation.guestRegexp.FindStringSubmatch(accountName) + if matches == nil || len(matches) < 2 { + rb.Add(nil, server.name, "FAIL", "REGISTER", "INVALID_USERNAME", utils.SafeErrorParam(accountName), client.t("Username invalid or not given")) + return + } + accountName = matches[1] + } + switch msg.Params[0] { case "*", accountName: // ok @@ -2928,7 +2940,6 @@ func registerHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res return } - config := server.Config() if !config.Accounts.Registration.Enabled { rb.Add(nil, server.name, "FAIL", "REGISTER", "DISALLOWED", accountName, client.t("Account registration is disabled")) return diff --git a/traditional.yaml b/traditional.yaml index c4c16e0e..df6ff052 100644 --- a/traditional.yaml +++ b/traditional.yaml @@ -494,7 +494,7 @@ accounts: # 1. these nicknames cannot be registered or reserved # 2. if a client is automatically renamed by the server, # this is the template that will be used (e.g., Guest-nccj6rgmt97cg) - # 3. if enforce-guest-format (see below) is enabled, clients without + # 3. if force-guest-format (see below) is enabled, clients without # a registered account will have this template applied to their # nicknames (e.g., 'katie' will become 'Guest-katie') guest-nickname-format: "Guest-*"