]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hlamer.c
CHANSERV: fix issue where chanserv_relay doesn't wait for db to be loaded before...
[irc/quakenet/newserv.git] / helpmod2 / hlamer.c
index 0e0b6ff09891b4d72e330c7d13783bd75d96b26f..7df076541ee4a7ff29a38bd8f64baaf8078a4b99 100644 (file)
@@ -2,8 +2,6 @@
 #include <ctype.h>
 #include <stdlib.h>
 
-#include "../nick/nick.h"
-
 #include "huser.h"
 #include "hban.h"
 #include "hchannel.h"
@@ -62,81 +60,40 @@ hlc_profile *hlc_get(const char *str)
     return NULL;
 }
 
+const char *hlc_get_cname(hlc_component comp)
+{
+    switch (comp)
+    {
+    default:
+        return "Error, contact strutsi";
+    }
+}
+
 /* static functions, used internally */
 
 static int hlc_violation_handle(hchannel *hchan, huser* husr, int violation)
 {
-        if (husr->lc[violation] >= hchan->lc_profile->tolerance_remove) /* get rid of the thing */
-        {
-            const char *banmask = hban_ban_string(husr->real_user, HBAN_HOST);
-
-            switch (violation)
-            {
-            case HLC_CAPS:
-                hban_add(banmask, "Excessive use of capital letters", time(NULL) + HLC_DEFAULT_BANTIME, 0);
-                break;
-            case HLC_REPEAT:
-                hban_add(banmask, "Excessive repeating", time(NULL) + HLC_DEFAULT_BANTIME, 0);
-                break;
-            case HLC_CHARACTER_REPEAT:
-                hban_add(banmask, "Excessive improper use of language", time(NULL) + HLC_DEFAULT_BANTIME, 0);
-                break;
-            case HLC_FLOOD:
-                hban_add(banmask, "Excessive flooding", time(NULL) + HLC_DEFAULT_BANTIME, 0);
-                break;
-            case HLC_SPAM:
-                hban_add(banmask, "Excessive spamming", time(NULL) + HLC_DEFAULT_BANTIME, 0);
-                break;
-            }
-
-            if (IsAccount(husr->real_user))
-                haccount_add(husr->real_user->authname, H_LAMER);
-
-            return !0;
-        }
-        if (husr->lc[violation] >= hchan->lc_profile->tolerance_kick) /* get rid of the thing */
-        {
-            switch (violation)
-            {
-            case HLC_CAPS:
-                helpmod_kick(hchan, husr, "channel rule violation: Excessive use of capital letters");
-                break;
-            case HLC_REPEAT:
-                helpmod_kick(hchan, husr, "channel rule violation: Repeating");
-                break;
-            case HLC_CHARACTER_REPEAT:
-                helpmod_kick(hchan, husr, "channel rule violation: Improper use of language");
-                break;
-            case HLC_FLOOD:
-                helpmod_kick(hchan, husr, "channel rule violation: Flooding");
-                break;
-            case HLC_SPAM:
-                helpmod_kick(hchan, husr, "channel rule violation: Spamming");
-                break;
-            }
-            return !0;
-        }
-        if (husr->lc[violation] >= hchan->lc_profile->tolerance_warn) /* get rid of the thing */
-        {
-            switch (violation)
-            {
-            case HLC_CAPS:
-                helpmod_reply(husr, hchan->real_channel, "You are violating the channel rule of %s : Excessive use of capital letters", hchannel_get_name(hchan));
-                break;
-            case HLC_REPEAT:
-                helpmod_reply(husr, hchan->real_channel, "You are violating the channel rule of %s : Repeating", hchannel_get_name(hchan));
-                break;
-            case HLC_CHARACTER_REPEAT:
-                helpmod_reply(husr, hchan->real_channel, "You are violating the channel rule of %s : Improper use of language", hchannel_get_name(hchan));
-                break;
-            case HLC_FLOOD:
-                helpmod_reply(husr, hchan->real_channel, "You are violating the channel rule of %s : Flooding", hchannel_get_name(hchan));
-                break;
-            case HLC_SPAM:
-                helpmod_reply(husr, hchan->real_channel, "You are violating the channel rule of %s : Spamming", hchannel_get_name(hchan));
-                break;
-            }
-        }
+    if (husr->lc[violation] >= hchan->lc_profile->tolerance_remove) /* get rid of the thing */
+    {
+       const char *banmask = hban_ban_string(husr->real_user, HBAN_HOST);
+       char reason_buffer[128];
+        sprintf(reason_buffer, "Excessive violations: %s", hlc_get_violation_name(violation));
+       hban_add(banmask, reason_buffer, time(NULL) + HLC_DEFAULT_BANTIME, 0);
+
+       if (IsAccount(husr->real_user))
+           haccount_add(huser_get_auth(husr), H_LAMER);
+
+       return !0;
+    }
+    if (husr->lc[violation] >= hchan->lc_profile->tolerance_kick) /* get rid of the thing */
+    {
+       helpmod_kick(hchan, husr, "Channel rule violation: %s", hlc_get_violation_name(violation));
+       return !0;
+    }
+    if (husr->lc[violation] >= hchan->lc_profile->tolerance_warn) /* get rid of the thing */
+    {
+       helpmod_reply(husr, NULL, "You are violating the channel rule of %s : %s. Continuous violation of this rule will result in you being removed from %s", hchannel_get_name(hchan), hlc_get_violation_name(violation), hchannel_get_name(hchan));
+    }
     return 0;
 
 }
