X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmodules%2Fglobal.mod%2Fcmd_global_unregister.c;h=df7b1b5ad4179fd496f1bc5c3ee72b42125a94ad;hb=fc61be208ca6dbf2fd915591c8dc7e5ef5779891;hp=e5525faca946391d0416bd6d52875f5a84eb6704;hpb=689da1db7e2517c187ce76c6c553e20d630a7f36;p=NeonServV5.git diff --git a/src/modules/global.mod/cmd_global_unregister.c b/src/modules/global.mod/cmd_global_unregister.c index e5525fa..df7b1b5 100644 --- a/src/modules/global.mod/cmd_global_unregister.c +++ b/src/modules/global.mod/cmd_global_unregister.c @@ -1,4 +1,4 @@ -/* cmd_global_unregister.c - NeonServ v5.4 +/* cmd_global_unregister.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -16,6 +16,7 @@ */ #include "cmd_global.h" +#include "../botid.h" /* * argv[0] - channel @@ -29,25 +30,30 @@ CMD_BIND(global_cmd_unregister) { else channel = (chan ? chan->name : ""); if(!is_valid_chan(channel)) { - reply(getTextBot(), user, "NS_INVALID_CHANNEL_NAME", argv[0]); + reply(textclient, user, "NS_INVALID_CHANNEL_NAME", channel); return; } int chanid; - printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel)); + printf_mysql_query("SELECT `channel_id`, `channel_nodelete` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel)); res = mysql_use(); if ((row = mysql_fetch_row(res)) != NULL) { chanid = atoi(row[0]); } else { - reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick); + reply(textclient, user, "NS_UNREGISTER_NOT_REGISTERED", channel, client->user->nick); + return; + } + if(client->botid == NEONSERV_BOTID && !strcmp(row[1], "1")) { + reply(textclient, user, "NS_UNREGISTER_NODELETE", channel); return; } + int sync_neonspam_unreg = get_int_field("General.sync_neonspam_unreg"); if(client->botid == 0) printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '0' AND `botid` = '%d'", chanid, client->clientid); else printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chanid, client->botid); res = mysql_use(); if ((row = mysql_fetch_row(res)) == NULL) { - reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick); + reply(textclient, user, "NS_UNREGISTER_NOT_REGISTERED", channel, client->user->nick); return; } int botid = atoi(row[0]); @@ -57,9 +63,56 @@ CMD_BIND(global_cmd_unregister) { break; } printf_mysql_query("DELETE FROM `bot_channels` WHERE `id` = '%s'", row[1]); - reply(getTextBot(), user, "NS_UNREGISTER_DONE", channel); + reply(textclient, user, "NS_UNREGISTER_DONE", channel); if(bot && strcmp(row[2], "1")) { putsock(bot, "PART %s :Channel unregistered.", channel); } + if(client->botid == NEONSERV_BOTID && sync_neonspam_unreg) { + printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), NEONSPAM_BOTID); + res = mysql_use(); + if ((row = mysql_fetch_row(res))) { + botid = atoi(row[0]); + for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { + if(bot->clientid == botid) + break; + } + printf_mysql_query("DELETE FROM `bot_channels` WHERE `id` = '%s'", row[1]); + if(bot && strcmp(row[2], "1")) + putsock(bot, "PART %s :Channel unregistered.", channel); + } + } + // NeonBackup SubBlock + if(client->botid == NEONSERV_BOTID) { + char setting[128]; + sprintf(setting, "modules.%s.auto_backup_unregister", get_module_name(module_id)); + if(get_int_field(setting)) + module_global_cmd_unregister_neonbackup(channel); + } logEvent(event); } + +void global_cmd_unregister_neonbackup(char *channel) { + MYSQL_RES *res; + MYSQL_ROW row; + int chanid; + printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel)); + res = mysql_use(); + if ((row = mysql_fetch_row(res)) != NULL) { + chanid = atoi(row[0]); + } else + return; + printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chanid, NEONBACKUP_BOTID); + res = mysql_use(); + if ((row = mysql_fetch_row(res)) == NULL) + return; + int botid = atoi(row[0]); + struct ClientSocket *bot; + for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { + if(bot->clientid == botid) + break; + } + printf_mysql_query("DELETE FROM `bot_channels` WHERE `id` = '%s'", row[1]); + if(bot && strcmp(row[2], "1")) { + putsock(bot, "PART %s :Channel unregistered.", channel); + } +}