tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_mdeluser.c
diff --git a/src/cmd_neonserv_mdeluser.c b/src/cmd_neonserv_mdeluser.c
new file mode 100644 (file)
index 0000000..5b09822
--- /dev/null
@@ -0,0 +1,48 @@
+
+#include "cmd_neonserv.h"
+
+/*
+* argv[0]  access (format: minaccess-maxaccess)
+* argv[1]  pattern
+*/
+
+CMD_BIND(neonserv_cmd_mdeluser) {
+    if(!checkChannelAccess(user, chan, "channel_candel", 1, 0)) {
+        reply(getTextBot(), user, "NS_ACCESS_DENIED");
+        return;
+    }
+    int min_access, max_access;
+    char *seperator = strstr(argv[0], "-");
+    if(seperator) {
+        *seperator = '\0';
+        seperator++;
+        min_access = atoi(argv[0]);
+        max_access = atoi(seperator);
+        if(max_access > min_access) {
+            reply(getTextBot(), user, "NS_INVALID_ACCESS_RANGE", min_access, max_access);
+            return;
+        }
+    } else {
+        min_access = atoi(argv[0]);
+        max_access = min_access;
+    }
+    if(max_access >= getChannelAccess(user, chan, 1)) {
+        reply(getTextBot(), user, "NS_NO_ACCESS");
+        return;
+    }
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    int del_count = 0;
+    printf_mysql_query("SELECT `user_user`, `chanuser_id` FROM `chanusers` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `chanuser_cid` = '%d' AND `chanuser_access` >= '%d' AND `chanuser_access` <= '%d'", chan->channel_id, min_access, max_access);
+    res = mysql_use();
+    while((row = mysql_fetch_row(res)) != NULL) {
+        if(!match(argv[1], row[0])) {
+            del_count++;
+            printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_id` = '%s'", row[1]);
+        }
+    }
+    reply(getTextBot(), user, "NS_MDELUSER_DONE", del_count, argv[1], min_access, max_access, chan->name);
+    if(del_count)
+        logEvent(event);
+}
+