+ if(action != SPAMSERV_CHECK_IGNORE) {
+ //whois the user to check against exceptlevel
+ if((user->flags & USERFLAG_ISAUTHED) || settings->exceptlevel == 501) {
+ neonspam_event_chanmsg_punish(client, chanuser, settings, action, reason, reaction);
+ } 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->action = action;
+ cache->reason = strdup(reason);
+ cache->reaction = reaction;
+ get_userauth(user, neonspam_event_chanmsg_nick_lookup, cache);
+ }
+
+ }
+}
+
+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->action, cache->reason, cache->reaction);
+ free(cache->reason);
+ free(cache);
+}
+
+static void neonspam_event_chanmsg_punish(struct ClientSocket *client, struct ChanUser *chanuser, struct NeonSpamSettings *settings, int action, char *reason, char *reaction) {
+ int uaccess = 0;
+ if(chanuser->user->flags & USERFLAG_ISAUTHED)
+ uaccess = getChannelAccess(chanuser->user, chanuser->chan, 0);
+ if(uaccess >= settings->exceptlevel) return;
+ 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);
+ int duration = 0;
+ char banmaskBuf[NICKLEN+USERLEN+HOSTLEN+3];
+ char *banmask = NULL;
+ switch (atoi(row[0])) {
+ case 2: //TIMEBAN: 3min
+ duration = 180;
+ 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));
+ case 1: //KICKBAN
+ if(!banmask)
+ banmask = generate_banmask(chanuser->user, banmaskBuf);
+ putsock(client, "MODE %s +b %s", chanuser->chan->name, banmask);
+ case 0: //KICK
+ putsock(client, "KICK %s %s :%s", chanuser->chan->name, chanuser->user->nick, reason);
+ break;
+ }
+ }