hirc

IRC client
Log | Files | Refs

commit d2542852950a5f7b7381964db2383d13ecea243a
parent de9445f36155d4c5a2a51f679ae32a5a8a153d24
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 20 Nov 2021 20:53:17 +0000

nick.c hirc.h: handle self in nick_getcolour

Diffstat:
Mhirc.h | 1+
Mnick.c | 14+++++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/hirc.h b/hirc.h @@ -41,6 +41,7 @@ int chan_selected(struct Channel *channel); /* nick.c */ void prefix_tokenize(char *prefix, char **nick, char **ident, char **host); +short nick_getcolour(struct Nick *nick); void nick_free(struct Nick *nick); void nick_free_list(struct Nick **head); struct Nick * nick_create(char *prefix, char priv, struct Server *server); diff --git a/nick.c b/nick.c @@ -13,10 +13,14 @@ #define MINA(array) MIN(array[0], array[1]) short -nick_getcolour(char *nick) { +nick_getcolour(struct Nick *nick) { unsigned short ret, sum; int i; long range[2]; + char *s = nick->nick; + + if (nick->self) + return config_getl("nickcolour.self"); config_getr("nickcolour.range", &range[0], &range[1]); @@ -27,17 +31,17 @@ nick_getcolour(char *nick) { if (range[0] == range[1]) return range[0]; - for (sum=i=0; nick && *nick; nick++, i++) { + for (sum=i=0; s && *s; s++, i++) { /* don't count certain trailing characters. The following: * hhvn * hhvn_ * hhvn2 * should all produce the same colour. */ - if ((*nick == '_' || isdigit(*nick)) && *(nick + 1) == '\0') + if ((*s == '_' || isdigit(*s)) && *(s + 1) == '\0') break; - sum += *nick * (i + 1); - sum ^= *nick; + sum += *s * (i + 1); + sum ^= *s; } return (sum % (MAXA(range) - MINA(range)) + MINA(range) - 1);