rearranged NeonServ code to be modular
[NeonServV5.git] / src / modules / NeonHelp.mod / cmd_neonhelp_delete.c
diff --git a/src/modules/NeonHelp.mod/cmd_neonhelp_delete.c b/src/modules/NeonHelp.mod/cmd_neonhelp_delete.c
new file mode 100644 (file)
index 0000000..43d5829
--- /dev/null
@@ -0,0 +1,83 @@
+/* cmd_neonhelp_delete.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_neonhelp.h"
+
+/*
+* argv[0]   suppid
+*/
+
+CMD_BIND(neonhelp_cmd_delete) {
+    //check permissions
+    MYSQL_RES *res;
+    MYSQL_ROW row, row2;
+    int caccess = 0;
+    printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
+    res = mysql_use();
+    if (!(row = mysql_fetch_row(res))) return;
+    //check if the user is a supporter (access in the support channel)
+    if((user->flags & USERFLAG_ISAUTHED)) {
+        int userid;
+        if(user->flags & USERFLAG_HAS_USERID)
+            userid = user->user_id;
+        else {
+            printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
+            res = mysql_use();
+            if ((row2 = mysql_fetch_row(res)) != NULL) {
+                userid = atoi(row2[0]);
+                user->user_id = userid;
+                user->flags |= USERFLAG_HAS_USERID;
+            } else
+                userid = 0;
+        }
+        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
+        res = mysql_use();
+        if ((row2 = mysql_fetch_row(res)) != NULL) {
+            int cflags = atoi(row2[1]);
+            if(!(cflags & DB_CHANUSER_SUSPENDED))
+                caccess = atoi(row2[0]);
+        }
+    }
+    if(!caccess) {
+        reply(getTextBot(), user, "MODCMD_ACCESS_DENIED");
+        return;
+    }
+    if(!(client->flags & SOCKET_HAVE_HELPNODE) || client->botclass_helpnode == NULL) {
+        reply(getTextBot(), user, "NH_NEXT_NONE");
+        return;
+    }
+    struct NeonHelpNode *helpnode, *next_helpnode = NULL, *prev_helpnode = NULL;
+    for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
+        if(atoi(argv[0]) == helpnode->suppid) {
+            next_helpnode = helpnode;
+            break;
+        } else
+            prev_helpnode = helpnode;
+    }
+    if(!next_helpnode) {
+        reply(getTextBot(), user, "NH_NEXT_NOT_FOUND");
+        return;
+    }
+    reply(client, next_helpnode->user, "NH_DELETED", next_helpnode->suppid);
+    printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '2' WHERE `id` = '%d'", next_helpnode->suppid);
+    if(prev_helpnode)
+        prev_helpnode->next = next_helpnode->next;
+    else
+        client->botclass_helpnode = next_helpnode->next;
+    reply(getTextBot(), user, "NH_DELETED_STAFF", next_helpnode->suppid, next_helpnode->user->nick);
+    free(next_helpnode);
+}