M commands.c => commands.c +6 -3
@@ 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 */
M main.c => main.c +1 -1
@@ 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:
M message.c => message.c +3 -1
@@ 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;