]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hhooks.c
Merge pull request #1 from meeb/meeb
[irc/quakenet/newserv.git] / helpmod2 / hhooks.c
index 2d77c190ecb9b72185c1418a328ded6203e3d2ad..546e1ceafa3e88ab0685effc5050b3dab8c3e7bf 100644 (file)
@@ -1,9 +1,6 @@
 #include <string.h>
 #include <assert.h>
 
-#include "../core/hooks.h"
-#include "../localuser/localuser.h"
-
 #include "helpmod.h"
 #include "hchannel.h"
 #include "haccount.h"
 #include "hqueue.h"
 #include "hgen.h"
 #include "hstat.h"
-
+/*
 void helpmod_hook_quit(int unused, void *args)
 {
     nick *nck = ((nick**)args)[0];
     huser *husr = huser_get(nck);
-    /* it was someone we didn't even know */
+    / * it was someone we didn't even know * /
     if (husr == NULL)
         return;
 }
+*/
+
 /*
 void helpmod_hook_part(int unused, void *args)
 {
@@ -29,39 +28,41 @@ void helpmod_hook_part(int unused, void *args)
     nick *nck = ((nick**)args)[1];
     huser *husr;
 
-
 }
 */
-void helpmod_hook_join(int unused, void *args)
+static void helpmod_hook_join(int unused, void *args)
 {
     channel *chan = ((channel**)args)[0];
     hchannel *hchan = hchannel_get_by_channel(chan);
     nick *nck = ((nick**)args)[1];
     huser *husr;
 
-    /* if we're not on this channel, the event is of no interest */
-    if (hchan == NULL || hchan->flags & H_PASSIVE)
+    /* if we're not on this channel or the target is G, the event is of no interest */
+    if (hchan == NULL || nck == helpmodnick)
         return;
 
     husr = huser_get(nck);
 
     assert(husr != NULL); /* hook_channel_newnick should fix this */
 
-    if (hchan->flags & H_JOINFLOOD_PROTECTION)
+    if ((hchan->flags & H_JOINFLOOD_PROTECTION) && !(hchan->flags & H_PASSIVE))
     {
-        if (hchan->jf_control < time(NULL))
-            hchan->jf_control = time(NULL);
-        else
-            hchan->jf_control++;
-
-        if (hchan->jf_control - time(NULL) > 25 && !IsRegOnly(hchan))
-        {
-            if (hchan->flags & H_REPORT && hchannel_is_valid(hchan->report_to))
-                helpmod_message_channel(hchan->report_to, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan));
-            hchannel_activate_join_flood(hchan);
-        }
+       if (hchan->jf_control < time(NULL))
+           hchan->jf_control = time(NULL);
+       else
+           hchan->jf_control++;
+
+       if (hchan->jf_control - time(NULL) > 12 && !IsRegOnly(hchan))
+       {
+           if (hchan->flags & H_REPORT && hchannel_is_valid(hchan->report_to))
+               helpmod_message_channel(hchan->report_to, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan));
+           hchannel_activate_join_flood(hchan);
+       }
     }
 
+    if (hchan->flags & H_PASSIVE)
+        return;
+
     if (hchan->flags & H_DO_STATS)
         hstat_add_join(hchan);
 
@@ -71,10 +72,10 @@ void helpmod_hook_join(int unused, void *args)
         return;
     }
 
-    if (huser_get_level(husr) > H_PEON && (huser_get_account_flags(husr) & H_AUTO_OP) && hchannel_authority(hchan, husr))
+    if (huser_get_level(husr) >= H_STAFF && (huser_get_account_flags(husr) & H_AUTO_OP) && hchannel_authority(hchan, husr))
         helpmod_channick_modes(husr, hchan ,MC_OP,HNOW);
 
-    if (huser_get_level(husr) > H_PEON && (huser_get_account_flags(husr) & H_AUTO_VOICE) && hchannel_authority(hchan, husr))
+    if (huser_get_level(husr) >= H_TRIAL && (huser_get_account_flags(husr) & H_AUTO_VOICE) && hchannel_authority(hchan, husr))
         helpmod_channick_modes(husr, hchan, MC_VOICE,HNOW);
 
     if (hchan->flags & H_WELCOME && *hchan->real_channel->index->name->content)
@@ -93,30 +94,32 @@ void helpmod_hook_join(int unused, void *args)
     }
 }
 
