Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / s_serv.c
index 08b391d848409a8faee81851e46fd3dd53bf9f2a..4084c54229087e53a50724e81798606cf2c12a40 100644 (file)
 #include "channel.h"
 #include "client.h"
 #include "crule.h"
+#include "gline.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
+#include "ircd_snprintf.h"
 #include "ircd_xopen.h"
 #include "jupe.h"
 #include "list.h"
@@ -58,9 +60,9 @@
 
 unsigned int max_connection_count = 0;
 unsigned int max_client_count = 0;
-
-int exit_new_server(struct Client *cptr, struct Client *sptr,
-    char *host, time_t timestamp, char *fmt, ...)
+#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 =
@@ -69,13 +71,33 @@ int exit_new_server(struct Client *cptr, struct Client *sptr,
   va_start(vl, fmt);
   if (!IsServer(sptr))
     return vexit_client_msg(cptr, cptr, &me, fmt, vl);
-  sprintf_irc(buf, ":%s SQUIT %s " TIME_T_FMT " :", me.name, host, timestamp);
+  sprintf_irc(buf, ":%s " TOK_SQUIT " %s " TIME_T_FMT " :", me.name, host, timestamp);
   strcat(buf, fmt);
-  vsendto_one(cptr, buf, vl);
+  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, ...)
+{
+  struct VarData vd;
+  int retval = 0;
+
+  vd.vd_format = pattern;
+  va_start(vd.vd_args, pattern);
+
+  if (!IsServer(sptr))
+    retval = vexit_client_msg(cptr, cptr, &me, pattern, vd.vd_args);
+  else
+    sendcmdto_one(&me, CMD_SQUIT, cptr, "%s %Tu :%v", host, timestamp, &vd);
+
+  va_end(vd.vd_args);
+
+  return retval;
+}
 
 int a_kills_b_too(struct Client *a, struct Client *b)
 {
@@ -89,7 +111,8 @@ 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;
@@ -104,20 +127,13 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
 
   if (IsUnknown(cptr)) {
     if (aconf->passwd[0])
-      sendto_one(cptr, "PASS :%s", aconf->passwd);
+      sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
     /*
      *  Pass my info to the new server
      */
-    sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
-        me.name, me.serv->timestamp, cptr->serv->timestamp,
-        MAJOR_PROTOCOL, NumServCap(&me),
-        (me.info[0]) ? (me.info) : "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 
-     */
-    IPcheck_connect_fail(cptr->ip);
+    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");
   }
 
   det_confs_butmask(cptr, CONF_LEAF | CONF_HUB | CONF_SERVER | CONF_UWORLD);
@@ -141,12 +157,8 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
   if (cptr->serv->user && *cptr->serv->by &&
       (acptr = findNUser(cptr->serv->by))) {
     if (acptr->user == cptr->serv->user) {
-      if (MyUser(acptr))
-        sendto_one(acptr, ":%s NOTICE %s :Link with %s established.",
-                   me.name, acptr->name, inpath);
-      else
-        sendto_one(acptr, "%s NOTICE %s%s :Link with %s established.",
-                   NumServ(&me), NumNick(acptr), inpath);
+      sendcmdto_one(&me, CMD_NOTICE, acptr, "%C :Link with %s established.",
+                   acptr, inpath);
     }
     else {
       /*
@@ -157,10 +169,11 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
     }
   }
 
-  sendto_lops_butone(acptr, "Link with %s established.", inpath);
+  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_op_mask(SNO_NETWORK, "Net junction: %s %s", me.name, cptr->name);
+  sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", me.name,
+                      cptr->name);
   SetJunction(cptr);
   /*
    * Old sendto_serv_but_one() call removed because we now
@@ -174,20 +187,16 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
       continue;
     if (!match(me.name, cptr->name))
       continue;
-    if (split)
-    {
-        sendto_one(acptr, "%s " TOK_SERVER " %s 2 0 " TIME_T_FMT " %s%u %s%s 0 :%s",
-            NumServ(&me), cptr->name, cptr->serv->timestamp,
-            (Protocol(cptr) > 9) ? "J" : "J0", 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", cptr->name,
+                   cptr->serv->timestamp, Protocol(cptr), NumServCap(cptr),
+                   JupeLastMod(ajupe), cptr->info);
     else
-    {
-        sendto_one(acptr, "%s " TOK_SERVER " %s 2 0 " TIME_T_FMT " %s%u %s%s 0 :%s",
-            NumServ(&me), cptr->name, cptr->serv->timestamp,
-            (Protocol(cptr) > 9) ? "J" : "J0", Protocol(cptr),
-            NumServCap(cptr), cptr->info);
-    }
+      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);
   }
 
   /*
@@ -222,24 +231,18 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
       split = (MyConnect(acptr) && 
                0 != ircd_strcmp(acptr->name, acptr->sockhost) &&
                0 != ircd_strncmp(acptr->info, "JUPE", 4));
-      if (split)
-      {
-          sendto_one(cptr,
-              "%s " TOK_SERVER " %s %d 0 " TIME_T_FMT " %s%u %s%s 0 :%s",
-              NumServ(acptr->serv->up), acptr->name,
-              acptr->hopcount + 1, acptr->serv->timestamp,
-              protocol_str, Protocol(acptr),
-              NumServCap(acptr), acptr->info);
-      }
+      if ((ajupe = jupe_find(acptr->name)) && !JupeIsLocal(ajupe))
+       sendcmdto_one(acptr->serv->up, CMD_SERVER, cptr,
+                     "%s %d 0 %Tu %s%u %s%s 0 %%%Tu :%s", acptr->name,
+                     acptr->hopcount + 1, acptr->serv->timestamp,
+                     protocol_str, Protocol(acptr), NumServCap(acptr),
+                     JupeLastMod(ajupe), acptr->info);
       else
-      {
-          sendto_one(cptr,
-              "%s " TOK_SERVER " %s %d 0 " TIME_T_FMT " %s%u %s%s 0 :%s",
-              NumServ(acptr->serv->up), acptr->name,
-              acptr->hopcount + 1, acptr->serv->timestamp,
-              protocol_str, Protocol(acptr), 
-              NumServCap(acptr), acptr->info);
-      }
+       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);
     }
   }
 
@@ -252,14 +255,25 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
     {
       char xxx_buf[8];
       char *s = umode_str(acptr);
-      sendto_one(cptr, *s ?
-            "%s N %s %d " TIME_T_FMT " %s %s +%s %s %s%s :%s" :
-            "%s N %s %d " TIME_T_FMT " %s %s %s%s %s%s :%s",
-            NumServ(acptr->user->server),
-            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(acptr->user->server, CMD_NICK, cptr,
+                     "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
+                     acptr->name, acptr->hopcount + 1, acptr->lastnick,
+                     acptr->user->username, acptr->user->host,
+                     *s ? "+" : "", s, *s ? " " : "",
+                     GlineLastMod(agline), GlineUser(agline),
+                     GlineHost(agline),
+                     inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
+                     NumNick(acptr), acptr->info);
+      else
+       sendcmdto_one(acptr->user->server, CMD_NICK, cptr,
+                     "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
+                     acptr->name, acptr->hopcount + 1, acptr->lastnick,
+                     acptr->user->username, acptr->user->host,
+                     *s ? "+" : "", s, *s ? " " : "",
+                     inttobase64(xxx_buf, ntohl(acptr->ip.s_addr), 6),
+                     NumNick(acptr), acptr->info);
     }
   }
   /*
@@ -272,7 +286,8 @@ int server_estab(struct Client *cptr, struct ConfItem *aconf)
       send_channel_modes(cptr, chptr);
   }
   jupe_burst(cptr);
-  sendto_one(cptr, "%s EB", NumServ(&me));
+  gline_burst(cptr);
+  sendcmdto_one(&me, CMD_END_OF_BURST, cptr, "");
   return 0;
 }