+++ /dev/null
-/* cmd_neonspam_set.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_neonspam.h"
-
-typedef char* neonspam_cmd_set_function(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_set_trigger(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setflags(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setexcept(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_set_reaction(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_set_reaction_time(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setpercent(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setsensibility(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_set_spamlimit(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setscanops(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setscanvoice(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-static char* neonspam_cmd_setscanexcept(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf);
-
-static MYSQL_ROW neonspam_settings_row, neonspam_settings_defaults;
-#define SPAMSERV_SETTINGS_QUERY "`channel_spam_reaction`, `channel_spam_reaction_duration`, `channel_flood_reaction`, `channel_flood_reaction_duration`, `channel_join_reaction`, `channel_join_reaction_duration`, `channel_botnet_bantime`, `channel_caps_reaction`, `channel_caps_reaction_duration`, `channel_digit_reaction`, `channel_digit_reaction_duration`"
-#define SPAMSERV_SETTINGS_RESET "\
-`channel_scanner` = NULL, \
-`channel_spam_limit` = NULL, \
-`channel_spam_reaction` = NULL, \
-`channel_spam_reaction_duration` = NULL, \
-`channel_spam_except` = NULL, \
-`channel_flood_limit` = NULL, \
-`channel_flood_time` = NULL, \
-`channel_flood_reaction` = NULL, \
-`channel_flood_reaction_duration` = NULL, \
-`channel_flood_except` = NULL, \
-`channel_join_limit` = NULL, \
-`channel_join_time` = NULL, \
-`channel_join_reaction` = NULL, \
-`channel_join_reaction_duration` = NULL, \
-`channel_join_except` = NULL, \
-`channel_botnet_bantime` = NULL, \
-`channel_botnet_except` = NULL, \
-`channel_caps_percent` = NULL, \
-`channel_caps_reaction` = NULL, \
-`channel_caps_reaction_duration` = NULL, \
-`channel_caps_except` = NULL,\
-`channel_digit_percent` = NULL, \
-`channel_digit_reaction` = NULL, \
-`channel_digit_reaction_duration` = NULL, \
-`channel_digit_except` = NULL "
-
-#define SET_HELP 0x0001
-#define SET_BOOL 0x0002
-#define SET_OPT 0x0004
-
-#define SET_SCANOPS 0x0010
-#define SET_SCANVOICE 0x0020
-#define SET_SCANEXCEPT 0x0040
-
-#define SET_OPT_MAX 0xff00
-#define SET_OPT_SHIFT 8
-
-static const struct {
- unsigned int if_flag;
- unsigned int indent;
- const char *setting;
- void *function;
- int intparam;
- char *charparam;
- int flags;
-} neonspam_settings[] = {
- {0, 0, "Trigger", neonspam_cmd_set_trigger, 0, NULL, SET_HELP},
-
- {0, 0, "SpamScan", neonspam_cmd_setflags, SPAMSETTINGS_SPAMSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_SPAMSCAN, 2, "SpamLimit", neonspam_cmd_set_spamlimit, 0, NULL, SET_HELP},
- {SPAMSETTINGS_SPAMSCAN | SPAMSETTINGS_SETTIMEBAN, 2, "SpamReaction", neonspam_cmd_set_reaction, 0, "channel_spam_reaction", SET_OPT | (3 << SET_OPT_SHIFT)},
- {SPAMSETTINGS_SPAMSCAN | SPAMSETTINGS_ISTIMEBAN, 4, "SpamBanDuration", neonspam_cmd_set_reaction_time, 1, "channel_spam_reaction_duration", 0},
- {SPAMSETTINGS_SPAMSCAN, 2, "SpamScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_SPAMSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_SPAMSCAN, 2, "SpamScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_SPAMSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- {SPAMSETTINGS_SPAMSCAN, 2, "SpamScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_SPAMEXCINDEX, "channel_spam_except", SET_HELP | SET_SCANEXCEPT},
-
- {0, 0, "FloodScan", neonspam_cmd_setflags, SPAMSETTINGS_FLOODSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_FLOODSCAN, 2, "FloodSensibility", neonspam_cmd_setsensibility, SPAMSETTINGS_FLOODSENINDEX, "channel_flood_", SET_HELP},
- {SPAMSETTINGS_FLOODSCAN | SPAMSETTINGS_SETTIMEBAN, 2, "FloodReaction", neonspam_cmd_set_reaction, 2, "channel_flood_reaction", SET_OPT | (3 << SET_OPT_SHIFT)},
- {SPAMSETTINGS_FLOODSCAN | SPAMSETTINGS_ISTIMEBAN, 4, "FloodBanDuration", neonspam_cmd_set_reaction_time, 3, "channel_flood_reaction_duration",0},
- {SPAMSETTINGS_FLOODSCAN, 2, "FloodScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_FLOODSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_FLOODSCAN, 2, "FloodScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_FLOODSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- {SPAMSETTINGS_FLOODSCAN, 2, "FloodScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_FLOODEXCINDEX, "channel_flood_except", SET_HELP | SET_SCANEXCEPT},
-
- {0, 0, "JoinScan", neonspam_cmd_setflags, SPAMSETTINGS_JOINSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_JOINSCAN, 2, "JoinSensibility", neonspam_cmd_setsensibility, SPAMSETTINGS_JOINSENINDEX, "channel_join_", SET_HELP},
- {SPAMSETTINGS_JOINSCAN | SPAMSETTINGS_SETTIMEBAN, 2, "JoinReaction", neonspam_cmd_set_reaction, 4, "channel_join_reaction", SET_OPT | (3 << SET_OPT_SHIFT)},
- {SPAMSETTINGS_JOINSCAN | SPAMSETTINGS_ISTIMEBAN, 4, "JoinBanDuration", neonspam_cmd_set_reaction_time, 5, "channel_join_reaction_duration", 0},
- {SPAMSETTINGS_JOINSCAN, 2, "JoinScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_JOINSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_JOINSCAN, 2, "JoinScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_JOINSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- {SPAMSETTINGS_JOINSCAN, 2, "JoinScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_JOINEXCINDEX, "channel_join_except", SET_HELP | SET_SCANEXCEPT},
-
- {0, 0, "BotNetScan", neonspam_cmd_setflags, SPAMSETTINGS_BOTNETSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_BOTNETSCAN, 4, "BotNetBanDuration", neonspam_cmd_set_reaction_time, 6, "channel_botnet_bantime", 0},
- {SPAMSETTINGS_BOTNETSCAN, 2, "BotNetScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_BOTNETSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_BOTNETSCAN, 2, "BotNetScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_BOTNETSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- //{SPAMSETTINGS_BOTNETSCAN, 2, "BotNetScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_BOTNETEXCINDEX, "channel_botnet_except", SET_HELP},
-
- {0, 0, "CapsScan", neonspam_cmd_setflags, SPAMSETTINGS_CAPSSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_CAPSSCAN, 2, "CapsPercent", neonspam_cmd_setpercent, SPAMSETTINGS_CAPSPERCENTINDEX, "channel_caps_percent", SET_HELP},
- {SPAMSETTINGS_CAPSSCAN | SPAMSETTINGS_SETTIMEBAN, 2, "CapsReaction", neonspam_cmd_set_reaction, 7, "channel_caps_reaction", SET_OPT | (3 << SET_OPT_SHIFT)},
- {SPAMSETTINGS_CAPSSCAN | SPAMSETTINGS_ISTIMEBAN, 4, "CapsBanDuration", neonspam_cmd_set_reaction_time, 8, "channel_caps_reaction_duration", 0},
- {SPAMSETTINGS_CAPSSCAN, 2, "CapsScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_CAPSSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_CAPSSCAN, 2, "CapsScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_CAPSSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- {SPAMSETTINGS_CAPSSCAN, 2, "CapsScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_CAPSEXCINDEX, "channel_caps_except", SET_HELP | SET_SCANEXCEPT},
-
- {0, 0, "DigitScan", neonspam_cmd_setflags, SPAMSETTINGS_DIGITSCAN, NULL, SET_BOOL},
- {SPAMSETTINGS_DIGITSCAN, 2, "DigitPercent", neonspam_cmd_setpercent, SPAMSETTINGS_DIGITPERCENTINDEX, "channel_digit_percent", SET_HELP},
- {SPAMSETTINGS_DIGITSCAN | SPAMSETTINGS_SETTIMEBAN, 2, "DigitReaction", neonspam_cmd_set_reaction, 9, "channel_digit_reaction", SET_OPT | (3 << SET_OPT_SHIFT)},
- {SPAMSETTINGS_DIGITSCAN | SPAMSETTINGS_ISTIMEBAN, 4, "DigitBanDuration", neonspam_cmd_set_reaction_time, 10, "channel_digit_reaction_duration", 0},
- {SPAMSETTINGS_DIGITSCAN, 2, "DigitScanChanOps", neonspam_cmd_setflags, SPAMSETTINGS_DIGITSCAN_OPS, NULL, SET_BOOL | SET_SCANOPS},
- {SPAMSETTINGS_DIGITSCAN, 2, "DigitScanVoiced", neonspam_cmd_setflags, SPAMSETTINGS_DIGITSCAN_VOICE, NULL, SET_BOOL | SET_SCANVOICE},
- {SPAMSETTINGS_DIGITSCAN, 2, "DigitScanExcept", neonspam_cmd_setexcept, SPAMSETTINGS_DIGITEXCINDEX, "channel_digit_except", SET_HELP | SET_SCANEXCEPT},
-
- {0, 0, "GlobalScanChanOps", neonspam_cmd_setscanops, 0, NULL, SET_BOOL},
- {0, 0, "GlobalScanVoice", neonspam_cmd_setscanvoice, 0, NULL, SET_BOOL},
- {0, 0, "GlobalScanExcept", neonspam_cmd_setscanexcept, 0, NULL, SET_HELP},
-
- {0, 0, NULL, NULL, 0, NULL, 0}
-};
-
-#define MAX_QUERY_LEN 1024
-CMD_BIND(neonspam_cmd_set) {
- int i, j;
- loadNeonSpamSettings(chan);
- if(argc && !strcmp(argv[0], "defaults")) {
- //reset channel settings
- int uaccess = getChannelAccess(user, chan);
- if(uaccess < 500) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_DEFAULTS_OWNER", chan->name);
- return;
- }
- }
- int seed = 0;
- char *tmp;
- static char defaultskey[16];
- for(tmp = user->auth; *tmp; tmp++)
- seed = (seed * 0xEECE66DL ^ ((*tmp << 24) | (*tmp << 16) | (*tmp << 8) | *tmp));
- for(tmp = chan->name; *tmp; tmp++)
- seed = (seed * 0xEECE66DL ^ ((*tmp << 24) | (*tmp << 16) | (*tmp << 8) | *tmp));
- sprintf(defaultskey, "%08x", seed);
- if(argc > 1 && !strcmp(argv[1], defaultskey)) {
- printf_mysql_query("UPDATE `channels` SET " SPAMSERV_SETTINGS_RESET " WHERE `channel_id` = '%d'", chan->channel_id);
- reply(getTextBot(), user, "NS_SET_DEFAULTS_DONE", chan->name);
- logEvent(event);
- } else {
- reply(getTextBot(), user, "NS_SET_DEFAULTS_CODE", chan->name, defaultskey);
- }
- } else if(argc && strcmp(argv[0], "help")) {
- //find the correct command
- i = 0;
- j = 0;
- char *args = (argc > 1 ? merge_argv(argv, 1, argc) : NULL);
- neonspam_settings_row = NULL;
- neonspam_settings_defaults = NULL;
- while(neonspam_settings[i].setting) {
- if(!stricmp(neonspam_settings[i].setting, argv[0])) {
- //setting found
- char valueBuf[MAXLEN], nameBuf[MAXLEN];
- char *value, *optimized_value, *option_help;
- neonspam_cmd_set_function *func = neonspam_settings[i].function;
- value = func(client, user, chan, event, neonspam_settings[i].intparam, neonspam_settings[i].charparam, args, valueBuf);
- if(value) {
- optimized_value = value;
- if(neonspam_settings[i].flags & SET_BOOL) {
- if(!strcmp(value, "0"))
- optimized_value = get_language_string(user, "NS_SET_OFF");
- else if(!strcmp(value, "1"))
- optimized_value = get_language_string(user, "NS_SET_ON");
- }
- if(neonspam_settings[i].flags & SET_OPT) {
- sprintf(nameBuf, "SS_SET_OPTION_%s_%s", neonspam_settings[i].setting, value);
- option_help = get_language_string(user, nameBuf);
- } else
- option_help = NULL;
- reply(getTextBot(), user, "\002%s\002 %s%s%s", neonspam_settings[i].setting, optimized_value, (option_help ? " - " : ""), (option_help ? option_help : ""));
- if(neonspam_settings[i].flags & SET_OPT) {
- int maxoption = (neonspam_settings[i].flags & SET_OPT_MAX) >> SET_OPT_SHIFT;
- for(j = 0; j < maxoption; j++) {
- sprintf(nameBuf, "SS_SET_OPTION_%s_%d", neonspam_settings[i].setting, j);
-
- reply(getTextBot(), user, " \002%d\002 - %s", j, option_help);
- }
- }
- if((neonspam_settings[i].flags & SET_HELP) && argc && !strcmp(argv[0], "help")) {
- char *tmp;
- sprintf(nameBuf, "SS_SET_HELP_%s", neonspam_settings[i].setting);
- tmp = get_language_string(user, nameBuf);
- if(tmp) {
- reply(getTextBot(), user, " %s", tmp);
- }
- }
- }
- j = 1;
- break;
- }
- i++;
- }
- if(j == 0) {
- //unknown setting
- reply(getTextBot(), user, "NS_SET_UNKNOWN_SETTING", argv[0]);
- }
- } else {
- char valueBuf[MAXLEN], nameBuf[MAXLEN];
- char *value;
- int namePos, boolflag = 0;
- MYSQL_RES *res, *defaults_res;
- struct Table *table;
- char *content[2];
- i = 0;
- while(neonspam_settings[i].setting)
- i++;
- table = table_init(2, i, 0);
- table_set_bold(table, 0, 1);
- printf_mysql_query("SELECT " SPAMSERV_SETTINGS_QUERY " FROM `channels` WHERE `channel_name` = 'defaults'");
- defaults_res = mysql_use();
- neonspam_settings_defaults = mysql_fetch_row(defaults_res);
- printf_mysql_query("SELECT " SPAMSERV_SETTINGS_QUERY " FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
- res = mysql_use();
- neonspam_settings_row = mysql_fetch_row(res);
- i = -1;
- reply(getTextBot(), user, "NS_SET_HEADER", chan->name);
- while(neonspam_settings[++i].setting) {
- if((chan->spam_settings->flags & (neonspam_settings[i].if_flag & SPAMSETTINGS_FLAGS)) != (neonspam_settings[i].if_flag & SPAMSETTINGS_FLAGS))
- continue;
- if((neonspam_settings[i].if_flag & SPAMSETTINGS_ISTIMEBAN) && !boolflag)
- continue;
- neonspam_cmd_set_function *func = neonspam_settings[i].function;
- value = func(client, user, chan, event, neonspam_settings[i].intparam, neonspam_settings[i].charparam, NULL, valueBuf);
- if(neonspam_settings[i].if_flag & SPAMSETTINGS_SETTIMEBAN)
- boolflag = !strcmp(value, "2");
- //TODO: append option or help info
- strcpy(valueBuf, value);
- if(neonspam_settings[i].flags & SET_BOOL) {
- if(!strcmp(value, "0"))
- strcpy(valueBuf, get_language_string(user, "NS_SET_OFF"));
- else if(!strcmp(value, "1"))
- strcpy(valueBuf, get_language_string(user, "NS_SET_ON"));
- }
- if(neonspam_settings[i].flags & SET_OPT) {
- char *tmp;
- sprintf(nameBuf, "SS_SET_OPTION_%s_%s", neonspam_settings[i].setting, value);
- tmp = get_language_string(user, nameBuf);
- if(tmp) {
- sprintf(valueBuf + strlen(valueBuf), " - %s", tmp);
- }
- }
- if((neonspam_settings[i].flags & SET_HELP) && argc && !strcmp(argv[0], "help")) {
- char *tmp;
- sprintf(nameBuf, "SS_SET_HELP_%s", neonspam_settings[i].setting);
- tmp = get_language_string(user, nameBuf);
- if(tmp) {
- sprintf(valueBuf + strlen(valueBuf), " - %s", tmp);
- }
- }
- namePos = 0;
- for(j = 0; j < neonspam_settings[i].indent; j++) {
- nameBuf[namePos++] = ' ';
- }
- sprintf(nameBuf + namePos, "%s", neonspam_settings[i].setting);
- content[0] = nameBuf;
- content[1] = valueBuf;
- table_add(table, content);
- }
- char **table_lines = table_end(table);
- for(i = 0; i < table->entrys; i++) {
- reply(getTextBot(), user, table_lines[i]);
- }
- table_free(table);
- }
-}
-
-static char* neonspam_cmd_set_trigger(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf) {
- char *trigger;
- //get current trigger
- MYSQL_RES *res;
- MYSQL_ROW row;
- printf_mysql_query("SELECT `trigger`, `defaulttrigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botid` = '%d'", chan->channel_id, client->clientid);
- res = mysql_use();
- row = mysql_fetch_row(res);
- trigger = (row[0] ? row[0] : row[1]);
- if(argument) {
- int uaccess = getChannelAccess(user, chan);
- if(uaccess < 500) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_TRIGGER_OWNER", chan->name);
- return NULL;
- }
- }
- if(strlen(argument) > 15)
- argument[15] = '\0';
- printf_mysql_query("UPDATE `bot_channels` SET `trigger` = '%s' WHERE `chanid` = '%d' AND `botid` = '%d'", escape_string(argument), chan->channel_id, client->clientid);
- trigger = argument;
- changeChannelTrigger(client->botid, chan, trigger);
- logEvent(event);
- }
- return trigger;
-}
-
-static char* neonspam_cmd_setflags(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int flag, char *charparam, char *argument, char *retBuf) {
- char *value = ((chan->spam_settings->flags & flag) ? "1" : "0");
- if(argument) {
- //binary argument...
- if(!strcmp(argument, "0") || !stricmp(argument, "off") || !stricmp(argument, get_language_string(user, "NS_SET_OFF"))) {
- chan->spam_settings->flags &= ~flag;
- } else if(!strcmp(argument, "1") || !stricmp(argument, "on") || !stricmp(argument, get_language_string(user, "NS_SET_ON"))) {
- chan->spam_settings->flags |= flag;
- } else {
- reply(getTextBot(), user, "NS_SET_INVALID_BOOLEAN", argument);
- return NULL;
- }
- char str_flags[50];
- convertNeonSpamSettingsToString(chan->spam_settings->flags, str_flags);
- printf_mysql_query("UPDATE `channels` SET `channel_scanner` = '%s' WHERE `channel_id` = '%d' ", str_flags, chan->channel_id);
- value = argument;
- }
- return value;
-}
-
-static char* neonspam_cmd_setexcept(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int exceptlvl_index, char *field, char *argument, char *retBuf) {
- unsigned int value = chan->spam_settings->exceptlevel[exceptlvl_index];
- if(argument) {
- //numeric argument... (access)
- int caccess = atoi(argument);
- if(caccess < 0 || caccess > 501) {
- reply(getTextBot(), user, "NS_INVALID_ACCESS", caccess);
- return NULL;
- }
- int uaccess = getChannelAccess(user, chan);
- if(uaccess == 500) uaccess++;
- if(value > uaccess) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_CANNOT_SET");
- return NULL;
- }
- }
- if(caccess > uaccess) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_BADLEVEL");
- return NULL;
- }
- }
- value = caccess;
- chan->spam_settings->exceptlevel[exceptlvl_index] = value;
- printf_mysql_query("UPDATE `channels` SET `%s` = '%u' WHERE `channel_id` = '%d' ", field, value, chan->channel_id);
- }
- sprintf(retBuf, "%u", value);
- return retBuf;
-}
-
-static char* neonspam_cmd_set_reaction(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int mysqlindex, char *mysqlfield, char *argument, char *retBuf) {
- if(argument) {
- /* valid options:
- * 0/kick - kick
- * 1/kickban - kickban
- * 2/ban - timed ban
- */
- if(!strcmp(argument, "0") || !stricmp(argument, "kick")) {
- argument = "0";
- } else if(!strcmp(argument, "1") || !stricmp(argument, "kickban")) {
- argument = "1";
- } else if(!strcmp(argument, "2") || !stricmp(argument, "ban")) {
- argument = "2";
- } else {
- reply(getTextBot(), user, "NS_SET_INVALID_OPTION_STR", argument);
- return NULL;
- }
- printf_mysql_query("UPDATE `channels` SET `%s` = '%s' WHERE `channel_id` = '%d' ", mysqlfield, argument, chan->channel_id);
- return argument;
- } else {
- if(neonspam_settings_row) {
- return (neonspam_settings_row[mysqlindex] ? neonspam_settings_row[mysqlindex] : neonspam_settings_defaults[mysqlindex]);
- } else {
- MYSQL_RES *res;
- MYSQL_ROW row;
- printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_id` = '%d'", mysqlfield, chan->channel_id);
- res = mysql_use();
- row = mysql_fetch_row(res);
- return row[0];
- }
- }
-}
-
-static char* neonspam_cmd_set_reaction_time(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int mysqlindex, char *mysqlfield, char *argument, char *retBuf) {
- int duration;
- if(argument) {
- duration = strToTime(user, argument);
- if(duration < 30) {
- reply(getTextBot(), user, "NS_TIMEBAN_DURATION_TOO_SHORT", 30);
- return NULL;
- }
- printf_mysql_query("UPDATE `channels` SET `%s` = '%s' WHERE `channel_id` = '%d' ", mysqlfield, argument, chan->channel_id);
- } else {
- if(neonspam_settings_row) {
- duration = atoi(neonspam_settings_row[mysqlindex] ? neonspam_settings_row[mysqlindex] : neonspam_settings_defaults[mysqlindex]);
- } else {
- MYSQL_RES *res;
- MYSQL_ROW row;
- printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_id` = '%d'", mysqlfield, chan->channel_id);
- res = mysql_use();
- row = mysql_fetch_row(res);
- duration = atoi(row[0]);
- }
- }
- timeToStr(user, duration, 3, retBuf);
- return retBuf;
-}
-
-static char* neonspam_cmd_setpercent(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int percent_index, char *mysqlfield, char *argument, char *retBuf) {
- unsigned int value = chan->spam_settings->percent[percent_index];
- if(argument) {
- //numeric argument... (access)
- value = atoi(argument);
- if(value < 0 || value > 100) {
- //invalid percent value
- reply(getTextBot(), user, "SS_SET_PERCENT", value);
- return NULL;
- }
- chan->spam_settings->percent[percent_index] = value;
- printf_mysql_query("UPDATE `channels` SET `%s` = '%u' WHERE `channel_id` = '%d' ", mysqlfield, value, chan->channel_id);
- }
- sprintf(retBuf, "%u", value);
- return retBuf;
-}
-
-static char* neonspam_cmd_setsensibility(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int sensibility_index, char *mysqlfield, char *argument, char *retBuf) {
- if(argument) {
- //change value
- char *delimiter = strstr(argument, ":");
- if(!delimiter) {
- //invalid format
- reply(getTextBot(), user, "SS_SET_SENSIBILITY", argument);
- return NULL;
- }
- *delimiter = '\0';
- delimiter++;
- int amount = atoi(argument);
- int timep = atoi(delimiter);
- if(amount > MAX_FLOOD_AMOUNT || amount < MIN_FLOOD_AMOUNT) {
- //invalid amount
- reply(getTextBot(), user, "SS_SET_SENSIBILITY_AMOUNT", amount, MIN_FLOOD_AMOUNT, MAX_FLOOD_AMOUNT);
- return NULL;
- }
- if(timep > MAX_FLOOD_TIME || timep < 0) {
- //invalid time period
- reply(getTextBot(), user, "SS_SET_SENSIBILITY_TIME", timep, 0, MAX_FLOOD_TIME);
- return NULL;
- }
- char amountfield[50], timefield[50];
- sprintf(amountfield, "%s%s", mysqlfield, "limit");
- sprintf(timefield, "%s%s", mysqlfield, "time");
- printf_mysql_query("UPDATE `channels` SET `%s` = '%d', `%s` = '%d' WHERE `channel_id` = '%d' ", amountfield, amount, timefield, timep, chan->channel_id);
- sprintf(retBuf, "%d:%d", amount, timep);
- chan->spam_settings->sensibility_amount[sensibility_index] = amount;
- chan->spam_settings->sensibility_time[sensibility_index] = timep;
- } else {
- sprintf(retBuf, "%d:%d", chan->spam_settings->sensibility_amount[sensibility_index], chan->spam_settings->sensibility_time[sensibility_index]);
- }
- return retBuf;
-}
-
-static char* neonspam_cmd_set_spamlimit(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int intparam, char *charparam, char *argument, char *retBuf) {
- if(argument) {
- //change value
- int amount = atoi(argument);
- if(amount > 10 || amount < 2) {
- //invalid amount
- reply(getTextBot(), user, "SS_SET_SPAMLIMIT", amount, 2, 10);
- return NULL;
- }
- printf_mysql_query("UPDATE `channels` SET `channel_maxrepeat` = '%d' WHERE `channel_id` = '%d' ", amount, chan->channel_id);
- sprintf(retBuf, "%d", amount);
- chan->spam_settings->spam_amount = amount;
- } else
- sprintf(retBuf, "%d", chan->spam_settings->spam_amount);
- return retBuf;
-}
-
-static char* neonspam_cmd_setscanops(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int flag, char *charparam, char *argument, char *retBuf) {
- int i = 0;
- int value = -1;
- int identical = 1;
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANOPS) {
- if(value == -1)
- value = ((chan->spam_settings->flags & neonspam_settings[i].intparam) ? 1 : 0);
- else {
- if(((chan->spam_settings->flags & neonspam_settings[i].intparam) ? 1 : 0) != value) {
- identical = 0;
- break;
- }
- }
- }
- i++;
- }
- if(argument) {
- //binary argument...
- if(!strcmp(argument, "0") || !stricmp(argument, "off") || !stricmp(argument, get_language_string(user, "NS_SET_OFF"))) {
- value = 0;
- } else if(!strcmp(argument, "1") || !stricmp(argument, "on") || !stricmp(argument, get_language_string(user, "NS_SET_ON"))) {
- value = 1;
- } else {
- reply(getTextBot(), user, "NS_SET_INVALID_BOOLEAN", argument);
- return NULL;
- }
- i = 0;
- char valueBuf[MAXLEN];
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANOPS) {
- neonspam_cmd_set_function *func = neonspam_settings[i].function;
- func(client, user, chan, event, neonspam_settings[i].intparam, neonspam_settings[i].charparam, (value ? "1" : "0"), valueBuf);
- }
- i++;
- }
- identical = 1;
- }
- if(identical && value)
- return "1";
- if(identical && !value)
- return "0";
- return "?";
-}
-
-static char* neonspam_cmd_setscanvoice(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int flag, char *charparam, char *argument, char *retBuf) {
- int i = 0;
- int value = -1;
- int identical = 1;
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANVOICE) {
- if(value == -1)
- value = ((chan->spam_settings->flags & neonspam_settings[i].intparam) ? 1 : 0);
- else {
- if(((chan->spam_settings->flags & neonspam_settings[i].intparam) ? 1 : 0) != value) {
- identical = 0;
- break;
- }
- }
- }
- i++;
- }
- if(argument) {
- //binary argument...
- if(!strcmp(argument, "0") || !stricmp(argument, "off") || !stricmp(argument, get_language_string(user, "NS_SET_OFF"))) {
- value = 0;
- } else if(!strcmp(argument, "1") || !stricmp(argument, "on") || !stricmp(argument, get_language_string(user, "NS_SET_ON"))) {
- value = 1;
- } else {
- reply(getTextBot(), user, "NS_SET_INVALID_BOOLEAN", argument);
- return NULL;
- }
- i = 0;
- char valueBuf[MAXLEN];
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANVOICE) {
- neonspam_cmd_set_function *func = neonspam_settings[i].function;
- func(client, user, chan, event, neonspam_settings[i].intparam, neonspam_settings[i].charparam, (value ? "1" : "0"), valueBuf);
- }
- i++;
- }
- identical = 1;
- }
- if(identical && value)
- return "1";
- if(identical && !value)
- return "0";
- return "?";
-}
-
-static char* neonspam_cmd_setscanexcept(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct Event *event, int flag, char *charparam, char *argument, char *retBuf) {
- int i = 0;
- int value = -1;
- int identical = 1;
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANEXCEPT) {
- if(value == -1)
- value = chan->spam_settings->exceptlevel[neonspam_settings[i].intparam];
- else {
- if(chan->spam_settings->exceptlevel[neonspam_settings[i].intparam] != value) {
- identical = 0;
- break;
- }
- }
- }
- i++;
- }
- if(argument) {
- //numeric argument... (access)
- int caccess = atoi(argument);
- if(caccess < 0 || caccess > 501) {
- reply(getTextBot(), user, "NS_INVALID_ACCESS", caccess);
- return NULL;
- }
- int uaccess = getChannelAccess(user, chan);
- if(uaccess == 500) uaccess++;
- if(identical && value > uaccess) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_CANNOT_SET");
- return NULL;
- }
- }
- if(caccess > uaccess) {
- if(isGodMode(user)) {
- event->flags |= CMDFLAG_OPLOG;
- } else {
- reply(getTextBot(), user, "NS_SET_BADLEVEL");
- return NULL;
- }
- }
- i = 0;
- char valueBuf[MAXLEN];
- sprintf(retBuf, "%d", caccess);
- while(neonspam_settings[i].setting) {
- if(neonspam_settings[i].flags & SET_SCANEXCEPT) {
- neonspam_cmd_set_function *func = neonspam_settings[i].function;
- func(client, user, chan, event, neonspam_settings[i].intparam, neonspam_settings[i].charparam, retBuf, valueBuf);
- }
- i++;
- }
- identical = 1;
- value = caccess;
- }
- if(identical) {
- sprintf(retBuf, "%d", value);
- return retBuf;
- }
- return "?";
-}
-
-#undef MAX_QUERY_LEN