Author: Isomer
[ircu2.10.12-pk.git] / ircd / s_bsd.c
index 2d82dbb80899a114aefd8de1bdac0206877dbcb9..f5c8aebe167dbb6d4670d49b673f6bb1a21ed0d0 100644 (file)
@@ -506,6 +506,7 @@ void close_connection(struct Client *cptr)
 
   if (-1 < cptr->fd) {
     flush_connections(cptr);
+    ip_registry_local_disconnect(cptr);
     LocalClientArray[cptr->fd] = 0;
     close(cptr->fd);
     cptr->fd = -1;
@@ -561,11 +562,12 @@ void add_connection(struct Listener* listener, int fd) {
   time_t             next_target = 0;
 
   const char* const throttle_message =
-         "ERRORYour host is trying to (re)connect too fast -- throttled\r\n";
+         "ERROR :Your host is trying to (re)connect too fast -- throttled\r\n";
        /* 12345678901234567890123456789012345679012345678901234567890123456 */
   
   assert(0 != listener);
 
   /*
    * Removed preliminary access check. Full check is performed in m_server and
    * m_user instead. Also connection time out help to get rid of unwanted
@@ -577,27 +579,21 @@ void add_connection(struct Listener* listener, int fd) {
     return;
   }
 
-
   /*
    * Add this local client to the IPcheck registry.
    *
-   * If it is a connection to a user port and if the site has been throttled,
-   * reject the user.
+   * If they're throttled, murder them, but tell them why first.
    */
-  if (!ip_registry_check_local(addr.sin_addr.s_addr, &next_target) &&
-      !listener->server) {
-    send(fd, throttle_message, 66, 0);
-    close(fd);
-    ++ServerStats->is_ref;
-    return;
+  if ( !ip_registry_check_local(addr.sin_addr.s_addr,&next_target) ) {
+       ++ServerStats->is_ref;
+       write(fd,throttle_message,strlen(throttle_message));
+       close(fd);
+       return;
   }
 
   new_client = make_client(0, ((listener->server) ? 
                               STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
 
-  if (!listener->server)
-    ip_registry_local_connect(new_client);
-
   /*
    * Copy ascii address to 'sockhost' just in case. Then we have something
    * valid to put into error messages...  
@@ -615,7 +611,7 @@ void add_connection(struct Listener* listener, int fd) {
   ++listener->ref_count;
 
   Count_newunknown(UserStats);
-
+  ip_registry_connect_succeeded(new_client);
   /* if we've made it this far we can put the client on the auth query pile */
   start_auth(new_client);
 }
@@ -1247,12 +1243,6 @@ int read_message(time_t delay)
       if (CPTR_KILLED == (length = read_packet(cptr, read_ready)))
         continue;
     }
-#if 0
-    /* Bullshit, why would we want to flush sockets while using non-blocking?
-     * This uses > 4% cpu! --Run */
-    if (length > 0)
-      flush_connections(LocalClientArray[i]);
-#endif
     if (IsDead(cptr)) {
       const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
       if (!msg)
@@ -1422,9 +1412,17 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if (cptr->fd > HighestFd)
     HighestFd = cptr->fd;
+
+  
   LocalClientArray[cptr->fd] = cptr;
 
   Count_newunknown(UserStats);
+  ip_registry_add_local(aconf->ipnum.s_addr);
+  /* Actually we lie, the connect hasn't succeeded yet, but we have a valid
+   * cptr, so we register it now.
+   * Maybe these two calls should be merged.
+   */
+  ip_registry_connect_succeeded(cptr);
   add_client_to_list(cptr);
   hAddClient(cptr);
   nextping = CurrentTime;