-void helpmod_hook_channel_newnick(int unused, void *args)
+static void helpmod_hook_channel_newnick(int unused, void *args)
 {
     channel *chan = ((channel**)args)[0];
     hchannel *hchan = hchannel_get_by_channel(chan);
     nick *nck = ((nick**)args)[1];
     huser *husr;
 
-    /* if we're not on this channel, the event is of no interest */
-    if (hchan == NULL)
+    /* if we're not on this channel or the target is G, the event is of no interest */
+    if (hchan == NULL || nck == helpmodnick)
         return;
 
     if ((husr = huser_get(nck)) == NULL)
         husr = huser_add(nck);
-/*
-    fprintf(hdebug_file, "%d ADD %s to %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
-    fflush(hdebug_file);
-*/
+
     assert(huser_on_channel(husr, hchan) == NULL);
     assert(hchannel_on_channel(hchan, husr) == NULL);
 
     hchannel_add_user(hchan, husr);
     huser_add_channel(husr, hchan);
 
-    if (huser_get_level(husr) == H_LAMER || (huser_get_level(husr) == H_PEON && hban_check(nck)))
+    if (hchan->flags & H_PASSIVE)
+        return;
+
+    huser_activity(husr, NULL);
+
+    if (huser_get_level(husr) == H_LAMER || (huser_get_level(husr) <= H_TRIAL && hban_check(nck)))
     {
         hban *hb = hban_check(nck);
 
@@ -124,7 +127,7 @@ void helpmod_hook_channel_newnick(int unused, void *args)
        helpmod_setban(hchan, banmask, time(NULL) + 1 * HDEF_d, MCB_ADD, HNOW);
 
        if (hb)
-           helpmod_kick(hchan, husr,hban_get_reason(hb));
+           helpmod_kick(hchan, husr, "%s", hban_get_reason(hb));
        else
            helpmod_kick(hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(hchan));
 
@@ -134,7 +137,7 @@ void helpmod_hook_channel_newnick(int unused, void *args)
         hqueue_handle_queue(hchan, NULL);
 }
 
-void helpmod_hook_channel_lostnick(int unused, void *args)
+static void helpmod_hook_channel_lostnick(int unused, void *args)
 {
     channel *chan = ((channel**)args)[0];
     hchannel *hchan = hchannel_get_by_channel(chan);
@@ -142,6 +145,10 @@ void helpmod_hook_channel_lostnick(int unused, void *args)
     nick *nck = ((nick**)args)[1];
     huser *husr;
 
+    /* In event that G was kicked, nothing is done */
+    if (nck == helpmodnick)
+        return;
+
     /* hackery, can't think of a better way to do this */
     huser *oper = NULL;
     int handle_queue = 0;
@@ -155,15 +162,12 @@ void helpmod_hook_channel_lostnick(int unused, void *args)
     assert(husr != NULL);
 
     huserchan = huser_on_channel(husr, hchan);
-/*
-    fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
-    fflush(hdebug_file);
-*/
+
     assert(hchannel_on_channel(hchan, husr) != NULL);
     assert(huserchan != NULL);
 
-    if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN)) /* && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))*/
-        if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
+    if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN) && !(hchan->flags & H_PASSIVE)) /* && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))*/
+       if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
             /* if it was a netsplit, we do not trigger autoqueue */
         {
             oper = huserchan->responsible_oper;
@@ -177,10 +181,6 @@ void helpmod_hook_channel_lostnick(int unused, void *args)
     { /* if H left the channel, we remove all the users from the channel */
         while (hchan->channel_users)
         {
-            /*
-            fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), hchan->channel_users->husr->real_user->nick, hchannel_get_name(hchan));
-            fflush(hdebug_file);
-            */
             huser_del_channel(hchan->channel_users->husr, hchan);
             hchannel_del_user(hchan, hchan->channel_users->husr);
         }
@@ -190,19 +190,19 @@ void helpmod_hook_channel_lostnick(int unused, void *args)
         hqueue_handle_queue(hchan, oper);
 }
 
-void helpmod_hook_nick_lostnick(int unused, void *args)
+static void helpmod_hook_nick_lostnick(int unused, void *args)
 {
-    nick *nck = ((nick**)args)[0];
+    nick *nck = (nick*)args;
     huser *husr = huser_get(nck);
 
     /* it was someone we didn't even know */
     if (husr == NULL)
-            return;
+       return;
 
     huser_del(husr);
 }
 
-void helpmod_hook_channel_opped(int unused, void *args)
+static void helpmod_hook_channel_opped(int unused, void *args)
 {
     hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
     huser_channel *huserchan;
@@ -222,15 +222,18 @@ void helpmod_hook_channel_opped(int unused, void *args)
 
     huserchan->flags |= HCUMODE_OP;
 
+    if (hchan->flags & H_PASSIVE)
+        return;
+
     /* if the +o was given by a network service, G will not interfere */
-    if (husr2 == NULL || strlen(husr2->real_user->nick) == 1)
+    if (husr2 == NULL || strlen(huser_get_nick(husr2)) == 1)
         return;
 
     if (huser_get_level(husr) < H_STAFF)
         helpmod_channick_modes(husr, hchan, MC_DEOP ,HNOW);
 }
 
-void helpmod_hook_channel_deopped(int unused, void *args)
+static void helpmod_hook_channel_deopped(int unused, void *args)
 {
     hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
     huser_channel *huserchan;
@@ -248,10 +251,9 @@ void helpmod_hook_channel_deopped(int unused, void *args)
     assert(huserchan != NULL);
 
     huserchan->flags &= ~HCUMODE_OP;
-
 }
 
-void helpmod_hook_channel_voiced(int unused, void *args)
+static void helpmod_hook_channel_voiced(int unused, void *args)
 {
     hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
     huser_channel *huserchan;
@@ -276,7 +278,7 @@ void helpmod_hook_channel_voiced(int unused, void *args)
     }
 }
 
