moved inviteme all to an own command called invitemeall
[NeonServV5.git] / src / modules / NeonServ.mod / cmd_neonserv_invitemeall.c
diff --git a/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c b/src/modules/NeonServ.mod/cmd_neonserv_invitemeall.c
new file mode 100644 (file)
index 0000000..9f5b56d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. 
+ */
+
+#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);
+        }
+    }
+}