+ if(warn || punish) {
+ //whois the user to check against exceptlevel
+ if(!needwho || (user->flags & USERFLAG_ISAUTHED)) {
+ neonspam_event_chanmsg_punish(client, chanuser, settings, warn, punish);
+ } else {
+ struct neonspam_event_chanmsg_cache *cache = malloc(sizeof(*cache));
+ if (!cache) {
+ perror("malloc() failed");
+ return;
+ }
+ cache->client = client;
+ cache->chanuser = chanuser;
+ cache->settings = settings;
+ cache->warn = warn;
+ cache->punish = punish;
+ get_userauth(user, neonspam_event_chanmsg_nick_lookup, cache);
+ }
+
+ }
+ #undef NEONSPAM_CHANMSG_DO_SCANOPS
+ #undef NEONSPAM_CHANMSG_DO_SCANVOICE
+ #undef NEONSPAM_CHANMSG_DO_EXCEPT
+ #undef NEONSPAM_CHANMSG_NEED_WHO
+}
+
+static USERAUTH_CALLBACK(neonspam_event_chanmsg_nick_lookup) {
+ struct neonspam_event_chanmsg_cache *cache = data;
+ neonspam_event_chanmsg_punish(cache->client, cache->chanuser, cache->settings, cache->warn, cache->punish);
+ free(cache);
+}
+
+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;
+ loadChannelSettings(chanuser->chan);
+ int uaccess = 0;
+ if(chanuser->user->flags & USERFLAG_ISAUTHED)
+ uaccess = getChannelAccess(chanuser->user, chanuser->chan, 0);
+ char reason[MAXLEN];
+ reason[0] = '\0';
+ int punishment = 0;
+ int punish_time = 0;
+ if(!punishment && (punish & SPAMSETTINGS_SPAMSCAN) && settings->exceptlevel[SPAMSETTINGS_SPAMEXCINDEX] > uaccess) {
+ 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]) {
+ 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);
+ }
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM);
+ punishment = atoi(row[0]) + 1;
+ punish_time = atoi(row[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]) {
+ 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);
+ }
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_FLOOD);
+ punishment = atoi(row[0]) + 1;
+ punish_time = atoi(row[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]) {
+ 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);
+ }
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_CAPS);
+ punishment = atoi(row[0]) + 1;
+ punish_time = atoi(row[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]) {
+ 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);
+ }
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_DIGIT);
+ punishment = atoi(row[0]) + 1;
+ punish_time = atoi(row[1]);
+ }
+ if(!punishment && (warn & SPAMSETTINGS_SPAMSCAN) && settings->exceptlevel[SPAMSETTINGS_SPAMEXCINDEX] > uaccess) {
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_SPAM);
+ }
+ if(!punishment && (warn & SPAMSETTINGS_FLOODSCAN) && settings->exceptlevel[SPAMSETTINGS_FLOODEXCINDEX] > uaccess) {
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_FLOOD);
+ }
+ if(!punishment && (warn & SPAMSETTINGS_CAPSSCAN) && settings->exceptlevel[SPAMSETTINGS_CAPSEXCINDEX] > uaccess) {
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_CAPS);
+ }
+ if(!punishment && (warn & SPAMSETTINGS_DIGITSCAN) && settings->exceptlevel[SPAMSETTINGS_DIGITEXCINDEX] > uaccess) {
+ sprintf(reason, SPAMSERV_MSG_WARNING, SPAMSERV_MSG_DIGIT);
+ }
+ if(punishment) {
+ char banmaskBuf[NICKLEN+USERLEN+HOSTLEN+3];
+ char *banmask = NULL;
+ switch (punishment) {
+ case 3: //TIMEBAN: 1h
+ 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);
+ char nameBuf[MAXLEN];
+ char banidBuf[20];
+ sprintf(nameBuf, "ban_%d", banid);
+ sprintf(banidBuf, "%d", banid);
+ timeq_add_name(nameBuf, punish_time, channel_ban_timeout, strdup(banidBuf));
+ }
+ case 2: //KICKBAN
+ if(!banmask)
+ banmask = generate_banmask(chanuser->user, banmaskBuf);
+ putsock(client, "MODE %s +b %s", chanuser->chan->name, banmask);
+ case 1: //KICK
+ putsock(client, "KICK %s %s :%s", chanuser->chan->name, chanuser->user->nick, reason);
+ break;
+ }
+ } else if(*reason)
+ reply(client, chanuser->user, "%s", reason);