From: Egor Date: Tue, 21 Jan 2025 03:05:04 +0000 (+0200) Subject: irc.c: factor out nuh update X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=1d21154aad603c3cdc1b39f4d1fbff8aa55678fd;p=patchyircd.git irc.c: factor out nuh update --- diff --git a/src/irc.c b/src/irc.c index 0dbe4ad..9d6d7b0 100644 --- 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)) {