summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Golde <nion@suckless.org>2015-11-04 19:35:23 -0500
committerNico Golde <nion@suckless.org>2015-11-04 19:35:23 -0500
commit1bc3e103c0cc59b32018c3680f8c97bad4191cce (patch)
treed6c1fc2f75f80dcbe6a746d47122cfab76ff53bd
parent29ff454e808d0ccc8bc53a84d10e5b3df4e0aa5e (diff)
downloadii-1bc3e103c0cc59b32018c3680f8c97bad4191cce.zip
ii-1bc3e103c0cc59b32018c3680f8c97bad4191cce.tar.gz
ii-1bc3e103c0cc59b32018c3680f8c97bad4191cce.tar.bz2
prevent nick collisions by only setting the nick after the server accepted it and print a message about change to server log
-rw-r--r--ii.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ii.c b/ii.c
index 8f6a42f..9ea8bbc 100644
--- a/ii.c
+++ b/ii.c
@@ -38,6 +38,7 @@ static time_t last_response;
static Channel *channels = NULL;
static char *host = "irc.freenode.net";
static char nick[32]; /* might change while running */
+static char _nick[32]; /* might change while running */
static char path[_POSIX_PATH_MAX];
static char message[PIPE_BUF]; /* message buf used for communication */
@@ -261,7 +262,7 @@ static void proc_channels_input(Channel *c, char *buf) {
break;
case 'n':
if(strlen(buf)>=3){
- snprintf(nick, sizeof(nick),"%s", &buf[3]);
+ snprintf(_nick, sizeof(nick),"%s", &buf[3]);
snprintf(message, PIPE_BUF, "NICK %s\r\n", &buf[3]);
}
break;
@@ -357,7 +358,11 @@ static void proc_server_cmd(char *buf) {
snprintf(message, PIPE_BUF, "-!- %s changed mode/%s -> %s %s", argv[TOK_NICKSRV], argv[TOK_CMD + 1] ? argv[TOK_CMD + 1] : "" , argv[TOK_CMD + 2]? argv[TOK_CMD + 2] : "", argv[TOK_CMD + 3] ? argv[TOK_CMD + 3] : "");
else if(!strncmp("QUIT", argv[TOK_CMD], 5))
snprintf(message, PIPE_BUF, "-!- %s(%s) has quit \"%s\"", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- else if(!strncmp("NICK", argv[TOK_CMD], 5))
+ else if(!strncmp("NICK", argv[TOK_CMD], 5) && !strcmp(_nick, argv[TOK_TEXT])) {
+ snprintf(nick, sizeof(nick), "%s", _nick);
+ snprintf(message, PIPE_BUF, "-!- changed nick to \"%s\"", nick);
+ print_out(NULL, message);
+ } else if(!strncmp("NICK", argv[TOK_CMD], 5))
snprintf(message, PIPE_BUF, "-!- %s changed nick to %s", argv[TOK_NICKSRV], argv[TOK_TEXT]);
else if(!strncmp("TOPIC", argv[TOK_CMD], 6))
snprintf(message, PIPE_BUF, "-!- %s changed topic to \"%s\"", argv[TOK_NICKSRV], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");