X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fevent_neonspam_join.c;h=1578a0154ec551d82367749ad631cc7f62288f33;hb=c575e458c6257e75b97884847143b20965a5dfda;hp=b443ef33187d5a914886862c10286b065b34747a;hpb=960872d9d1679c3329e9ff8369efa02ef6c81c3b;p=NeonServV5.git diff --git a/src/event_neonspam_join.c b/src/event_neonspam_join.c index b443ef3..1578a01 100644 --- a/src/event_neonspam_join.c +++ b/src/event_neonspam_join.c @@ -1,4 +1,4 @@ -/* event_neonspam_join.c - NeonServ v5.1 +/* event_neonspam_join.c - NeonServ v5.2 * Copyright (C) 2011 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ */ static USERAUTH_CALLBACK(neonspam_event_join_nick_lookup); -static void neonspam_event_join_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, int action, char *reason, char *reaction); +static void neonspam_event_join_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, int action); static int neonspam_joinfloodscan(struct NeonSpamSettings *settings, struct ChanUser *chanuser); struct neonspam_event_join_cache { @@ -24,8 +24,6 @@ struct neonspam_event_join_cache { struct ChanUser *chanuser; struct NeonSpamSettings *settings; int action; - char *reason; - char *reaction; }; static void neonspam_event_join(struct ChanUser *chanuser) { @@ -33,38 +31,13 @@ static void neonspam_event_join(struct ChanUser *chanuser) { if(!client) return; //we can't "see" this event loadNeonSpamSettings(chanuser->chan); struct NeonSpamSettings *settings = chanuser->chan->spam_settings; - if(!settings) return; - if(settings->exceptlevel == 0) return; - //scan the message - int result = 0; - int action = SPAMSERV_CHECK_IGNORE; - char reason[MAXLEN]; - char *reaction = NULL; - if(action != SPAMSERV_CHECK_PUNISH && (settings->flags & SPAMSETTINGS_JOINSCAN)) { - result = neonspam_joinfloodscan(settings, chanuser); - switch(result) { - case SPAMSERV_CHECK_IGNORE: - break; - case SPAMSERV_CHECK_WARN: - if(action == SPAMSERV_CHECK_IGNORE) { - action = result; - sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_JOINFLOOD); - } - break; - case SPAMSERV_CHECK_PUNISH: - if(action != SPAMSERV_CHECK_PUNISH) { - action = result; - sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_JOINFLOOD); - reaction = "channel_joinreaction"; - } - break; - } - } - //some other checks? - if(action != SPAMSERV_CHECK_IGNORE) { + if(!settings || !(settings->flags & SPAMSETTINGS_JOINSCAN)) return; + if(settings->exceptlevel[SPAMSETTINGS_JOINEXCINDEX] == 0) return; + int result = neonspam_joinfloodscan(settings, chanuser); + if(result != SPAMSERV_CHECK_IGNORE) { //whois the user to check against exceptlevel - if((chanuser->user->flags & USERFLAG_ISAUTHED) || settings->exceptlevel == 501) { - neonspam_event_join_punish(client, chanuser, settings, action, reason, reaction); + if((chanuser->user->flags & USERFLAG_ISAUTHED) || settings->exceptlevel[SPAMSETTINGS_JOINEXCINDEX] == 501) { + neonspam_event_join_punish(client, chanuser, settings, result); } else { struct neonspam_event_join_cache *cache = malloc(sizeof(*cache)); if (!cache) { @@ -74,58 +47,57 @@ static void neonspam_event_join(struct ChanUser *chanuser) { cache->client = client; cache->chanuser = chanuser; cache->settings = settings; - cache->action = action; - cache->reason = strdup(reason); - cache->reaction = reaction; + cache->action = result; get_userauth(chanuser->user, neonspam_event_join_nick_lookup, cache); } - } } static USERAUTH_CALLBACK(neonspam_event_join_nick_lookup) { struct neonspam_event_join_cache *cache = data; - neonspam_event_join_punish(cache->client, cache->chanuser, cache->settings, cache->action, cache->reason, cache->reaction); - free(cache->reason); + neonspam_event_join_punish(cache->client, cache->chanuser, cache->settings, cache->action); free(cache); } -static void neonspam_event_join_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, int action, char *reason, char *reaction) { +static void neonspam_event_join_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, int action) { int uaccess = 0; if(chanuser->user->flags & USERFLAG_ISAUTHED) uaccess = getChannelAccess(chanuser->user, chanuser->chan, 0); - if(uaccess >= settings->exceptlevel) return; + if(uaccess >= settings->exceptlevel[SPAMSETTINGS_JOINEXCINDEX]) return; + //scanops / scanvoiced + MYSQL_RES *res; + MYSQL_ROW row, defaults = NULL; + loadChannelSettings(chanuser->chan); + printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration`, `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_id` = '%d'", chanuser->chan->channel_id); + res = mysql_use(); + row = mysql_fetch_row(res); + if(!row[0] || !row[1] || !row[2] || !row[3]) { + printf_mysql_query("SELECT `channel_flood_reaction`, `channel_flood_reaction_duration`, `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_name` = 'defaults'"); + res = mysql_use(); + defaults = mysql_fetch_row(res); + } + if(!(settings->flags & SPAMSETTINGS_JOINSCAN_OPS) && uaccess >= atoi((row[2] ? row[2] : defaults[2]))) return; + if(!(settings->flags & SPAMSETTINGS_JOINSCAN_VOICE) && uaccess >= atoi((row[3] ? row[3] : defaults[3]))) return; + char reason[MAXLEN]; + sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_JOINFLOOD); if(action == SPAMSERV_CHECK_WARN) { reply(client, chanuser->user, "%s", reason); } else if(action == SPAMSERV_CHECK_PUNISH) { - MYSQL_RES *res; - MYSQL_ROW row; - loadChannelSettings(chanuser->chan); - printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_id` = '%d'", reaction, chanuser->chan->channel_id); - res = mysql_use(); - row = mysql_fetch_row(res); - if(!row[0]) { - printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_name` = 'defaults'", reaction); - res = mysql_use(); - row = mysql_fetch_row(res); - } - int duration = 0; + int duration = atoi((row[1] ? row[1] : defaults[1])); char banmaskBuf[NICKLEN+USERLEN+HOSTLEN+3]; char *banmask = NULL; - switch (atoi(row[0])) { - case 2: //TIMEBAN: 3min - duration = 180; + switch (atoi((row[0] ? row[0] : defaults[0]))) { case 3: //TIMEBAN: 1h - if(!duration) - duration = 3600; 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) (time(0) + duration), 0, escape_string(reason)); - int banid = (int) mysql_insert_id(mysql_conn); - char nameBuf[MAXLEN]; - char banidBuf[20]; - sprintf(nameBuf, "ban_%d", banid); - sprintf(banidBuf, "%d", banid); - timeq_add_name(nameBuf, duration, channel_ban_timeout, strdup(banidBuf)); + 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) (duration ? (time(0) + duration) : 0), 0, escape_string(reason)); + if(duration) { + int banid = (int) mysql_insert_id(mysql_conn); + char nameBuf[MAXLEN]; + char banidBuf[20]; + sprintf(nameBuf, "ban_%d", banid); + sprintf(banidBuf, "%d", banid); + timeq_add_name(nameBuf, duration, channel_ban_timeout, strdup(banidBuf)); + } case 1: //KICKBAN if(!banmask) banmask = generate_banmask(chanuser->user, banmaskBuf); @@ -141,7 +113,7 @@ static int neonspam_update_join_penalty(struct NeonSpamSettings *settings, struc int last_update = time(0) - joinnode->last_penalty_update; if(last_update) { if(last_update < MAX_JOIN_TIME && joinnode->joinpenalty) { - joinnode->joinpenalty -= last_update * (MAX_JOIN_TIME / settings->join_time); + joinnode->joinpenalty -= last_update * (MAX_JOIN_TIME / settings->sensibility_time[SPAMSETTINGS_JOINSENINDEX]); if(joinnode->joinpenalty < 0) joinnode->joinpenalty = 0; } else @@ -156,9 +128,9 @@ static int neonspam_joinfloodscan(struct NeonSpamSettings *settings, struct Chan if(!chanuser->spamnode) createSpamNode(chanuser); int joins_pending = neonspam_update_join_penalty(settings, getNeonSpamJoinNode(chanuser), 1); - if(joins_pending == settings->join_amount) + if(joins_pending == settings->sensibility_amount[SPAMSETTINGS_JOINSENINDEX]) return SPAMSERV_CHECK_WARN; - else if(joins_pending > settings->join_amount) + else if(joins_pending > settings->sensibility_amount[SPAMSETTINGS_JOINSENINDEX]) return SPAMSERV_CHECK_PUNISH; else return SPAMSERV_CHECK_IGNORE;