*** VERSION 5.2.0 ***
[NeonServV5.git] / src / bot_NeonSpam.c
index 5a200c1f3dd5ef7d8f1b93e787fe214bf93424dd..8463d430697772f955748d0a1c1215aad54ac0d0 100644 (file)
@@ -1,4 +1,4 @@
-/* bot_NeonSpam.c - NeonServ v5.1
+/* bot_NeonSpam.c - NeonServ v5.2
  * Copyright (C) 2011  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
 #define BOTID 2
 
 static const struct default_language_entry msgtab[] = {
+    {"SS_SET_PERCENT", "%u is an invalid percent value (valid: 0-100)"},
+    {"SS_SET_SENSIBILITY", "%s is an invalid sensibility format. (valid: amount:time   e.g. 5:10)"},
+    {"SS_SET_SENSIBILITY_AMOUNT", "%d is an invalid amount value. (valid: %d-%d)"},
+    {"SS_SET_SENSIBILITY_TIME", "%d is an invalid time value. (valid: %d-%d)"},
+    {"SS_SET_SPAMLIMIT", "%d is an invalid spamlimit value. (valid: %d-%d)"},
+    {"SS_SET_OPTION_SpamReaction_0", "Kick"},
+    {"SS_SET_OPTION_SpamReaction_1", "KickBan"},
+    {"SS_SET_OPTION_SpamReaction_2", "Timed Ban"},
+    {"SS_SET_OPTION_FloodReaction_0", "Kick"},
+    {"SS_SET_OPTION_FloodReaction_1", "KickBan"},
+    {"SS_SET_OPTION_FloodReaction_2", "Timed Ban"},
+    {"SS_SET_OPTION_JoinReaction_0", "Kick"},
+    {"SS_SET_OPTION_JoinReaction_1", "KickBan"},
+    {"SS_SET_OPTION_JoinReaction_2", "Timed Ban"},
+    {"SS_SET_OPTION_CapsReaction_0", "Kick"},
+    {"SS_SET_OPTION_CapsReaction_1", "KickBan"},
+    {"SS_SET_OPTION_CapsReaction_2", "Timed Ban"},
+    {"SS_SET_OPTION_DigitReaction_0", "Kick"},
+    {"SS_SET_OPTION_DigitReaction_1", "KickBan"},
+    {"SS_SET_OPTION_DigitReaction_2", "Timed Ban"},
     {NULL, NULL}
 };
 
+static unsigned int convertNeonSpamSettingsToFlags(char *str);
 static int loadNeonSpamSettings(struct ChanNode *chan);
 static void createSpamNode(struct ChanUser *chanuser);
 static void freeJoinNode(struct NeonSpamJoinNode *joinnode);
@@ -52,12 +73,16 @@ static struct NeonSpamJoinNode *getNeonSpamJoinNode(struct ChanUser *chanuser);
 #define SPAMSERV_CHECK_IGNORE 0
 #define SPAMSERV_CHECK_WARN   1
 #define SPAMSERV_CHECK_PUNISH 2
+#define SPAMSERV_CHECK_DEAD   3 /* scanner has already killed the user */
 
 #define SPAMSERV_MSG_SPAM       "Spamming"
 #define SPAMSERV_MSG_FLOOD      "Flooding the channel/network"
 #define SPAMSERV_MSG_ADV        "Advertising"
 #define SPAMSERV_MSG_JOINFLOOD  "Join flooding the channel"
 #define SPAMSERV_MSG_WARNING    "%s is against the channel rules"
+#define SPAMSERV_MSG_BOTNET     "BotNet detected."
+#define SPAMSERV_MSG_CAPS       "Using too many chars in UPPER CASE"
+#define SPAMSERV_MSG_DIGIT      "Using too many numeric chars"
 
 //EVENTS
 #include "event_neonspam_join.c"
