From 369cdfc4775458e47408320cb036e1fd7a865fc0 Mon Sep 17 00:00:00 2001 From: Aritra Sarkar Date: Sun, 3 Jul 2022 09:37:35 +0530 Subject: [PATCH] Fix blank nicks appearing on everyone else's screen --- commands.c | 9 ++++++--- main.c | 2 +- message.c | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/commands.c b/commands.c index 026bdce..45a7d14 100644 --- a/commands.c +++ b/commands.c @@ -69,15 +69,18 @@ set_nick(const char *nick, char *buf, char *rem, int *len, syntax_error_t *why, return -1; } - /* Set the new nick for the client */ - strcpy(pending->new_nick, new_nick); - /* * Depending on whether current nick exists, decide if it's a join * or a nick change. */ *buf = pending->type = *nick ? RES_SETNICK : RES_JOIN; + /* Set the new nick for the client */ + if ( pending->type == RES_SETNICK ) + strcpy(pending->new_nick, new_nick); + else + strcpy(pending->nick, new_nick); + /* Modify rest of `buf` for the announcement of join */ strcpy(buf + 1, new_nick); *len = strlen(new_nick) + 1; /* + 1 for the send code */ diff --git a/main.c b/main.c index d46168f..192b5b6 100644 --- a/main.c +++ b/main.c @@ -508,7 +508,7 @@ int main(int argc, char **argv) case RES_JOIN: /* Announce join */ - printf("[!] %s has joined\n", msg.new_nick); + printf("[!] %s has joined\n", msg.nick); break; case RES_SETNICK: diff --git a/message.c b/message.c index daaf258..b1fd7c5 100644 --- a/message.c +++ b/message.c @@ -131,7 +131,9 @@ parse_response(const char *buf, int len, char *nick, Message *msg, free(*pending); *pending = NULL; - if ( msg->type == RES_JOIN || msg->type == RES_SETNICK ) + if ( msg->type == RES_JOIN ) + strcpy(nick, msg->nick); + else if ( msg->type == RES_SETNICK ) strcpy(nick, msg->new_nick); } break; -- 2.45.2