Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / IPcheck.c
index fd9173f915849ec98667878e696b296ebefa0fee..439d60e51fe151cac49c21a1c5929f83a3d620c7 100644 (file)
  *
  * $Id$
  *
+ * 
+ * This file should be edited in a window with a width of 141 characters
+ * ick
  */
 #include "IPcheck.h"
 #include "client.h"
 #include "ircd.h"
+#include "msg.h"
 #include "numnicks.h"       /* NumNick, NumServ (GODMODE) */
 #include "ircd_alloc.h"
-#include "s_bsd.h"          /* SetIPChecked */
 #include "s_debug.h"        /* Debug */
 #include "s_user.h"         /* TARGET_DELAY */
 #include "send.h"
 
 #include <assert.h>
-#include <stdio.h>          /* NULL ... bleah */
 
 
 struct IPTargetEntry {
@@ -42,8 +44,8 @@ struct IPRegistryEntry {
   struct IPRegistryEntry*  next;
   struct IPTargetEntry*    target;
   unsigned int             addr;
-  unsigned short           last_connect;
-  unsigned char            connected;
+  int                     last_connect;
+  unsigned short           connected;
   unsigned char            attempts;
 };
 
@@ -59,8 +61,8 @@ struct IPRegistryEntry {
 #define NOW ((unsigned short)(CurrentTime & MASK_16))
 #define CONNECTED_SINCE(x) (NOW - (x))
 
-#define IPCHECK_CLONE_LIMIT 2
-#define IPCHECK_CLONE_PERIOD 20
+#define IPCHECK_CLONE_LIMIT 4
+#define IPCHECK_CLONE_PERIOD 40
 #define IPCHECK_CLONE_DELAY 600
 
 
@@ -240,13 +242,14 @@ int ip_registry_check_local(unsigned int addr, time_t* next_target_out)
     if (next_target_out)
       *next_target_out = CurrentTime - (TARGET_DELAY * free_targets - 1);
   }
-  else if ((CurrentTime - me.since) > IPCHECK_CLONE_DELAY) {
+  else if ((CurrentTime - cli_since(&me)) > IPCHECK_CLONE_DELAY) {
     /* 
      * Don't refuse connection when we just rebooted the server
      */
 #ifdef NOTHROTTLE 
     return 1;
 #else
+    --entry->connected;
     return 0;
 #endif        
   }
@@ -266,7 +269,7 @@ int ip_registry_check_local(unsigned int addr, time_t* next_target_out)
  */
 int ip_registry_check_remote(struct Client* cptr, int is_burst)
 {
-  struct IPRegistryEntry* entry = ip_registry_find(cptr->ip.s_addr);
+  struct IPRegistryEntry* entry = ip_registry_find((cli_ip(cptr)).s_addr);
 
   /*
    * Mark that we did add/update an IPregistry entry
@@ -274,7 +277,7 @@ int ip_registry_check_remote(struct Client* cptr, int is_burst)
   SetIPChecked(cptr);
   if (0 == entry) {
     entry = ip_registry_new_entry();
-    entry->addr = cptr->ip.s_addr;
+    entry->addr = (cli_ip(cptr)).s_addr;
     if (is_burst)
       entry->attempts = 0;
     ip_registry_add(entry);
@@ -299,6 +302,7 @@ int ip_registry_check_remote(struct Client* cptr, int is_burst)
       entry->last_connect = NOW;
     }
   }
+  SetIPChecked(cptr);
   return 1;
 }
 
@@ -332,20 +336,20 @@ void ip_registry_connect_succeeded(struct Client *cptr)
 {
   const char*             tr    = "";
   unsigned int free_targets     = STARTTARGETS;
-  struct IPRegistryEntry* entry = ip_registry_find(cptr->ip.s_addr);
+  struct IPRegistryEntry* entry = ip_registry_find((cli_ip(cptr)).s_addr);
 
   if (!entry) {
-    Debug((DEBUG_ERROR, "Missing registry entry for: %s", cptr->sock_ip));
+    Debug((DEBUG_ERROR, "Missing registry entry for: %s", cli_sock_ip(cptr)));
     return;
   }
   if (entry->target) {
-    memcpy(cptr->targets, entry->target->targets, MAXTARGETS);
+    memcpy(cli_targets(cptr), entry->target->targets, MAXTARGETS);
     free_targets = entry->target->count;
     tr = " tr";
   }
-  sendto_one(cptr, ":%s NOTICE %s :on %u ca %u(%u) ft %u(%u)%s",
-             me.name, cptr->name, entry->connected, entry->attempts,
-             IPCHECK_CLONE_LIMIT, free_targets, STARTTARGETS, tr);
+  sendcmdto_one(&me, CMD_NOTICE, cptr, ":on %u ca %u(%u) ft %u(%u)%s",
+               entry->connected, entry->attempts, IPCHECK_CLONE_LIMIT,
+               free_targets, STARTTARGETS, tr);
 }
 
 /*
@@ -361,7 +365,7 @@ void ip_registry_connect_succeeded(struct Client *cptr)
  */
 void ip_registry_disconnect(struct Client *cptr)
 {
-  struct IPRegistryEntry* entry = ip_registry_find(cptr->ip.s_addr);
+  struct IPRegistryEntry* entry = ip_registry_find((cli_ip(cptr)).s_addr);
   if (0 == entry) {
     /*
      * trying to find an entry for a server causes this to happen,
@@ -393,7 +397,7 @@ void ip_registry_disconnect(struct Client *cptr)
     }
     assert(0 != entry->target);
 
-    memcpy(entry->target->targets, cptr->targets, MAXTARGETS);
+    memcpy(entry->target->targets, cli_targets(cptr), MAXTARGETS);
     /*
      * This calculation can be pretty unfair towards large multi-user hosts, but
      * there is "nothing" we can do without also allowing spam bots to send more
@@ -407,22 +411,22 @@ void ip_registry_disconnect(struct Client *cptr)
      * ALL should get no free targets when reconnecting.  We'd need to store an entry
      * per client (instead of per IP number) to avoid this.
      */
-    if (cptr->nexttarget < CurrentTime) {
+    if (cli_nexttarget(cptr) < CurrentTime) {
         /*
          * Number of free targets
          */
-      free_targets = (CurrentTime - cptr->nexttarget) / TARGET_DELAY + 1;
+      free_targets = (CurrentTime - cli_nexttarget(cptr)) / TARGET_DELAY + 1;
     }
     else
       free_targets = 0;
     /*
      * Add bonus, this is pretty fuzzy, but it will help in some cases.
      */
-    if ((CurrentTime - cptr->firsttime) > 600)
+    if ((CurrentTime - cli_firsttime(cptr)) > 600)
       /*
        * Was longer then 10 minutes online?
        */
-      free_targets += (CurrentTime - cptr->firsttime - 600) / TARGET_DELAY;
+      free_targets += (CurrentTime - cli_firsttime(cptr) - 600) / TARGET_DELAY;
     /*
      * Finally, store smallest value for Judgement Day
      */