From d45311f417e3108b572425413b1da523c3817209 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 1 Jul 2012 15:35:22 +0200 Subject: [PATCH] added recover function to NeonBackup (used to recover Bot privileges when NeonBackup connects after the other ones) --- src/ClientSocket.h | 1 + src/modules/NeonBackup.mod/bot_NeonBackup.c | 20 ++++++++++++++++++-- src/modules/NeonFun.mod/bot_NeonFun.c | 2 +- src/modules/NeonHelp.mod/bot_NeonHelp.c | 2 +- src/modules/NeonServ.mod/bot_NeonServ.c | 2 +- src/modules/NeonSpam.mod/bot_NeonSpam.c | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ClientSocket.h b/src/ClientSocket.h index 9261be3..a1f87da 100644 --- a/src/ClientSocket.h +++ b/src/ClientSocket.h @@ -32,6 +32,7 @@ #define SOCKET_FLAG_SILENT 0x400 #define SOCKET_FLAG_CHANGENICK 0x800 #define SOCKET_FLAG_REQUEST_INVITE 0x1000 +#define SOCKET_FLAG_REQUEST_OP 0x2000 #define SOCKET_HAVE_BOTCLASSVALUE1 0x10000000 #define SOCKET_HAVE_BOTCLASSVALUE2 0x20000000 diff --git a/src/modules/NeonBackup.mod/bot_NeonBackup.c b/src/modules/NeonBackup.mod/bot_NeonBackup.c index 9738afb..19cffbd 100644 --- a/src/modules/NeonBackup.mod/bot_NeonBackup.c +++ b/src/modules/NeonBackup.mod/bot_NeonBackup.c @@ -96,7 +96,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0); client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); - client->flags |= SOCKET_FLAG_REQUEST_INVITE; + client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP; client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); @@ -124,7 +124,23 @@ static void start_bots(int type) { } void neonbackup_recover_chan(struct ChanNode *chan) { - + struct ClientSocket *bot = getChannelBot(chan, BOTID); // prefer backup bot ;) + struct ChanUser *chanuser = (bot ? getChanUser(bot->user, chan) : NULL); + if(!chanuser || !(chanuser->flags & CHANUSERFLAG_OPPED)) { + //search an opped bot + for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { + if((chanuser = getChanUser(bot->user, chan)) && (chanuser->flags & CHANUSERFLAG_OPPED)) + break; + } + } + if(!bot) //no opped bots present... channel can't be recovered + return; + struct ClientSocket *target; + for(target = getBots(SOCKET_FLAG_READY, NULL); target; target = getBots(SOCKET_FLAG_READY, target)) { + if((target->flags & SOCKET_FLAG_REQUEST_OP) && (chanuser = getChanUser(target->user, chan)) && !(chanuser->flags & CHANUSERFLAG_OPPED)) { + putsock(bot, "MODE %s +o %s", chan->name, target->user->nick); + } + } } static void neonbackup_event_join(struct ChanUser *chanuser) { diff --git a/src/modules/NeonFun.mod/bot_NeonFun.c b/src/modules/NeonFun.mod/bot_NeonFun.c index 75afbba..3679234 100644 --- a/src/modules/NeonFun.mod/bot_NeonFun.c +++ b/src/modules/NeonFun.mod/bot_NeonFun.c @@ -101,7 +101,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); client->flags |= SOCKET_FLAG_SILENT; - client->flags |= SOCKET_FLAG_REQUEST_INVITE; + client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP; client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); diff --git a/src/modules/NeonHelp.mod/bot_NeonHelp.c b/src/modules/NeonHelp.mod/bot_NeonHelp.c index 07b6a97..ac36300 100644 --- a/src/modules/NeonHelp.mod/bot_NeonHelp.c +++ b/src/modules/NeonHelp.mod/bot_NeonHelp.c @@ -127,7 +127,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); client->flags |= SOCKET_FLAG_SILENT; - client->flags |= SOCKET_FLAG_REQUEST_INVITE; + client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP; client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); diff --git a/src/modules/NeonServ.mod/bot_NeonServ.c b/src/modules/NeonServ.mod/bot_NeonServ.c index 4d377e4..89f298b 100644 --- a/src/modules/NeonServ.mod/bot_NeonServ.c +++ b/src/modules/NeonServ.mod/bot_NeonServ.c @@ -473,7 +473,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0); client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); - client->flags |= SOCKET_FLAG_REQUEST_INVITE; + client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP; client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); diff --git a/src/modules/NeonSpam.mod/bot_NeonSpam.c b/src/modules/NeonSpam.mod/bot_NeonSpam.c index 16e0016..b568fac 100644 --- a/src/modules/NeonSpam.mod/bot_NeonSpam.c +++ b/src/modules/NeonSpam.mod/bot_NeonSpam.c @@ -160,7 +160,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0); client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); - client->flags |= SOCKET_FLAG_REQUEST_INVITE; + client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP; client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); -- 2.20.1