1 /* cmd_neonserv_invitemeall.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonserv.h"
24 CMD_BIND(neonserv_cmd_invitemeall) {
25 //invite to all channels where autoinvite is enabled
26 MYSQL_RES *res, *res2;
27 MYSQL_ROW chanuserrow, defaultrow = NULL;
28 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);
30 struct ChanUser *bchanuser;
31 struct ClientSocket *bot;
32 while((chanuserrow = mysql_fetch_row(res)) != NULL) {
33 int userflags = atoi(chanuserrow[1]);
34 if(!(argc && !stricmp(argv[0], "all")) && !(userflags & DB_CHANUSER_AUTOINVITE)) continue;
35 if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel
36 if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED))
39 bot = getBotForChannel(chan);
41 if(getChanUser(user, chan)) continue; //user is already in the channel
42 if(chanuserrow[3] == NULL && defaultrow == NULL) {
43 printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'");
45 defaultrow = mysql_fetch_row(res2);
47 if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) {
48 putsock(bot, "INVITE %s %s", user->nick, chan->name);
49 reply(textclient, user, "NS_INVITEME_DONE", chan->name);