hirc

IRC client
Log | Files | Refs

commit 2c6a20a3a506c96bad3fda3341ca0bd528de34f4
parent 2aa591bdb96470cc08e54bb046a7bb354d136861
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 27 Mar 2022 12:05:02 +0100

Keep server->self up to date with server's impression.

Diffstat:
Msrc/hirc.h | 2+-
Msrc/hist.c | 16++++++++++++++--
Msrc/nick.c | 15+++++++++++++--
3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/hirc.h b/src/hirc.h @@ -87,7 +87,7 @@ void nick_free_list(struct Nick **head); struct Nick * nick_create(char *prefix, char priv, struct Server *server); struct Nick * nick_get(struct Nick **head, char *nick); struct Nick * nick_add(struct Nick **head, char *prefix, char priv, struct Server *server); -struct Nick * nick_dup(struct Nick *nick, struct Server *server); +struct Nick * nick_dup(struct Nick *nick); int nick_isself(struct Nick *nick); int nick_isself_server(struct Nick *nick, struct Server *server); int nick_remove(struct Nick **head, char *nick); diff --git a/src/hist.c b/src/hist.c @@ -74,7 +74,7 @@ hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, new->origin = histinfo; if (from) { - new->from = nick_dup(from, histinfo->server); + new->from = nick_dup(from); } else if (**new->_params == ':') { np = NULL; if (histinfo->channel) { @@ -83,13 +83,25 @@ hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, } if (np) - new->from = nick_dup(np, histinfo->server); + new->from = nick_dup(np); else new->from = nick_create(*new->_params, ' ', histinfo->server); } else { new->from = NULL; } + /* Update histinfo->server->self */ + if (new->from && new->from->self && histinfo->server) { + if (new->from->ident && strcmp_n(new->from->ident, histinfo->server->self->ident) != 0) { + free(histinfo->server->self->ident); + histinfo->server->self->ident = strdup(new->from->ident); + } + if (new->from->host && strcmp_n(new->from->host, histinfo->server->self->host) != 0) { + free(histinfo->server->self->host); + histinfo->server->self->host = strdup(new->from->host); + } + } + if (**new->_params == ':') new->params++; diff --git a/src/nick.c b/src/nick.c @@ -180,8 +180,19 @@ nick_add(struct Nick **head, char *prefix, char priv, struct Server *server) { } struct Nick * -nick_dup(struct Nick *nick, struct Server *server) { - return nick_create(nick->prefix, nick->priv, server); +nick_dup(struct Nick *nick) { + struct Nick *ret; + if (!nick) + return NULL; + ret = emalloc(sizeof(struct Nick)); + ret->prev = ret->next = NULL; + ret->priv = nick->priv; + ret->prefix = nick->prefix ? strdup(nick->prefix) : NULL; + ret->nick = nick->nick ? strdup(nick->nick) : NULL; + ret->ident = nick->ident ? strdup(nick->ident) : NULL; + ret->host = nick->host ? strdup(nick->host) : NULL; + ret->self = nick->self; + return ret; } struct Nick *