From b1513885643cadcc6beec1cf47b960fa891b468b Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 24 Sep 2012 00:01:03 +0200 Subject: [PATCH] moved inviteme all to an own command called invitemeall --- Makefile.am | 1 + src/modules/NeonServ.mod/cmd_neonserv.c | 1 + src/modules/NeonServ.mod/cmd_neonserv.h | 1 + .../NeonServ.mod/cmd_neonserv_inviteme.c | 50 ++++-------------- .../NeonServ.mod/cmd_neonserv_invitemeall.c | 52 +++++++++++++++++++ 5 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c diff --git a/Makefile.am b/Makefile.am index 02a219c..df5f180 100644 --- a/Makefile.am +++ b/Makefile.am @@ -97,6 +97,7 @@ libNeonServ_la_SOURCES = src/modules/NeonServ.mod/bot_NeonServ.c \ src/modules/NeonServ.mod/cmd_neonserv_help.c \ src/modules/NeonServ.mod/cmd_neonserv_invite.c \ src/modules/NeonServ.mod/cmd_neonserv_inviteme.c \ + src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c \ src/modules/NeonServ.mod/cmd_neonserv_kick.c \ src/modules/NeonServ.mod/cmd_neonserv_kickban.c \ src/modules/NeonServ.mod/cmd_neonserv_mdeluser.c \ diff --git a/src/modules/NeonServ.mod/cmd_neonserv.c b/src/modules/NeonServ.mod/cmd_neonserv.c index 79a4119..62750a4 100644 --- a/src/modules/NeonServ.mod/cmd_neonserv.c +++ b/src/modules/NeonServ.mod/cmd_neonserv.c @@ -75,6 +75,7 @@ void register_commands() { USER_COMMAND("unbanme", neonserv_cmd_unbanme, 0, "#channel_canban", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG); USER_COMMAND("invite", neonserv_cmd_invite, 1, "#channel_canop", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG); USER_COMMAND("inviteme", neonserv_cmd_inviteme, 0, "#channel_getinvite", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG); + USER_COMMAND("invitemeall", neonserv_cmd_invitemeall,0,NULL, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG); USER_COMMAND("help", neonserv_cmd_help, 0, NULL, 0); USER_COMMAND("events", neonserv_cmd_events, 0, "1", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH); USER_COMMAND("info", neonserv_cmd_info, 0, NULL, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_NO_CROSSCHAN); diff --git a/src/modules/NeonServ.mod/cmd_neonserv.h b/src/modules/NeonServ.mod/cmd_neonserv.h index 097a1f2..da09147 100644 --- a/src/modules/NeonServ.mod/cmd_neonserv.h +++ b/src/modules/NeonServ.mod/cmd_neonserv.h @@ -78,6 +78,7 @@ CMD_BIND(neonserv_cmd_help); CMD_BIND(neonserv_cmd_info); CMD_BIND(neonserv_cmd_invite); CMD_BIND(neonserv_cmd_inviteme); +CMD_BIND(neonserv_cmd_invitemeall); CMD_BIND(neonserv_cmd_kick); CMD_BIND(neonserv_cmd_kickban); CMD_BIND(neonserv_cmd_listrank); diff --git a/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c b/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c index f7f2a82..bbe7a30 100644 --- a/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c +++ b/src/modules/NeonServ.mod/cmd_neonserv_inviteme.c @@ -22,45 +22,15 @@ */ CMD_BIND(neonserv_cmd_inviteme) { - if(argc && !stricmp(argv[0], "all")) { - //invite to all channels where autoinvite is enabled - MYSQL_RES *res, *res2; - MYSQL_ROW chanuserrow, defaultrow = NULL; - printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `channel_name`, `channel_getinvite` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `user_user` = '%s' AND `chanuser_flags` >= '%d'", escape_string(user->auth), DB_CHANUSER_AUTOINVITE); - res = mysql_use(); - struct ChanUser *bchanuser; - struct ClientSocket *bot; - while((chanuserrow = mysql_fetch_row(res)) != NULL) { - int userflags = atoi(chanuserrow[1]); - if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue; - if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel - if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED)) - bot = client; - else { - bot = getBotForChannel(chan); - } - if(getChanUser(user, chan)) continue; //user is already in the channel - if(chanuserrow[3] == NULL && defaultrow == NULL) { - printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'"); - res2 = mysql_use(); - defaultrow = mysql_fetch_row(res2); - } - if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) { - putsock(bot, "INVITE %s %s", user->nick, chan->name); - reply(textclient, user, "NS_INVITEME_DONE", chan->name); - } - } - } else { - if(getChanUser(user, chan)) { - reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name); - /* BUG - This check does not work if the user is invisible (CHMODE +D/+d) - to fix this we'd need to request the full userlist... - this is really senseless to invite a simple user so we simply mark this bug as unsolvable. - */ - return; - } - putsock(client, "INVITE %s %s", user->nick, chan->name); - reply(textclient, user, "NS_INVITEME_DONE", chan->name); + if(getChanUser(user, chan)) { + reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name); + /* BUG + This check does not work if the user is invisible (CHMODE +D/+d) + to fix this we'd need to request the full userlist... + this is really senseless to invite a simple user so we simply mark this bug as unsolvable. + */ + return; } + putsock(client, "INVITE %s %s", user->nick, chan->name); + reply(textclient, user, "NS_INVITEME_DONE", chan->name); } diff --git a/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c b/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c new file mode 100644 index 0000000..9f5b56d --- /dev/null +++ b/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c @@ -0,0 +1,52 @@ +/* cmd_neonserv_invitemeall.c - NeonServ v5.6 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "cmd_neonserv.h" + +/* +* no arguments +*/ + +CMD_BIND(neonserv_cmd_invitemeall) { + //invite to all channels where autoinvite is enabled + MYSQL_RES *res, *res2; + MYSQL_ROW chanuserrow, defaultrow = NULL; + printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `channel_name`, `channel_getinvite` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `user_user` = '%s' AND `chanuser_flags` >= '%d'", escape_string(user->auth), DB_CHANUSER_AUTOINVITE); + res = mysql_use(); + struct ChanUser *bchanuser; + struct ClientSocket *bot; + while((chanuserrow = mysql_fetch_row(res)) != NULL) { + int userflags = atoi(chanuserrow[1]); + if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue; + if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel + if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED)) + bot = client; + else { + bot = getBotForChannel(chan); + } + if(getChanUser(user, chan)) continue; //user is already in the channel + if(chanuserrow[3] == NULL && defaultrow == NULL) { + printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'"); + res2 = mysql_use(); + defaultrow = mysql_fetch_row(res2); + } + if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) { + putsock(bot, "INVITE %s %s", user->nick, chan->name); + reply(textclient, user, "NS_INVITEME_DONE", chan->name); + } + } +} -- 2.20.1