Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_serv.c
index cd7e82627ee4600d899509e59aa2c572e39f4947..ff5d2e0149dba658a4091ff9dabe5bb17b70334d 100644 (file)
  *
  * $Id$
  */
+#include "config.h"
+
 #include "s_serv.h"
 #include "IPcheck.h"
 #include "channel.h"
 #include "client.h"
-#include "crule.h"
 #include "gline.h"
 #include "hash.h"
 #include "ircd.h"
@@ -37,8 +38,9 @@
 #include "ircd_xopen.h"
 #include "jupe.h"
 #include "list.h"
-#include "msg.h"
 #include "match.h"
+#include "msg.h"
+#include "msgq.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "parse.h"
 
 unsigned int max_connection_count = 0;
 unsigned int max_client_count = 0;
-#if 0
-int exit_new_server(struct Client* cptr, struct Client* sptr,
-                    const char* host, time_t timestamp, const char* fmt, ...)
-{
-  va_list vl;
-  char *buf =
-      (char*) MyMalloc(strlen(me.name) + strlen(host) + 22 + strlen(fmt));
-  assert(0 != buf);
-  va_start(vl, fmt);
-  if (!IsServer(sptr))
-    return vexit_client_msg(cptr, cptr, &me, fmt, vl);
-  sprintf_irc(buf, ":%s " TOK_SQUIT " %s " TIME_T_FMT " :", me.name, host, timestamp);
-  strcat(buf, fmt);
-  vsendto_one(cptr, buf, vl); /* XXX DEAD */
-  va_end(vl);
-  MyFree(buf);
-  return 0;
-}
-#endif /* 0 */
 
 int exit_new_server(struct Client *cptr, struct Client *sptr, const char *host,
-                   time_t timestamp, const char *pattern, ...)
+                    time_t timestamp, const char *pattern, ...)
 {
   struct VarData vd;
   int retval = 0;
@@ -101,7 +84,7 @@ int exit_new_server(struct Client *cptr, struct Client *sptr, const char *host,
 
 int a_kills_b_too(struct Client *a, struct Client *b)
 {
-  for (; b != a && b != &me; b = b->serv->up);
+  for (; b != a && b != &me; b = cli_serv(b)->up);
   return (a == b ? 1 : 0);
 }
 
@@ -111,18 +94,19 @@ int a_kills_b_too(struct Client *a, struct Client *b)
  * May only be called after a SERVER was received from cptr,
  * and thus make_server was called, and serv->prot set. --Run
  */
-int server_estab(struct Client *cptr, struct ConfItem *aconf)
+int server_estab(struct Client *cptr, struct ConfItem *aconf,
+                 struct Jupe *ajupe)
 {
   struct Client* acptr = 0;
   const char*    inpath;
   int split,     i;
 
   assert(0 != cptr);
-  assert(0 != cptr->local);
+  assert(0 != cli_local(cptr));
 
-  split = (0 != ircd_strcmp(cptr->name, cptr->sockhost)
-      &&   0 != ircd_strncmp(cptr->info, "JUPE", 4));
-  inpath = cptr->name;
+  split = (0 != ircd_strcmp(cli_name(cptr), cli_sockhost(cptr))
+      &&   0 != ircd_strncmp(cli_info(cptr), "JUPE", 4));
+  inpath = cli_name(cptr);
 
   if (IsUnknown(cptr)) {
     if (aconf->passwd[0])
@@ -130,15 +114,15 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
     /*
      *  Pass my info to the new server
      */
-    sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s", me.name,
-                 me.serv->timestamp, cptr->serv->timestamp, MAJOR_PROTOCOL,
-                 NumServCap(&me), *me.info ? me.info : "IRCers United");
+    sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s", cli_name(&me),
+                  cli_serv(&me)->timestamp, cli_serv(cptr)->timestamp, MAJOR_PROTOCOL,
+                  NumServCap(&me), *(cli_info(&me)) ? cli_info(&me) : "IRCers United");
     /*
      * Don't charge this IP# for connecting
      * XXX - if this comes from a server port, it will not have been added
-     * to the IP check registry, see add_connection in s_bsd.c 
+     * to the IP check registry, see add_connection in s_bsd.c
      */
-    IPcheck_connect_fail(cptr->ip);
+    IPcheck_connect_fail(cli_ip(cptr));
   }
 
   det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
@@ -146,39 +130,39 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
   if (!IsHandshake(cptr))
     hAddClient(cptr);
   SetServer(cptr);
-  cptr->handler = SERVER_HANDLER;
+  cli_handler(cptr) = SERVER_HANDLER;
   Count_unknownbecomesserver(UserStats);
 
   release_dns_reply(cptr);
 
   SetBurst(cptr);
 
-  nextping = CurrentTime;
+/*    nextping = CurrentTime; */
 
   /*
    * NOTE: check for acptr->user == cptr->serv->user is necessary to insure
    * that we got the same one... bleah
    */
-  if (cptr->serv->user && *cptr->serv->by &&
-      (acptr = findNUser(cptr->serv->by))) {
-    if (acptr->user == cptr->serv->user) {
+  if (cli_serv(cptr)->user && *(cli_serv(cptr))->by &&
+      (acptr = findNUser(cli_serv(cptr)->by))) {
+    if (cli_user(acptr) == cli_serv(cptr)->user) {
       sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
-                   acptr, inpath);
+                    acptr, inpath);
     }
     else {
       /*
        * if not the same client, set by to empty string
        */
       acptr = 0;
-      *cptr->serv->by = '\0';
+      *(cli_serv(cptr))->by = '\0';
     }
   }
 
   sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s established.", inpath);
-  cptr->serv->up = &me;
-  cptr->serv->updown = add_dlink(&me.serv->down, cptr);
-  sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", me.name,
-                      cptr->name);
+  cli_serv(cptr)->up = &me;
+  cli_serv(cptr)->updown = add_dlink(&(cli_serv(&me))->down, cptr);
+  sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", cli_name(&me),
+                       cli_name(cptr));
   SetJunction(cptr);
   /*
    * Old sendto_serv_but_one() call removed because we now
@@ -190,11 +174,18 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
     if (!(acptr = LocalClientArray[i]) || !IsServer(acptr) ||
         acptr == cptr || IsMe(acptr))
       continue;
-    if (!match(me.name, cptr->name))
+    if (!match(cli_name(&me), cli_name(cptr)))
       continue;
-    sendcmdto_one(&me, CMD_SERVER, acptr, "%s 2 0 %Tu J%02u %s%s 0 :%s",
-                 cptr->name, cptr->serv->timestamp, Protocol(cptr),
-                 NumServCap(cptr), cptr->info);
+    if (ajupe)
+      sendcmdto_one(&me, CMD_SERVER, acptr,
+                    "%s 2 0 %Tu J%02u %s%s 0 %%%Tu :%s", cli_name(cptr),
+                    cli_serv(cptr)->timestamp, Protocol(cptr), NumServCap(cptr),
+                    JupeLastMod(ajupe), cli_info(cptr));
+    else
+      sendcmdto_one(&me, CMD_SERVER, acptr,
+                    "%s 2 0 %Tu J%02u %s%s 0 :%s", cli_name(cptr),
+                    cli_serv(cptr)->timestamp, Protocol(cptr), NumServCap(cptr),
+                    cli_info(cptr));
   }
 
   /*
@@ -212,9 +203,9 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
    * a race condition, not the normal way of operation...
    */
 
