rearranged NeonServ code to be modular
[NeonServV5.git] / src / modules / NeonServ.mod / cmd_neonserv_upall.c
diff --git a/src/modules/NeonServ.mod/cmd_neonserv_upall.c b/src/modules/NeonServ.mod/cmd_neonserv_upall.c
new file mode 100644 (file)
index 0000000..0f12379
--- /dev/null
@@ -0,0 +1,73 @@
+/* cmd_neonserv_upall.c - NeonServ v5.3
+ * 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_upall) {
+    MYSQL_RES *res, *default_res;
+    MYSQL_ROW row, default_row;
+    struct ChanUser *chanuser;
+    int userid, chan_getop, chan_getvoice, caccess;
+    int botid = client->botid;
+    printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", user->auth);
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) == NULL)
+        return;
+    userid = atoi(row[0]);
+    printf_mysql_query("SELECT `chanuser_access`, `channel_getop`, `channel_getvoice`, `channel_name`, `channel_id` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d'", userid);
+    res = mysql_use();
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        chan = getChanByName(row[3]);
+        if(!chan) continue;
+        printf_mysql_query("SELECT `botid` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%s' AND `botclass` = '%d'", row[4], client->botid);
+        if (mysql_fetch_row(mysql_use()) == NULL) continue;
+        if(!(chanuser = getChanUser(user, chan))) continue;
+        if(!row[1] || !row[2]) {
+            printf_mysql_query("SELECT `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_name` = 'defaults'");
+            default_res = mysql_use();
+            if ((default_row = mysql_fetch_row(default_res)) == NULL) return;
+            chan_getop = (row[1] ? atoi(row[1]) : atoi(default_row[0]));
+            chan_getvoice = (row[2] ? atoi(row[2]) : atoi(default_row[1]));
+        } else {
+            chan_getop = atoi(row[1]);
+            chan_getvoice = atoi(row[2]);
+        }
+        caccess = atoi(row[0]);
+        int done = 0;
+        client = getChannelBot(chan, botid);
+        if(!client) continue;
+        if(caccess >= chan_getop) {
+            if(!(chanuser->flags & CHANUSERFLAG_OPPED)) {
+                putsock(client, "MODE %s +o %s", chan->name, user->nick);
+                done = 1;
+            }
+        } else if(caccess >= chan_getvoice) {
+            if(!(chanuser->flags & CHANUSERFLAG_VOICED)) {
+                putsock(client, "MODE %s +v %s", chan->name, user->nick);
+                done = 1;
+            }
+        }
+        if(done) {
+            event->chan = chan;
+            logEvent(event);
+        }
+    }
+}