*** VERSION 5.5.0 ***
[NeonServV5.git] / src / modules / NeonSpam.mod / cmd_neonspam_delbad.c
1 /* cmd_neonspam_delbad.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_neonspam.h"
19
20 CMD_BIND(neonspam_cmd_delbad) {
21     MYSQL_RES *res;
22     MYSQL_ROW row;
23     loadChannelSettings(chan);
24     loadNeonSpamSettings(chan);
25     struct NeonSpamSettings *settings = chan->spam_settings;
26     if(!settings) return;
27     int badword_id = atoi(argv[0]);
28     printf_mysql_query("SELECT `badword_match` FROM `spamserv_badwords` WHERE `badword_id` = '%d' AND `badword_cid` = '%d'", badword_id, chan->channel_id);
29     res = mysql_use();
30     if(!(row = mysql_fetch_row(res))) {
31         reply(textclient, user, "SS_BADWORD_ID_UNKNOWN", badword_id, chan->name);
32         return;
33     }
34     struct NeonSpamBadword *badword, *prev = NULL;
35     for(badword = settings->badwords; badword; badword = badword->next) {
36         if(badword->id == badword_id) {
37             if(prev)
38                 prev->next = badword->next;
39             else
40                 settings->badwords = badword->next;
41             free(badword->badword);
42             free(badword);
43             break;
44         } else
45             prev = badword;
46     }
47     printf_mysql_query("DELETE FROM `spamserv_badwords` WHERE `badword_id` = '%d'", badword_id);
48     reply(textclient, user, "SS_BADWORD_DELETED", row[0], badword_id);
49 }