]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - modules/core/m_message.c
Reverting to 398.. trying again with native charybdis hash
[irc/rqf/shadowircd.git] / modules / core / m_message.c
index 96da9d2edb15c36e33546c29fc9a959e4e3ea309..95a68fc76b5eded57416cf2c18ca6a18f0af232d 100644 (file)
 #include "msg.h"
 #include "packet.h"
 #include "send.h"
-#include "event.h"
-#include "patricia.h"
 #include "s_newconf.h"
+#include "s_stats.h"
 
 static int m_message(int, const char *, struct Client *, struct Client *, int, const char **);
 static int m_privmsg(struct Client *, struct Client *, int, const char **);
 static int m_notice(struct Client *, struct Client *, int, const char **);
 
 static void expire_tgchange(void *unused);
+static struct ev_entry *expire_tgchange_event;
 
 static int
 modinit(void)
 {
-       eventAddIsh("expire_tgchange", expire_tgchange, NULL, 300);
+       expire_tgchange_event = rb_event_addish("expire_tgchange", expire_tgchange, NULL, 300);
        expire_tgchange(NULL);
        return 0;
 }
@@ -62,7 +62,7 @@ modinit(void)
 static void
 moddeinit(void)
 {
-       eventDelete(expire_tgchange, NULL);
+       rb_event_delete(expire_tgchange_event);
 }
 
 struct Message privmsg_msgtab = {
@@ -446,7 +446,7 @@ msg_channel(int p_or_n, const char *command,
        {
                /* idle time shouldnt be reset by notices --fl */
                if(p_or_n != NOTICE)
-                       source_p->localClient->last = CurrentTime;
+                       source_p->localClient->last = rb_current_time();
        }
 
        if(chptr->mode.mode & MODE_NOCOLOR)
@@ -530,7 +530,7 @@ msg_channel_flags(int p_or_n, const char *command, struct Client *client_p,
        {
                /* idletime shouldnt be reset by notice --fl */
                if(p_or_n != NOTICE)
-                       source_p->localClient->last = CurrentTime;
+                       source_p->localClient->last = rb_current_time();
        }
 
        sendto_channel_flags(client_p, type, source_p, chptr, "%s %c%s :%s",
@@ -545,18 +545,18 @@ static void
 expire_tgchange(void *unused)
 {
        tgchange *target;
-       dlink_node *ptr, *next_ptr;
+       rb_dlink_node *ptr, *next_ptr;
 
-       DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head)
        {
                target = ptr->data;
 
-               if(target->expiry < CurrentTime)
+               if(target->expiry < rb_current_time())
                {
-                       dlinkDelete(ptr, &tgchange_list);
-                       patricia_remove(tgchange_tree, target->pnode);
-                       MyFree(target->ip);
-                       MyFree(target);
+                       rb_dlinkDelete(ptr, &tgchange_list);
+                       rb_patricia_remove(tgchange_tree, target->pnode);
+                       rb_free(target->ip);
+                       rb_free(target);
                }
        }
 }
@@ -565,6 +565,7 @@ static int
 add_target(struct Client *source_p, struct Client *target_p)
 {
        int i, j;
+       uint32_t hashv;
 
        /* can msg themselves or services without using any target slots */
        if(source_p == target_p || IsService(target_p))
@@ -575,16 +576,18 @@ add_target(struct Client *source_p, struct Client *target_p)
         *
         * XXX: is this controversial?
         */
-       if(source_p->localClient->target_last > CurrentTime && IsOper(target_p))
+       if(source_p->localClient->target_last > rb_current_time() && IsOper(target_p))
                return 1;
 
+       hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32);
+
        if(USED_TARGETS(source_p))
        {
                /* hunt for an existing target */
                for(i = PREV_FREE_TARGET(source_p), j = USED_TARGETS(source_p);
                    j; --j, PREV_TARGET(i))
                {
-                       if(source_p->localClient->targets[i] == target_p)
+                       if(source_p->localClient->targets[i] == hashv)
                                return 1;
                }
 
@@ -594,21 +597,22 @@ add_target(struct Client *source_p, struct Client *target_p)
                if(!IsTGChange(source_p))
                {
                        SetTGChange(source_p);
-                       source_p->localClient->target_last = CurrentTime;
+                       source_p->localClient->target_last = rb_current_time();
                }
                /* clear as many targets as we can */
-               else if((i = (CurrentTime - source_p->localClient->target_last) / 60))
+               else if((i = (rb_current_time() - source_p->localClient->target_last) / 60))
                {
                        if(i > USED_TARGETS(source_p))
                                USED_TARGETS(source_p) = 0;
                        else
                                USED_TARGETS(source_p) -= i;
 
-                       source_p->localClient->target_last = CurrentTime;
+                       source_p->localClient->target_last = rb_current_time();
                }
                /* cant clear any, full target list */
                else if(USED_TARGETS(source_p) == 10)
                {
+                       ServerStats->is_tgch++;
                        add_tgchange(source_p->sockhost);
                        return 0;
                }
@@ -618,11 +622,11 @@ add_target(struct Client *source_p, struct Client *target_p)
         */
        else
        {
-               source_p->localClient->target_last = CurrentTime;
+               source_p->localClient->target_last = rb_current_time();
                SetTGChange(source_p);
        }
 
-       source_p->localClient->targets[FREE_TARGET(source_p)] = target_p;
+       source_p->localClient->targets[FREE_TARGET(source_p)] = hashv;
        NEXT_TARGET(FREE_TARGET(source_p));
        ++USED_TARGETS(source_p);
        return 1;
@@ -649,7 +653,7 @@ msg_client(int p_or_n, const char *command,
                /* reset idle time for message only if its not to self 
                 * and its not a notice */
                if(p_or_n != NOTICE)
-                       source_p->localClient->last = CurrentTime;
+                       source_p->localClient->last = rb_current_time();
 
                /* target change stuff, dont limit ctcp replies as that
                 * would allow people to start filling up random users
@@ -712,7 +716,7 @@ msg_client(int p_or_n, const char *command,
                                }
 
                                if((target_p->localClient->last_caller_id_time +
-                                   ConfigFileEntry.caller_id_wait) < CurrentTime)
+                                   ConfigFileEntry.caller_id_wait) < rb_current_time())
                                {
                                        if(p_or_n != NOTICE)
                                                sendto_one_numeric(source_p, RPL_TARGNOTIFY,
@@ -723,7 +727,7 @@ msg_client(int p_or_n, const char *command,
                                                   me.name, target_p->name, source_p->name,
                                                   source_p->username, source_p->host);
 
-                                       target_p->localClient->last_caller_id_time = CurrentTime;
+                                       target_p->localClient->last_caller_id_time = rb_current_time();
                                }
                                /* Only so opers can watch for floods */
                                (void) flood_attack_client(p_or_n, source_p, target_p);
@@ -764,11 +768,11 @@ flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p
 
        if(GlobalSetOptions.floodcount && MyConnect(target_p) && IsClient(source_p))
        {
-               if((target_p->localClient->first_received_message_time + 1) < CurrentTime)
+               if((target_p->localClient->first_received_message_time + 1) < rb_current_time())
                {
-                       delta = CurrentTime - target_p->localClient->first_received_message_time;
+                       delta = rb_current_time() - target_p->localClient->first_received_message_time;
                        target_p->localClient->received_number_of_privmsgs -= delta;
-                       target_p->localClient->first_received_message_time = CurrentTime;
+                       target_p->localClient->first_received_message_time = rb_current_time();
                        if(target_p->localClient->received_number_of_privmsgs <= 0)
                        {
                                target_p->localClient->received_number_of_privmsgs = 0;
@@ -781,7 +785,7 @@ flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p
                {
                        if(target_p->localClient->flood_noticed == 0)
                        {
-                               sendto_realops_snomask(SNO_BOTS, L_ALL,
+                               sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
                                                     "Possible Flooder %s[%s@%s] on %s target: %s",
                                                     source_p->name, source_p->username,
                                                     source_p->orighost,
@@ -819,11 +823,11 @@ flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr,
 
        if(GlobalSetOptions.floodcount && MyClient(source_p))
        {
-               if((chptr->first_received_message_time + 1) < CurrentTime)
+               if((chptr->first_received_message_time + 1) < rb_current_time())
                {
-                       delta = CurrentTime - chptr->first_received_message_time;
+                       delta = rb_current_time() - chptr->first_received_message_time;
                        chptr->received_number_of_privmsgs -= delta;
-                       chptr->first_received_message_time = CurrentTime;
+                       chptr->first_received_message_time = rb_current_time();
                        if(chptr->received_number_of_privmsgs <= 0)
                        {
                                chptr->received_number_of_privmsgs = 0;
@@ -836,7 +840,7 @@ flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr,
                {
                        if(chptr->flood_noticed == 0)
                        {
-                               sendto_realops_snomask(SNO_BOTS, L_ALL,
+                               sendto_realops_snomask(SNO_BOTS, *chptr->chname == '&' ? L_ALL : L_NETWIDE,
                                                     "Possible Flooder %s[%s@%s] on %s target: %s",
                                                     source_p->name, source_p->username,
                                                     source_p->orighost,
@@ -1019,11 +1023,11 @@ find_userhost(const char *user, const char *host, int *count)
        struct Client *c2ptr;
        struct Client *res = NULL;
        char *u = LOCAL_COPY(user);
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        *count = 0;
        if(collapse(u) != NULL)
        {
-               DLINK_FOREACH(ptr, global_client_list.head)
+               RB_DLINK_FOREACH(ptr, global_client_list.head)
                {
                        c2ptr = ptr->data;
                        if(!MyClient(c2ptr))    /* implies mine and an user */