X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fevent_neonspam_chanmsg.c;h=163315db30fd03e13c096403d1b3fab85faa9b29;hb=b53d0c5f88063f075a48a0426f9d5d6b3490b9fc;hp=2d2978ba349181c58d7ec5a9bd13e55f392c0b21;hpb=c575e458c6257e75b97884847143b20965a5dfda;p=NeonServV5.git diff --git a/src/event_neonspam_chanmsg.c b/src/event_neonspam_chanmsg.c index 2d2978b..163315d 100644 --- a/src/event_neonspam_chanmsg.c +++ b/src/event_neonspam_chanmsg.c @@ -1,5 +1,5 @@ -/* event_neonspam_chanmsg.c - NeonServ v5.2 - * Copyright (C) 2011 Philipp Kreil (pk910) +/* event_neonspam_chanmsg.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 @@ -36,7 +36,7 @@ struct neonspam_event_chanmsg_cache { static void neonspam_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) { struct ClientSocket *client = getChannelBot(chan, BOTID); - if(!client) return; //we can't "see" this event + if(!client || (user->flags & USERFLAG_ISBOT)) return; //we can't "see" this event loadNeonSpamSettings(chan); struct NeonSpamSettings *settings = chan->spam_settings; struct ChanUser *chanuser = getChanUser(user, chan); @@ -162,11 +162,11 @@ static USERAUTH_CALLBACK(neonspam_event_chanmsg_nick_lookup) { static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, unsigned int warn, unsigned int punish) { MYSQL_RES *res; - MYSQL_ROW row; + MYSQL_ROW row, defaults; loadChannelSettings(chanuser->chan); int uaccess = 0; if(chanuser->user->flags & USERFLAG_ISAUTHED) - uaccess = getChannelAccess(chanuser->user, chanuser->chan, 0); + uaccess = getChannelAccess(chanuser->user, chanuser->chan); char reason[MAXLEN]; reason[0] = '\0'; int punishment = 0; @@ -175,53 +175,53 @@ static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct Ch printf_mysql_query("SELECT `channel_spam_reaction`, `channel_spam_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id); res = mysql_use(); row = mysql_fetch_row(res); - if(!row[0]) { + if(!row[0] || !row[1]) { printf_mysql_query("SELECT `channel_spam_reaction`, `channel_spam_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'"); res = mysql_use(); - row = mysql_fetch_row(res); + defaults = mysql_fetch_row(res); } sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM); - punishment = atoi(row[0]) + 1; - punish_time = atoi(row[1]); + punishment = atoi((row[0] ? row[0] : defaults[0])) + 1; + punish_time = atoi((row[1] ? row[1] : defaults[1])); } if(!punishment && (punish & SPAMSETTINGS_FLOODSCAN) && settings->exceptlevel[SPAMSETTINGS_FLOODEXCINDEX] > uaccess) { printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id); res = mysql_use(); row = mysql_fetch_row(res); - if(!row[0]) { + if(!row[0] || !row[1]) { printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'"); res = mysql_use(); - row = mysql_fetch_row(res); + defaults = mysql_fetch_row(res); } sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_FLOOD); - punishment = atoi(row[0]) + 1; - punish_time = atoi(row[1]); + punishment = atoi((row[0] ? row[0] : defaults[0])) + 1; + punish_time = atoi((row[1] ? row[1] : defaults[1])); } if(!punishment && (punish & SPAMSETTINGS_CAPSSCAN) && settings->exceptlevel[SPAMSETTINGS_CAPSEXCINDEX] > uaccess) { printf_mysql_query("SELECT `channel_caps_reaction`, `channel_caps_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id); res = mysql_use(); row = mysql_fetch_row(res); - if(!row[0]) { + if(!row[0] || !row[1]) { printf_mysql_query("SELECT `channel_caps_reaction`, `channel_caps_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'"); res = mysql_use(); - row = mysql_fetch_row(res); + defaults = mysql_fetch_row(res); } sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_CAPS); - punishment = atoi(row[0]) + 1; - punish_time = atoi(row[1]); + punishment = atoi((row[0] ? row[0] : defaults[0])) + 1; + punish_time = atoi((row[1] ? row[1] : defaults[1])); } if(!punishment && (punish & SPAMSETTINGS_DIGITSCAN) && settings->exceptlevel[SPAMSETTINGS_DIGITEXCINDEX] > uaccess) { printf_mysql_query("SELECT `channel_digit_reaction`, `channel_digit_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id); res = mysql_use(); row = mysql_fetch_row(res); - if(!row[0]) { + if(!row[0] || !row[1]) { printf_mysql_query("SELECT `channel_digit_reaction`, `channel_digit_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'"); res = mysql_use(); - row = mysql_fetch_row(res); + defaults = mysql_fetch_row(res); } sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_DIGIT); - punishment = atoi(row[0]) + 1; - punish_time = atoi(row[1]); + punishment = atoi((row[0] ? row[0] : defaults[0])) + 1; + punish_time = atoi((row[1] ? row[1] : defaults[1])); } if(!punishment && (warn & SPAMSETTINGS_SPAMSCAN) && settings->exceptlevel[SPAMSETTINGS_SPAMEXCINDEX] > uaccess) { sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM); @@ -239,11 +239,11 @@ static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct Ch char banmaskBuf[NICKLEN+USERLEN+HOSTLEN+3]; char *banmask = NULL; switch (punishment) { - case 3: //TIMEBAN: 1h + case 3: //TIMEBAN banmask = generate_banmask(chanuser->user, banmaskBuf); printf_mysql_query("INSERT INTO `bans` (`ban_channel`, `ban_mask`, `ban_triggered`, `ban_timeout`, `ban_owner`, `ban_reason`) VALUES ('%d', '%s', UNIX_TIMESTAMP(), '%lu', '%d', '%s')", chanuser->chan->channel_id, escape_string(banmask), (unsigned long) (punish_time ? (time(0) + punish_time) : 0), 0, escape_string(reason)); if(punish_time) { - int banid = (int) mysql_insert_id(mysql_conn); + int banid = (int) mysql_insert_id(get_mysql_conn()); char nameBuf[MAXLEN]; char banidBuf[20]; sprintf(nameBuf, "ban_%d", banid);