-  for (acptr = &me; acptr; acptr = acptr->prev) {
+  for (acptr = &me; acptr; acptr = cli_prev(acptr)) {
     /* acptr->from == acptr for acptr == cptr */
-    if (acptr->from == cptr)
+    if (cli_from(acptr) == cptr)
       continue;
     if (IsServer(acptr)) {
       const char* protocol_str;
@@ -224,34 +215,54 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
       else
         protocol_str = IsBurst(acptr) ? "J0" : "P0";
 
-      if (0 == match(me.name, acptr->name))
+      if (0 == match(cli_name(&me), cli_name(acptr)))
         continue;
       split = (MyConnect(acptr) && 
-               0 != ircd_strcmp(acptr->name, acptr->sockhost) &&
-               0 != ircd_strncmp(acptr->info, "JUPE", 4));
-      sendcmdto_one(acptr->serv->up, CMD_SERVER, cptr, "%s %d 0 %Tu %s%u "
-                   "%s%s 0 :%s", acptr->name, acptr->hopcount + 1,
-                   acptr->serv->timestamp, protocol_str, Protocol(acptr),
-                   NumServCap(acptr), acptr->info);
+               0 != ircd_strcmp(cli_name(acptr), cli_sockhost(acptr)) &&
+               0 != ircd_strncmp(cli_info(acptr), "JUPE", 4));
+      if ((ajupe = jupe_find(cli_name(acptr))) && !JupeIsLocal(ajupe))
+        sendcmdto_one(cli_serv(acptr)->up, CMD_SERVER, cptr,
+                      "%s %d 0 %Tu %s%u %s%s 0 %%%Tu :%s", cli_name(acptr),
+                      cli_hopcount(acptr) + 1, cli_serv(acptr)->timestamp,
+                      protocol_str, Protocol(acptr), NumServCap(acptr),
+                      JupeLastMod(ajupe), cli_info(acptr));
+      else
+        sendcmdto_one(cli_serv(acptr)->up, CMD_SERVER, cptr,
+                      "%s %d 0 %Tu %s%u %s%s 0 :%s", cli_name(acptr),
+                      cli_hopcount(acptr) + 1, cli_serv(acptr)->timestamp,
+                      protocol_str, Protocol(acptr), NumServCap(acptr),
+                      cli_info(acptr));
     }
   }
 
