*** VERSION 5.5.0 ***
[NeonServV5.git] / src / modules / NeonHelp.mod / cmd_neonhelp_delete.c
1 /* cmd_neonhelp_delete.c - NeonServ v5.5
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "cmd_neonhelp.h"
19
20 /*
21 * argv[0]   suppid
22 */
23
24 CMD_BIND(neonhelp_cmd_delete) {
25     //check permissions
26     MYSQL_RES *res;
27     MYSQL_ROW row, row2;
28     int caccess = 0;
29     printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
30     res = mysql_use();
31     if (!(row = mysql_fetch_row(res))) return;
32     //check if the user is a supporter (access in the support channel)
33     if((user->flags & USERFLAG_ISAUTHED)) {
34         int userid;
35         if(user->flags & USERFLAG_HAS_USERID)
36             userid = user->user_id;
37         else {
38             printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
39             res = mysql_use();
40             if ((row2 = mysql_fetch_row(res)) != NULL) {
41                 userid = atoi(row2[0]);
42                 user->user_id = userid;
43                 user->flags |= USERFLAG_HAS_USERID;
44             } else
45                 userid = 0;
46         }
47         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]));
48         res = mysql_use();
49         if ((row2 = mysql_fetch_row(res)) != NULL) {
50             int cflags = atoi(row2[1]);
51             if(!(cflags & DB_CHANUSER_SUSPENDED))
52                 caccess = atoi(row2[0]);
53         }
54     }
55     if(!caccess) {
56         reply(textclient, user, "MODCMD_ACCESS_DENIED");
57         return;
58     }
59     if(!(client->flags & SOCKET_HAVE_HELPNODE) || client->botclass_helpnode == NULL) {
60         reply(textclient, user, "NH_NEXT_NONE");
61         return;
62     }
63     struct NeonHelpNode *helpnode, *prev_helpnode = NULL;
64     for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
65         if(atoi(argv[0]) == helpnode->suppid)
66             break;
67         else
68             prev_helpnode = helpnode;
69     }
70     if(!helpnode) {
71         reply(textclient, user, "NH_NEXT_NOT_FOUND");
72         return;
73     }
74     if(helpnode->status == 1) {
75         struct ChanNode *support, *public;
76         support = getChanByName(row[0]);
77         public = (row[1] ? getChanByName(row[1]) : NULL);
78         if(isUserOnChan(helpnode->user, support)) {
79             if(public)
80                 putsock(client, "KICK %s %s :your request has been closed", support->name, helpnode->user->nick);
81             else
82                 putsock(client, "MODE %s -v %s", support->name, helpnode->user->nick);
83         } else {
84             putsock(client, "MODE %s -i", support->name); //clear invite list
85             if(isModeSet(support->modes, 'i'))
86                 putsock(client, "MODE %s +i", support->name);
87             neonhelp_invite_active_requests(client, support, public, helpnode->user);
88         }
89     }
90     if(prev_helpnode)
91         prev_helpnode->next = helpnode->next;
92     else
93         client->botclass_helpnode = helpnode->next;
94     reply(textclient, user, "NH_DELETED_STAFF", helpnode->suppid, helpnode->user->nick);
95     neonhelp_destroy_support_request(client, helpnode, 1);
96 }