1 /* cmd_neonserv_inviteme.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_inviteme) {
25 if(argc && !stricmp(argv[0], "all")) {
26 //invite to all channels where autoinvite is enabled
27 MYSQL_RES *res, *res2;
28 MYSQL_ROW chanuserrow, defaultrow = NULL;
29 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);
31 struct ChanUser *bchanuser;
32 struct ClientSocket *bot;
33 while((chanuserrow = mysql_fetch_row(res)) != NULL) {
34 int userflags = atoi(chanuserrow[1]);
35 if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue;
36 if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel
37 if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED))
40 bot = getBotForChannel(chan);
42 if(getChanUser(user, chan)) continue; //user is already in the channel
43 if(chanuserrow[3] == NULL && defaultrow == NULL) {
44 printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'");
46 defaultrow = mysql_fetch_row(res2);
48 if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) {
49 putsock(bot, "INVITE %s %s", user->nick, chan->name);
50 reply(textclient, user, "NS_INVITEME_DONE", chan->name);
54 if(getChanUser(user, chan)) {
55 reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name);
57 This check does not work if the user is invisible (CHMODE +D/+d)
58 to fix this we'd need to request the full userlist...
59 this is really senseless to invite a simple user so we simply mark this bug as unsolvable.
63 putsock(client, "INVITE %s %s", user->nick, chan->name);
64 reply(textclient, user, "NS_INVITEME_DONE", chan->name);