*** VERSION 5.5.0 ***
[NeonServV5.git] / src / modules / NeonSpam.mod / cmd_neonspam_addbad.c
1 /* cmd_neonspam_addbad.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_addbad) {
21     char *cbadword = merge_argv(argv, 0, argc);
22     MYSQL_RES *res;
23     MYSQL_ROW row, defaults;
24     loadChannelSettings(chan);
25     loadNeonSpamSettings(chan);
26     struct NeonSpamSettings *settings = chan->spam_settings;
27     if(!settings) return;
28     printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
29     res = mysql_use();
30     row = mysql_fetch_row(res);
31     if(!row[0] || !row[1]) {
32         printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
33         res = mysql_use();
34         defaults = mysql_fetch_row(res);
35     }
36     int reaction = atoi((row[0] ? row[0] : defaults[0])) + 1;
37     int reaction_time = atoi((row[1] ? row[1] : defaults[1]));
38     if(strlen(cbadword) > 128)
39         cbadword[128] = 0;
40     int scan_ops = ((settings->flags & SPAMSETTINGS_BADWORDSCAN_OPS) ? 1 : 0);
41     int scan_voice = ((settings->flags & SPAMSETTINGS_BADWORDSCAN_VOICE) ? 1 : 0);
42     printf_mysql_query("INSERT INTO `spamserv_badwords` (`badword_cid`, `badword_match`, `badword_use_default`, `badword_exceptlevel`, `badword_scan_ops`, `badword_scan_voice`, `badword_use_default_reaction`, `badword_reaction`, `badword_reaction_time`) VALUES ('%d', '%s', '1', '%d', '%d', '%d', '1', '%d', '%d')", chan->channel_id, escape_string(cbadword), settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX], scan_ops, scan_voice, reaction, reaction_time);
43     int badword_id = (int) mysql_insert_id(get_mysql_conn());
44     struct NeonSpamBadword *badword = malloc(sizeof(*badword));
45     badword->id = badword_id;
46     badword->badword = strdup(cbadword);
47     badword->use_defaults = 1;
48     badword->exceptlevel = settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX];
49     badword->scan_ops = scan_ops;
50     badword->scan_voice = scan_voice;
51     badword->use_default_reaction = 1;
52     badword->reaction = reaction;
53     badword->reaction_time = reaction_time;
54     badword->next = settings->badwords;
55     settings->badwords = badword;
56     reply(textclient, user, "SS_BADWORD_ADDED", cbadword, badword_id);
57 }