@@ -146,6 +103,26 @@ static int hlc_check_caps(hlc_profile *hlc_prof, huser *husr, const char *line)
     int caps = 0;
     int noncaps = 0;
     int i;
+    int firstword;
+
+    if (strchr(line, ' '))
+       firstword = strchr(line, ' ') - line;
+    else
+        firstword = 0;
+
+    /* Handle the thing sent with /me */
+    if (!strncmp(line, "\1ACTION", 6 + 1))
+       line+=(6 + 1);
+    else if (firstword && firstword < NICKLEN + 3)
+    {
+       char buffer[NICKLEN + 3];
+       strncpy(buffer, line, firstword);
+       buffer[firstword] = '\0';
+       if (buffer[firstword - 1] == ':')
+           buffer[firstword - 1] = '\0';
+       if (getnickbynick(buffer))
+            line+=firstword + 1;
+    }
 
     for (i = 0;line[i];i++)
     {
@@ -173,6 +150,8 @@ static int hlc_check_repeat(hlc_profile *hlc_prof, huser *husr, const char *line
 {
     if (!strncmp(husr->last_line, line, strlen(husr->last_line)) && (strlen(husr->last_line) >= hlc_prof->repeats_min_length))
         husr->last_line_repeats++;
+    else if (!strcmp(husr->last_line, line))
+        husr->last_line_repeats++;
     else
         husr->last_line_repeats = 0;
 
@@ -188,7 +167,7 @@ static int hlc_check_character_repeats(hlc_profile *hlc_prof, huser *husr, const
 {
     char chr = '\0';
     int i;
-    int repeats;
+    int repeats = 0;
 
     for (i = 0;line[i];i++)
         if (line[i] == chr)
@@ -224,7 +203,7 @@ static int hlc_check_flood(hlc_profile *hlc_prof, huser *husr, const char *line)
     else
         husr->flood_val++;
 
-    if ((husr->flood_val - time(NULL)) >= (hlc_prof->tolerance_flood))
+    if ((husr->flood_val - time(NULL)) > (hlc_prof->tolerance_flood))
     {
         husr->flood_val = time(NULL);
         return ++husr->lc[HLC_FLOOD];
@@ -235,12 +214,12 @@ static int hlc_check_flood(hlc_profile *hlc_prof, huser *husr, const char *line)
 
 static int hlc_check_spam(hlc_profile *hlc_prof, huser *husr, const char *line)
 {
-    if (husr->spam_val < (float)time(NULL))
-        husr->spam_val = (float)time(NULL);
+    if (husr->spam_val < (double)time(NULL))
+        husr->spam_val = (double)time(NULL);
 
-    husr->spam_val += (hlc_prof->constant_spam * (double)strlen(line));
+    husr->spam_val += ((double)(hlc_prof->constant_spam) * (double)strlen(line));
 
-    if (((int)husr->spam_val - time(NULL)) >= (hlc_prof->tolerance_spam))
+    if (((int)(husr->spam_val) - time(NULL)) >= (hlc_prof->tolerance_spam))
     {
         husr->spam_val = time(NULL);
         return ++husr->lc[HLC_SPAM];
@@ -249,14 +228,17 @@ static int hlc_check_spam(hlc_profile *hlc_prof, huser *husr, const char *line)
 }
 
 /* checks a string for lameness, returns non-zero if lameness is present */
-int hlc_check(void *hchan_ptr, void *husr_ptr, const char *line)
+int hlc_check(hchannel *hchan, huser* husr, const char *line)
 {
-    hchannel *hchan = (hchannel*)hchan_ptr;
-    huser *husr = (huser*)husr_ptr;
-
     if (hchan == NULL || hchan->lc_profile == NULL)
         return 0;
 
+    if (hlc_check_flood(hchan->lc_profile, husr, line))
+        if (hlc_violation_handle(hchan, husr, HLC_FLOOD))
+            return -1;
+    if (hlc_check_spam(hchan->lc_profile, husr, line))
+        if (hlc_violation_handle(hchan, husr, HLC_SPAM))
+           return -1;
     if (hlc_check_caps(hchan->lc_profile, husr, line))
         if (hlc_violation_handle(hchan, husr, HLC_CAPS))
             return -1;
@@ -266,13 +248,25 @@ int hlc_check(void *hchan_ptr, void *husr_ptr, const char *line)
     if (hlc_check_character_repeats(hchan->lc_profile, husr, line))
         if (hlc_violation_handle(hchan, husr, HLC_CHARACTER_REPEAT))
             return -1;
-    if (hlc_check_flood(hchan->lc_profile, husr, line))
-        if (hlc_violation_handle(hchan, husr, HLC_FLOOD))
-            return -1;
-    if (hlc_check_spam(hchan->lc_profile, husr, line))
-        if (hlc_violation_handle(hchan, husr, HLC_SPAM))
-            return -1;
 
     return 0;
 }
 
+const char *hlc_get_violation_name(hlc_violation violation)
+{
+    switch (violation)
+    {
+    case HLC_CAPS:
+       return "Excessive use of capital letters";
+    case HLC_REPEAT:
+       return "Repeating";
+    case HLC_CHARACTER_REPEAT:
+       return "Improper use of language";
+    case HLC_FLOOD:
+       return "Flooding";
+    case HLC_SPAM:
+       return "Spamming";
+    default:
+        return "Error, please contact strutsi";
+    }
+}