1 /* cmd_neonspam_badwords.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
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.
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.
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/>.
18 #include "cmd_neonspam.h"
20 CMD_BIND(neonspam_cmd_badwords) {
22 MYSQL_ROW row, defaults;
23 loadChannelSettings(chan);
24 loadNeonSpamSettings(chan);
25 struct NeonSpamSettings *settings = chan->spam_settings;
28 int badword_id = atoi(argv[0]);
29 printf_mysql_query("SELECT `badword_match` FROM `spamserv_badwords` WHERE `badword_id` = '%d' AND `badword_cid` = '%d'", badword_id, chan->channel_id);
31 if(!(row = mysql_fetch_row(res))) {
32 reply(textclient, user, "SS_BADWORD_ID_UNKNOWN", badword_id, chan->name);
39 printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
41 row = mysql_fetch_row(res);
42 if(!row[0] || !row[1]) {
43 printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
45 defaults = mysql_fetch_row(res);
47 int default_reaction = atoi((row[0] ? row[0] : defaults[0]));
48 int default_reaction_time = atoi((row[1] ? row[1] : defaults[1]));
49 printf_mysql_query("SELECT `badword_id`, `badword_match`, `badword_use_default`, `badword_exceptlevel`, `badword_scan_ops`, `badword_scan_voice`, `badword_use_default_reaction`, `badword_reaction`, `badword_reaction_time` FROM `spamserv_badwords` WHERE `badword_cid` = '%d' ORDER BY `badword_id` ASC", chan->channel_id);
51 table = table_init(4, mysql_num_rows(res) + 1, 0);
53 content[0] = get_language_string(user, "SS_BADWORDS_ID");
54 content[1] = get_language_string(user, "SS_BADWORDS_PATTERN");
55 content[2] = get_language_string(user, "SS_BADWORDS_SCAN");
56 content[3] = get_language_string(user, "SS_BADWORDS_REACTION");
57 table_add(table, content);
58 char default_exception[100];
59 char exception_buf[100], reaction_buf[100], reaction_time_buf[100];
60 int exception_pos = 0, reaction_pos;
61 int reaction, reaction_time;
62 if(settings->flags & SPAMSETTINGS_BADWORDSCAN_OPS)
63 exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & @" : "@"));
64 if(settings->flags & SPAMSETTINGS_BADWORDSCAN_VOICE)
65 exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & +" : "+"));
66 if(settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX])
67 exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & <%d" : "<%d"), settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX]);
68 while ((row = mysql_fetch_row(res)) != NULL) {
72 if(strcmp(row[2], "0")) {
73 exception_pos += sprintf(exception_buf, "\00314%s\003", default_exception);
75 if(!strcmp(row[4], "1"))
76 exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & @" : "@"));
77 if(!strcmp(row[5], "1"))
78 exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & +" : "+"));
80 exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & <%d" : "<%d"), atoi(row[3]));
82 content[2] = exception_buf;
84 if(strcmp(row[6], "0")) {
85 reaction = default_reaction;
86 reaction_time = default_reaction_time;
88 reaction = atoi(row[7]);
89 reaction_time = atoi(row[8]);
91 sprintf(reaction_buf, "SS_BADWORDS_REACTION_%d", reaction);
92 reaction_pos += sprintf(reaction_buf, "%s", get_language_string(user, reaction_buf));
94 reaction_pos += sprintf(reaction_buf+reaction_pos, " (%s)", timeToStr(user, reaction_time, 2, reaction_time_buf));
96 content[3] = reaction_buf;
97 table_add(table, content);
99 char **table_lines = table_end(table);
101 for(i = 0; i < table->entrys; i++) {
102 reply(textclient, user, table_lines[i]);