-void helpmod_hook_channel_devoiced(int unused, void *args)
+static void helpmod_hook_channel_devoiced(int unused, void *args)
 {
     hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
     huser_channel *huserchan;
@@ -295,26 +297,24 @@ void helpmod_hook_channel_devoiced(int unused, void *args)
 
     huserchan->flags &= ~HCUMODE_VOICE;
 
+    if (hchan->flags & H_PASSIVE)
+        return;
+
     if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN) && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))
     {
         if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
         { /* if it was a netsplit, we do not trigger autoqueue */
             hqueue_handle_queue(hchan, huserchan->responsible_oper);
-            /*if (huser_valid(huserchan->responsible_oper) && huser_on_channel(huserchan->responsible_oper, hchan))
-                hqueue_advance(hchan, huserchan->responsible_oper, 1);
-            else
-            hqueue_advance(hchan, huserchan->responsible_oper, 1);
-            */
         }
     }
 }
 
-void helpmod_hook_channel_topic(int unused, void *args)
+static void helpmod_hook_channel_topic(int unused, void *args)
 {
     hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
     huser *husr;
 
-    if (hchan == NULL)
+    if (hchan == NULL || hchan->flags & H_PASSIVE)
         return;
 
     husr = huser_get(((nick**)args)[2]);
@@ -333,19 +333,42 @@ void helpmod_hook_channel_topic(int unused, void *args)
     }
 }
 
-void helpmod_hook_nick_account(int unused, void *args)
+static void helpmod_hook_nick_account(int unused, void *args)
 {
     nick *nck = (nick*)args;
     huser *husr = huser_get(nck);
+    huser_channel *huserchan, *huserchannext;
     if (husr == NULL)
         return;
     else
-        husr->account = haccount_get_by_name(nck->authname);
+       husr->account = haccount_get_by_name(nck->authname);
+
+    if (huser_get_level(husr) == H_LAMER) {
+        for (huserchan = husr->hchannels; huserchan; huserchan = huserchannext) {
+            huserchannext = huserchan->next;
+            helpmod_kick(huserchan->hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(huserchan->hchan));
+        }
+    }
+}
+
+static void helpmod_hook_server_newserver(int unused, void *args)
+{
+    hchannel *hchan;
+    long numeric = (long)args;
+    server srv = serverlist[numeric];
+
+    /* check linkstate to prevent spam */
+    if (srv.linkstate == LS_LINKING)
+    {
+       for (hchan = hchannels;hchan != NULL;hchan = hchan->next)
+           if ((hchan->flags & H_HANDLE_TOPIC) && (hchan->topic != NULL))
+               hchannel_set_topic(hchan);
+    }
 }
 
 void helpmod_registerhooks(void)
 {
-    registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit);
+/*    registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
     /*if (registerhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
     registerhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
     registerhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
@@ -357,11 +380,12 @@ void helpmod_registerhooks(void)
     registerhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
     registerhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
     registerhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
+    registerhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
 }
 
 void helpmod_deregisterhooks(void)
 {
-    deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit);
+/*    deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
     /*if (deregisterhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
     deregisterhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
     deregisterhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
@@ -373,4 +397,5 @@ void helpmod_deregisterhooks(void)
     deregisterhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
     deregisterhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
     deregisterhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
+    deregisterhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
 }