From e3e2059c57f051d103645c120934a05ef5e35156 Mon Sep 17 00:00:00 2001 From: dequis Date: Mon, 6 Apr 2015 09:30:30 -0300 Subject: irc: split bee_irc_chat_name_hint in a few functions Also split underscore_dedupe from nick_dedupe. --- nick.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'nick.c') diff --git a/nick.c b/nick.c index 1ace448a..fb84f986 100644 --- a/nick.c +++ b/nick.c @@ -213,6 +213,22 @@ char *nick_gen(bee_user_t *bu) return NULL; } +/* Used for nicks and channel names too! */ +void underscore_dedupe(char nick[MAX_NICK_LENGTH + 1]) +{ + if (strlen(nick) < (MAX_NICK_LENGTH - 1)) { + nick[strlen(nick) + 1] = 0; + nick[strlen(nick)] = '_'; + } else { + /* We've got no more space for underscores, + so truncate it and replace the last three + chars with a random "_XX" suffix */ + int len = truncate_utf8(nick, MAX_NICK_LENGTH - 3); + nick[len] = '_'; + g_snprintf(nick + len + 1, 3, "%2x", rand()); + } +} + void nick_dedupe(bee_user_t *bu, char nick[MAX_NICK_LENGTH + 1]) { irc_t *irc = (irc_t *) bu->bee->ui_data; @@ -223,17 +239,8 @@ void nick_dedupe(bee_user_t *bu, char nick[MAX_NICK_LENGTH + 1]) subtle changes to make it unique. */ while (!nick_ok(irc, nick) || ((iu = irc_user_by_name(irc, nick)) && iu->bu != bu)) { - if (strlen(nick) < (MAX_NICK_LENGTH - 1)) { - nick[strlen(nick) + 1] = 0; - nick[strlen(nick)] = '_'; - } else { - /* We've got no more space for underscores, - so truncate it and replace the last three - chars with a random "_XX" suffix */ - int len = truncate_utf8(nick, MAX_NICK_LENGTH - 3); - nick[len] = '_'; - g_snprintf(nick + len + 1, 3, "%2x", rand()); - } + + underscore_dedupe(nick); if (inf_protection-- == 0) { g_snprintf(nick, MAX_NICK_LENGTH + 1, "xx%x", rand()); -- cgit v1.2.3