-  for (acptr = &me; acptr; acptr = acptr->prev)
+  for (acptr = &me; acptr; acptr = cli_prev(acptr))
   {
     /* acptr->from == acptr for acptr == cptr */
-    if (acptr->from == cptr)
+    if (cli_from(acptr) == cptr)
       continue;
     if (IsUser(acptr))
     {
       char xxx_buf[8];
       char *s = umode_str(acptr);
-      sendcmdto_one(acptr->user->server, CMD_NICK, cptr, *s ?
-                   "%s %d %Tu %s %s +%s %s %s%s :%s" :
-                   "%s %d %Tu %s %s %s%s %s%s :%s",
-                   acptr->name, acptr->hopcount + 1, acptr->lastnick,
-                   acptr->user->username, acptr->user->host, s,
-                   inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
-                   NumNick(acptr), acptr->info);
+      struct Gline *agline = 0;
+      if ((agline = gline_lookup(acptr, GLINE_GLOBAL | GLINE_LASTMOD)))
+        sendcmdto_one(cli_user(acptr)->server, CMD_NICK, cptr,
+                      "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
+                      cli_name(acptr), cli_hopcount(acptr) + 1, cli_lastnick(acptr),
+                      cli_user(acptr)->username, cli_user(acptr)->host,
+                      *s ? "+" : "", s, *s ? " " : "",
+                      GlineLastMod(agline), GlineUser(agline),
+                      GlineHost(agline),
+                      inttobase64(xxx_buf, ntohl(cli_ip(acptr).s_addr), 6),
+                      NumNick(acptr), cli_info(acptr));
+      else
+        sendcmdto_one(cli_user(acptr)->server, CMD_NICK, cptr,
+                      "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
+                      cli_name(acptr), cli_hopcount(acptr) + 1, cli_lastnick(acptr),
+                      cli_user(acptr)->username, cli_user(acptr)->host,
+                      *s ? "+" : "", s, *s ? " " : "",
+                      inttobase64(xxx_buf, ntohl(cli_ip(acptr).s_addr), 6),
+                      NumNick(acptr), cli_info(acptr));
     }
   }
   /*