From d2f5566813cad3f8e9e5d05bd1a4f768ec079050 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 14 Feb 2012 16:31:58 +0100 Subject: [PATCH] added possibility to change bot nick even if bot is on +m channels --- src/ClientSocket.h | 3 +++ src/IRCParser.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/ClientSocket.h b/src/ClientSocket.h index 34db5d6..5c707e1 100644 --- a/src/ClientSocket.h +++ b/src/ClientSocket.h @@ -30,6 +30,7 @@ #define SOCKET_FLAG_QUITTED 0x100 #define SOCKET_FLAG_FAST_JUMP 0x200 #define SOCKET_FLAG_SILENT 0x400 +#define SOCKET_FLAG_CHANGENICK 0x800 #define SOCKET_HAVE_BOTCLASSVALUE1 0x10000000 #define SOCKET_HAVE_BOTCLASSVALUE2 0x20000000 @@ -74,6 +75,8 @@ struct ClientSocket { void *botclassvalue2; void *botclassvalue3; + void *changenick_channels; //parted channels due raw 437 + struct ClientSocket *next; }; diff --git a/src/IRCParser.c b/src/IRCParser.c index 17aeef4..e92b346 100644 --- a/src/IRCParser.c +++ b/src/IRCParser.c @@ -566,11 +566,17 @@ static IRC_CMD(raw_notice) { return 1; } +static void client_renamed(struct ClientSocket *client); + static IRC_CMD(raw_nick) { if(from == NULL || argc == 0) return 0; struct UserNode *user = getUserByMask(from); if(user == NULL) return 0; - if(!is_firstBotSeeUser(client, user)) return 1; //we ignore it - but it's not a parse error + if(isBot(user)) { + if(client->user != user) return 1; + client_renamed(client); + } + else if(!is_firstBotSeeUser(client, user)) return 1; //we ignore it - but it's not a parse error event_nick(user, argv[0]); renameUser(user, argv[0]); return 1; @@ -684,8 +690,40 @@ static IRC_CMD(raw_332) { return 1; } +struct ClientRenamePartedChannel { + char channel[CHANNELLEN+1]; + struct ClientRenamePartedChannel *next; +}; + +static IRC_CMD(raw_437) { //can NOT change nick + struct ClientRenamePartedChannel *partedchan = malloc(sizeof(*partedchan)); + strcpy(partedchan->channel, argv[1]); + if((client->flags & SOCKET_FLAG_CHANGENICK)) + partedchan->next = client->changenick_channels; + else + partedchan->next = NULL; + client->changenick_channels = partedchan; + client->flags |= SOCKET_FLAG_CHANGENICK; + putsock(client, "PART %s", argv[1]); + putsock(client, "NICK %s", client->nick); + return 1; +} + +static void client_renamed(struct ClientSocket *client) { + if((client->flags & SOCKET_FLAG_CHANGENICK)) { + struct ClientRenamePartedChannel *partedchan, *nextchan; + for(partedchan = client->changenick_channels; partedchan; partedchan = nextchan) { + nextchan = partedchan->next; + putsock(client, "JOIN %s", partedchan->channel); + free(partedchan); + } + client->flags &= ~SOCKET_FLAG_CHANGENICK; + } +} + void init_parser() { //all the raws we receive... + register_irc_function("437", raw_437); register_irc_function("002", raw_002); register_irc_function("251", raw_251); register_irc_function("254", raw_254); -- 2.20.1