Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / s_bsd.c
index 4d9be9e639f699c85fe85583fd00a9060a01ef24..15d53b812c28ecce38b68b0cf346a95cf1ebc518 100644 (file)
@@ -406,9 +406,9 @@ static int completed_connection(struct Client* cptr)
     sendto_opmask_butone(0, SNO_OLDSNO, "Lost Server Line for %s", cptr->name);
     return 0;
   }
-  /* XXX sendto_one sending without a prefix; be careful! */
+
   if (!EmptyString(aconf->passwd))
-    sendto_one(cptr, "PASS :%s", aconf->passwd);
+    sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
 
 #if 0 
   /* dead code, already done in connect_server */
@@ -434,10 +434,10 @@ static int completed_connection(struct Client* cptr)
    */
   cptr->lasttime = CurrentTime;
   cptr->flags |= FLAGS_PINGSENT;
-  /* XXX sendto_one sending without a prefix; be careful! */
-  sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
-             me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
-             NumServCap(&me), me.info);
+
+  sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s",
+               me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL, 
+               NumServCap(&me), me.info);
 
   return (IsDead(cptr)) ? 0 : 1;
 }
@@ -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;
@@ -547,52 +548,55 @@ int net_close_unregistered_connections(struct Client* source)
   return count;
 }
 
-/*
+/*----------------------------------------------------------------------------
+ * add_connection
+ *
  * Creates a client which has just connected to us on the given fd.
  * The sockhost field is initialized with the ip# of the host.
  * The client is not added to the linked list of clients, it is
  * passed off to the auth handler for dns and ident queries.
- */
-void add_connection(struct Listener* listener, int fd)
-{
+ *--------------------------------------------------------------------------*/
+void add_connection(struct Listener* listener, int fd) {
   struct sockaddr_in addr;
-  struct Client*     new_client;
+  struct Client      *new_client;
   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 connections.
+   * 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
+   * connections.  
    */
   if (!os_get_peername(fd, &addr) || !os_set_nonblocking(fd)) {
     ++ServerStats->is_ref;
     close(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 (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
-    ++ServerStats->is_ref;
-    /*
-     * strlen(throttle_message) == 66
-     */
-    send(fd, throttle_message, 66, 0);
-    close(fd);
-    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);
+  new_client = make_client(0, ((listener->server) ? 
+                              STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER));
+
   /*
-   * Copy ascii address to 'sockhost' just in case. Then we
-   * have something valid to put into error messages...
+   * Copy ascii address to 'sockhost' just in case. Then we have something
+   * valid to put into error messages...  
    */
   ircd_ntoa_r(new_client->sock_ip, (const char*) &addr.sin_addr);   
   strcpy(new_client->sockhost, new_client->sock_ip);
@@ -603,19 +607,16 @@ void add_connection(struct Listener* listener, int fd)
     new_client->nexttarget = next_target;
 
   new_client->fd = fd;
-
-  if (!listener->server)
-    SetIPChecked(new_client);
   new_client->listener = listener;
   ++listener->ref_count;
 
   Count_newunknown(UserStats);
-  /*
-   * if we've made it this far we can put the client on the auth query pile
-   */
+
+  /* if we've made it this far we can put the client on the auth query pile */
   start_auth(new_client);
 }
 
+
 /*
  * read_packet
  *
@@ -1242,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)
@@ -1417,6 +1412,8 @@ int connect_server(struct ConfItem* aconf, struct Client* by,
 
   if (cptr->fd > HighestFd)
     HighestFd = cptr->fd;
+
+  
   LocalClientArray[cptr->fd] = cptr;
 
   Count_newunknown(UserStats);