]> PatchyGit - patchyircd.git/commitdiff
irc.c: factor out nuh update
authorEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 03:05:04 +0000 (05:05 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 21 Jan 2025 03:05:04 +0000 (05:05 +0200)
src/irc.c

index 0dbe4ad..9d6d7b0 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -1304,6 +1304,17 @@ void sendMOTD(struct client_data *client) {
        }
 }
 
+static void updateNuh(struct client_data *client) {
+       char *n = client->nick ? client->nick : "*";
+       char *u = client->username ? client->username : "*";
+       char *h = client->hostname;
+       free(client->nuh);
+       client->nuh = malloc(strlen(n) + strlen(u) + strlen(h) + 3);
+       if (!client->nuh)
+               abort();
+       sprintf(client->nuh, "%s!%s@%s", n, u, h);
+       stringlower(client->nuh);
+}
 void setNick(struct client_data *client, char* nickname) {
        // TODO: perform basic sanitization
 
@@ -1365,11 +1376,7 @@ void setNick(struct client_data *client, char* nickname) {
        client->nick = mystrdup(nickname);
        if (!client->nick)
                abort();
-       client->nuh = malloc(strlen(client->nick) + strlen(client->username) + strlen(client->hostname) + 3);
-       if (!client->nuh)
-               abort();
-       sprintf(client->nuh, "%s!%s@%s", client->nick, client->username, client->hostname);
-       stringlower(client->nuh);
+       updateNuh(client);
        client->key = mystrdup(key);
        if (!client->key)
                abort();
@@ -1428,17 +1435,7 @@ void client_chghost(struct client_data *client, const char *newusername, const c
                        abort();
        }
        // update nuh
-       {
-               char *n = client->nick ? client->nick : "*";
-               char *u = client->username ? client->username : "*";
-               char *h = client->hostname;
-               free(client->nuh);
-               client->nuh = malloc(strlen(n) + strlen(u) + strlen(h) + 3);
-               if (!client->nuh)
-                       abort();
-               sprintf(client->nuh, "%s!%s@%s", n, u, h);
-               stringlower(client->nuh);
-       }
+       updateNuh(client);
 
        // now we have to simulate rejoins for clients without chghost support
        if (is_registered(client)) {