@@ -97,7 +122,7 @@ static void start_bots() {
     MYSQL_RES *res, *res2;
     MYSQL_ROW row;
     
-    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
+    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
@@ -108,6 +133,7 @@ static void start_bots() {
         user->flags |= USERFLAG_ISBOT;
         client = create_socket(row[3], atoi(row[4]), row[5], user);
         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
+        client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
         client->botid = BOTID;
         client->clientid = atoi(row[7]);
         connect_socket(client);
@@ -129,6 +155,39 @@ static void start_bots() {
     }
 }
 
+char* convertNeonSpamSettingsToString(unsigned int flags, char *buffer) {
+    int pos = 0;
+    unsigned int i;
+    int j = 0;
+    char *chars = SPAMSETTINGS_CHARS;
+    for(i = 1; i <= SPAMSETTINGS_FLAGS; i = i << 1) {
+        if(flags & i)
+            buffer[pos++] = chars[j];
+        j++;
+    }
+    buffer[pos] = '\0';
+    return buffer;
+}
+
+static unsigned int convertNeonSpamSettingsToFlags(char *str) {
+    unsigned int i = 1, flags = 0;
+    int j = 0;
+    char *chars = SPAMSETTINGS_CHARS;
+    while(*str) {
+        for(; i <= SPAMSETTINGS_FLAGS; i = i << 1) {
+            if(*str == chars[j]) {
+                flags |= i;
+                j++;
+                i = i << 1;
+                break;
+            }
+            j++;
+        }
+        str++;
+    }
+    return flags;
+}
+
 static int loadNeonSpamSettings(struct ChanNode *chan) {
     if(chan->spam_settings) return 0;
     struct NeonSpamSettings *settings = malloc(sizeof(*settings));
@@ -139,22 +198,32 @@ static int loadNeonSpamSettings(struct ChanNode *chan) {
     MYSQL_RES *res;
     MYSQL_ROW row, defaults = NULL;
     loadChannelSettings(chan);
-    printf_mysql_query("SELECT `channel_scanstate`, `channel_maxrepeat`, `channel_maxflood`, `channel_floodtime`, `channel_maxjoin`, `channel_jointime`, `channel_scanexcept` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
+    printf_mysql_query("SELECT `channel_scanner`, `channel_spam_limit`, `channel_spam_except`, `channel_flood_limit`, `channel_flood_time`, `channel_flood_except`, `channel_join_limit`, `channel_join_time`, `channel_join_except`, `channel_caps_percent`, `channel_caps_except`, `channel_digit_percent`, `channel_digit_except` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
     res = mysql_use();
     row = mysql_fetch_row(res);
-    if(!row[0] || !row[1] || !row[2] || !row[3] || !row[4] || !row[5]) {
-        printf_mysql_query("SELECT `channel_scanstate`, `channel_maxrepeat`, `channel_maxflood`, `channel_floodtime`, `channel_maxjoin`, `channel_jointime`, `channel_scanexcept` FROM `channels` WHERE `channel_name` = 'defaults'");
+    if(!row[0] || !row[1] || !row[2] || !row[3] || !row[4] || !row[5] || !row[6] || !row[7] || !row[8] || !row[9] || !row[10] || !row[11] || !row[12]) {
+        printf_mysql_query("SELECT `channel_scanner`, `channel_spam_limit`, `channel_spam_except`, `channel_flood_limit`, `channel_flood_time`, `channel_flood_except`, `channel_join_limit`, `channel_join_time`, `channel_join_except`, `channel_caps_percent`, `channel_caps_except`, `channel_digit_percent`, `channel_digit_except` FROM `channels` WHERE `channel_name` = 'defaults'");
         res = mysql_use();
         defaults = mysql_fetch_row(res);
     }
-    settings->flags = atoi(row[0] ? row[0] : defaults[0]);
+    settings->flags = convertNeonSpamSettingsToFlags(row[0] ? row[0] : defaults[0]);
     settings->spam_amount = atoi(row[1] ? row[1] : defaults[1]);
-    settings->flood_amount = atoi(row[2] ? row[2] : defaults[2]);
-    settings->flood_time = atoi(row[3] ? row[3] : defaults[3]);
-    settings->join_amount = atoi(row[4] ? row[4] : defaults[4]);
-    settings->join_time = atoi(row[5] ? row[5] : defaults[5]);
-    settings->exceptlevel = atoi(row[6] ? row[6] : defaults[6]);
+    settings->exceptlevel[SPAMSETTINGS_SPAMEXCINDEX] = atoi(row[2] ? row[2] : defaults[2]);
+    settings->sensibility_amount[SPAMSETTINGS_FLOODSENINDEX] = atoi(row[3] ? row[3] : defaults[3]);
+    settings->sensibility_time[SPAMSETTINGS_FLOODSENINDEX] = atoi(row[4] ? row[4] : defaults[4]);
+    settings->exceptlevel[SPAMSETTINGS_FLOODEXCINDEX] = atoi(row[5] ? row[5] : defaults[5]);
+    settings->sensibility_amount[SPAMSETTINGS_JOINSENINDEX] = atoi(row[6] ? row[6] : defaults[6]);
+    settings->sensibility_time[SPAMSETTINGS_JOINSENINDEX] = atoi(row[7] ? row[7] : defaults[7]);
+    settings->exceptlevel[SPAMSETTINGS_JOINEXCINDEX] = atoi(row[8] ? row[8] : defaults[8]);
+    settings->percent[SPAMSETTINGS_CAPSPERCENTINDEX] = atoi(row[9] ? row[9] : defaults[9]);
+    settings->exceptlevel[SPAMSETTINGS_CAPSEXCINDEX] = atoi(row[10] ? row[10] : defaults[10]);
+    settings->percent[SPAMSETTINGS_DIGITPERCENTINDEX] = atoi(row[11] ? row[11] : defaults[11]);
+    settings->exceptlevel[SPAMSETTINGS_DIGITEXCINDEX] = atoi(row[12] ? row[12] : defaults[12]);
     settings->join_nodes = NULL;
+    settings->lastmsg_time = 0;
+    int i;
+    for(i = 0; i < BOTNETSCAN_USERS; i++) 
+        settings->botnicks[i] = NULL;
     chan->spam_settings = settings;
     return 1;
 }