Author: ZenShadow
[ircu2.10.12-pk.git] / ircd / s_misc.c
index 4cb82723d4f1c5ac2ef781c69a2f44c7d457c227..82fb0648c11e78c0abac383caa98418831316191 100644 (file)
@@ -30,6 +30,7 @@
 #include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_log.h"
+#include "ircd_reply.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "match.h"
@@ -48,6 +49,7 @@
 #include "struct.h"
 #include "support.h"
 #include "sys.h"
+#include "uping.h"
 #include "userload.h"
 
 #include <assert.h>
@@ -58,7 +60,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static void exit_one_client(struct Client *, char *);
 
 static char *months[] = {
   "January", "February", "March", "April",
@@ -198,6 +199,110 @@ void get_sockhost(struct Client *cptr, char *host)
   ircd_strncpy(cptr->sockhost, s, HOSTLEN);
 }
 
+/*
+ * Exit one client, local or remote. Assuming for local client that
+ * all dependants already have been removed, and socket is closed.
+ *
+ * Rewritten by Run - 24 sept 94
+ *
+ * bcptr : client being (s)quitted
+ * sptr : The source (prefix) of the QUIT or SQUIT
+ *
+ * --Run
+ */
+static void exit_one_client(struct Client* bcptr, const char* comment)
+{
+  struct SLink *lp;
+
+  if (bcptr->serv && bcptr->serv->client_list)  /* Was SetServerYXX called ? */
+    ClearServerYXX(bcptr);      /* Removes server from server_list[] */
+  if (IsUser(bcptr)) {
+    /*
+     * clear out uping requests
+     */
+    if (IsUPing(bcptr))
+      uping_cancel(bcptr, 0);
+    /*
+     * Stop a running /LIST clean
+     */
+    if (MyUser(bcptr) && bcptr->listing) {
+      bcptr->listing->chptr->mode.mode &= ~MODE_LISTED;
+      MyFree(bcptr->listing);
+      bcptr->listing = NULL;
+    }
+    /*
+     * If a person is on a channel, send a QUIT notice
+     * to every client (person) on the same channel (so
+     * that the client can show the "**signoff" message).
+     * (Note: The notice is to the local clients *only*)
+     */
+    sendcmdto_common_channels(bcptr, CMD_QUIT, ":%s", comment);
+
+    remove_user_from_all_channels(bcptr);
+
+    /* Clean up invitefield */
+    while ((lp = bcptr->user->invited))
+      del_invite(bcptr, lp->value.chptr);
+
+    /* Clean up silencefield */
+    while ((lp = bcptr->user->silence))
+      del_silence(bcptr, lp->value.cp);
+
+    if (IsInvisible(bcptr))
+      --UserStats.inv_clients;
+    if (IsOper(bcptr))
+      --UserStats.opers;
+    if (MyConnect(bcptr))
+      Count_clientdisconnects(bcptr, UserStats);
+    else
+      Count_remoteclientquits(UserStats, bcptr);
+  }
+  else if (IsServer(bcptr))
+  {
+    /* Remove downlink list node of uplink */
+    remove_dlink(&bcptr->serv->up->serv->down, bcptr->serv->updown);
+    bcptr->serv->updown = 0;
+
+    if (MyConnect(bcptr))
+      Count_serverdisconnects(UserStats);
+    else
+      Count_remoteserverquits(UserStats);
+  }
+  else if (IsMe(bcptr))
+  {
+    sendto_opmask_butone(0, SNO_OLDSNO, "ERROR: tried to exit me! : %s",
+                        comment);
+    return;                     /* ...must *never* exit self! */
+  }
+  else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
+    Count_unknowndisconnects(UserStats);
+
+  /* Update IPregistry */
+  ip_registry_disconnect(bcptr);
+
+
+  /* 
+   * Remove from serv->client_list
+   * NOTE: user is *always* NULL if this is a server
+   */
+  if (bcptr->user) {
+    assert(!IsServer(bcptr));
+    /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
+    RemoveYXXClient(bcptr->user->server, bcptr->yxx);
+  }
+
+  /* Remove bcptr from the client list */
+#ifdef DEBUGMODE
+  if (hRemClient(bcptr) != 0)
+    Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p",
+          bcptr, bcptr->name, bcptr->from ? bcptr->from->sockhost : "??host",
+          bcptr->from, bcptr->next, bcptr->prev, bcptr->fd,
+          bcptr->status, bcptr->user));
+#else
+  hRemClient(bcptr);
+#endif
+  remove_client_from_list(bcptr);
+}
 /*
  * exit_downlinks - added by Run 25-9-94
  *
@@ -271,7 +376,7 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
     struct Client* victim,              /* Client being killed */
     struct Client* killer,              /* The client that made the decision
                                    to remove this one, never NULL */
-    char *comment)              /* Reason for the exit */
+    const char* comment)              /* Reason for the exit */
 {
   struct Client* acptr = 0;
   struct DLink *dlp;
@@ -282,25 +387,6 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
 
   if (MyConnect(victim)) {
     victim->flags |= FLAGS_CLOSING;
-#ifdef ALLOW_SNO_CONNEXIT
-#ifdef SNO_CONNEXIT_IP
-    if (IsUser(victim)) {
-      sprintf_irc(sendbuf,
-          ":%s NOTICE * :*** Notice -- Client exiting: %s (%s@%s) [%s] [%s]",
-          me.name, victim->name, victim->user->username, victim->user->host,
-          comment, ircd_ntoa((const char*) &victim->ip));
-      sendbufto_op_mask(SNO_CONNEXIT);
-    }
-#else /* SNO_CONNEXIT_IP */
-    if (IsUser(victim)) {
-      sprintf_irc(sendbuf,
-          ":%s NOTICE * :*** Notice -- Client exiting: %s (%s@%s) [%s]",
-          me.name, victim->name, victim->user->username, victim->user->host,
-          comment);
-      sendbufto_op_mask(SNO_CONNEXIT);
-    }
-#endif /* SNO_CONNEXIT_IP */
-#endif /* ALLOW_SNO_CONNEXIT */
     update_load();
 #ifdef FNAME_USERLOG
     on_for = CurrentTime - victim->firsttime;
@@ -323,11 +409,11 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
         && IsClient(victim))    /* Not a Ping struct or Log file */
     {
       if (IsServer(victim) || IsHandshake(victim))
-        sendto_one(victim, ":%s " TOK_SQUIT " %s 0 :%s", killer->name, me.name, comment);
+       sendcmdto_one(killer, CMD_SQUIT, victim, "%s 0 :%s", me.name, comment);
       else if (!IsConnecting(victim)) {
         if (!IsDead(victim))
-          sendto_one(victim, "ERROR :Closing Link: %s by %s (%s)",
-                     victim->name, killer->name, comment);
+         sendrawto_one(victim, MSG_ERROR " :Closing Link: %s by %s (%s)",
+                       victim->name, killer->name, comment);
       }
       if ((IsServer(victim) || IsHandshake(victim) || IsConnecting(victim)) &&
           (killer == &me || (IsServer(killer) &&
@@ -341,14 +427,9 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
         if (victim->serv->user && *victim->serv->by &&
             (acptr = findNUser(victim->serv->by))) {
           if (acptr->user == victim->serv->user) {
-            if (MyUser(acptr) || Protocol(acptr->from) < 10)
-              sendto_one(acptr,
-                         ":%s NOTICE %s :Link with %s cancelled: %s",
-                         me.name, acptr->name, victim->name, comment);
-            else
-              sendto_one(acptr,
-                         "%s NOTICE %s%s :Link with %s cancelled: %s",
-                         NumServ(&me), NumNick(acptr), victim->name, comment);
+           sendcmdto_one(&me, CMD_NOTICE, acptr,
+                         "%C :Link with %s cancelled: %s", acptr,
+                         victim->name, comment);
           }
           else {
             /*
@@ -359,8 +440,8 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
           }
         }
         if (killer == &me)
-          sendto_lops_butone(acptr, "Link with %s cancelled: %s",
-                             victim->name, comment);
+         sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s cancelled: %s",
+                              victim->name, comment);
       }
     }
     /*
@@ -375,14 +456,18 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
     strcat(comment1, " ");
     strcat(comment1, victim->name);
     if (IsUser(killer))
-      sendto_lops_butone(killer, "%s SQUIT by %s [%s]:",
-                         (killer->user->server == victim ||
-                         killer->user->server == victim->serv->up) ? "Local" : "Remote",
-                         get_client_name(killer, HIDE_IP), killer->user->server->name);
+      sendto_opmask_butone(killer, SNO_OLDSNO, "%s SQUIT by %s [%s]:",
+                          (killer->user->server == victim ||
+                           killer->user->server == victim->serv->up) ?
+                          "Local" : "Remote",
+                          get_client_name(killer, HIDE_IP),
+                          killer->user->server->name);
     else if (killer != &me && victim->serv->up != killer)
-      sendto_ops("Received SQUIT %s from %s :", victim->name,
-                 IsServer(killer) ? killer->name : get_client_name(killer, HIDE_IP));
-    sendto_op_mask(SNO_NETWORK, "Net break: %s (%s)", comment1, comment);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Received SQUIT %s from %s :",
+                          victim->name, IsServer(killer) ? killer->name :
+                          get_client_name(killer, HIDE_IP));
+    sendto_opmask_butone(0, SNO_NETWORK, "Net break: %s (%s)", comment1,
+                        comment);
   }
 
   /*
@@ -392,10 +477,10 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
   for (dlp = me.serv->down; dlp; dlp = dlp->next) {
     if (dlp->value.cptr != killer->from && dlp->value.cptr != victim) {
       if (IsServer(victim))
-        sendto_one(dlp->value.cptr, ":%s " TOK_SQUIT " %s " TIME_T_FMT " :%s",
-                   killer->name, victim->name, victim->serv->timestamp, comment);
+       sendcmdto_one(killer, CMD_SQUIT, dlp->value.cptr, "%s %Tu :%s",
+                     victim->name, victim->serv->timestamp, comment);
       else if (IsUser(victim) && 0 == (victim->flags & FLAGS_KILLED))
-        sendto_one(dlp->value.cptr, "%s%s " TOK_QUIT " :%s", NumNick(victim), comment);
+       sendcmdto_one(victim, CMD_QUIT, dlp->value.cptr, ":%s", comment);
     }
   }
   /* Then remove the client structures */
@@ -414,7 +499,7 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
  * Exit client with formatted message, added 25-9-94 by Run
  */
 int vexit_client_msg(struct Client *cptr, struct Client *bcptr, struct Client *sptr,
-    char *pattern, va_list vl)
+    const char *pattern, va_list vl)
 {
   char msgbuf[1024];
   vsprintf_irc(msgbuf, pattern, vl);
@@ -422,7 +507,7 @@ int vexit_client_msg(struct Client *cptr, struct Client *bcptr, struct Client *s
 }
 
 int exit_client_msg(struct Client *cptr, struct Client *bcptr,
-    struct Client *sptr, char *pattern, ...)
+    struct Client *sptr, const char *pattern, ...)
 {
   va_list vl;
   char msgbuf[1024];
@@ -434,108 +519,6 @@ int exit_client_msg(struct Client *cptr, struct Client *bcptr,
   return exit_client(cptr, bcptr, sptr, msgbuf);
 }
 
-/*
- * Exit one client, local or remote. Assuming for local client that
- * all dependants already have been removed, and socket is closed.
- *
- * Rewritten by Run - 24 sept 94
- *
- * bcptr : client being (s)quitted
- * sptr : The source (prefix) of the QUIT or SQUIT
- *
- * --Run
- */
-static void exit_one_client(struct Client *bcptr, char *comment)
-{
-  struct SLink *lp;
-
-  if (bcptr->serv && bcptr->serv->client_list)  /* Was SetServerYXX called ? */
-    ClearServerYXX(bcptr);      /* Removes server from server_list[] */
-  if (IsUser(bcptr)) {
-    /*
-     * Stop a running /LIST clean
-     */
-    if (MyUser(bcptr) && bcptr->listing) {
-      bcptr->listing->chptr->mode.mode &= ~MODE_LISTED;
-      MyFree(bcptr->listing);
-      bcptr->listing = NULL;
-    }
-    /*
-     * If a person is on a channel, send a QUIT notice
-     * to every client (person) on the same channel (so
-     * that the client can show the "**signoff" message).
-     * (Note: The notice is to the local clients *only*)
-     */
-    sendto_common_channels(bcptr, ":%s QUIT :%s", bcptr->name, comment);
-
-    remove_user_from_all_channels(bcptr);
-
-    /* Clean up invitefield */
-    while ((lp = bcptr->user->invited))
-      del_invite(bcptr, lp->value.chptr);
-
-    /* Clean up silencefield */
-    while ((lp = bcptr->user->silence))
-      del_silence(bcptr, lp->value.cp);
-
-    if (IsInvisible(bcptr))
-      --UserStats.inv_clients;
-    if (IsOper(bcptr))
-      --UserStats.opers;
-    if (MyConnect(bcptr))
-      Count_clientdisconnects(bcptr, UserStats);
-    else
-      Count_remoteclientquits(UserStats, bcptr);
-  }
-  else if (IsServer(bcptr))
-  {
-    /* Remove downlink list node of uplink */
-    remove_dlink(&bcptr->serv->up->serv->down, bcptr->serv->updown);
-    bcptr->serv->updown = 0;
-
-    if (MyConnect(bcptr))
-      Count_serverdisconnects(UserStats);
-    else
-      Count_remoteserverquits(UserStats);
-  }
-  else if (IsMe(bcptr))
-  {
-    sendto_ops("ERROR: tried to exit me! : %s", comment);
-    return;                     /* ...must *never* exit self! */
-  }
-  else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
-    Count_unknowndisconnects(UserStats);
-
-  /*
-   * Update IPregistry
-   */
-  if (IsIPChecked(bcptr))
-    IPcheck_disconnect(bcptr);
-
-  /* 
-   * Remove from serv->client_list
-   * NOTE: user is *always* NULL if this is a server
-   */
-  if (bcptr->user) {
-    assert(!IsServer(bcptr));
-    /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
-    RemoveYXXClient(bcptr->user->server, bcptr->yxx);
-  }
-
-  /* Remove bcptr from the client list */
-#ifdef DEBUGMODE
-  if (hRemClient(bcptr) != 0)
-    Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p",
-          bcptr, bcptr->name, bcptr->from ? bcptr->from->sockhost : "??host",
-          bcptr->from, bcptr->next, bcptr->prev, bcptr->fd,
-          bcptr->status, bcptr->user));
-#else
-  hRemClient(bcptr);
-#endif
-  remove_client_from_list(bcptr);
-}
-
-
 void initstats(void)
 {
   memset(&ircst, 0, sizeof(ircst));
@@ -596,29 +579,27 @@ void tstats(struct Client *cptr, char *name)
       sp->is_ni++;
   }
 
-  sendto_one(cptr, ":%s %d %s :accepts %u refused %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_ac, sp->is_ref);
-  sendto_one(cptr, ":%s %d %s :unknown commands %u prefixes %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_unco, sp->is_unpf);
-  sendto_one(cptr, ":%s %d %s :nick collisions %u unknown closes %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_kill, sp->is_ni);
-  sendto_one(cptr, ":%s %d %s :wrong direction %u empty %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_wrdi, sp->is_empt);
-  sendto_one(cptr, ":%s %d %s :numerics seen %u mode fakes %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_num, sp->is_fake);
-  sendto_one(cptr, ":%s %d %s :auth successes %u fails %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_asuc, sp->is_abad);
-  sendto_one(cptr, ":%s %d %s :local connections %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_loc);
-  sendto_one(cptr, ":%s %d %s :Client Server", me.name, RPL_STATSDEBUG, name);
-  sendto_one(cptr, ":%s %d %s :connected %u %u",
-      me.name, RPL_STATSDEBUG, name, sp->is_cl, sp->is_sv);
-  sendto_one(cptr, ":%s %d %s :bytes sent %u.%uK %u.%uK",
-      me.name, RPL_STATSDEBUG, name,
-      sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs);
-  sendto_one(cptr, ":%s %d %s :bytes recv %u.%uK %u.%uK",
-      me.name, RPL_STATSDEBUG, name,
-      sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr);
-  sendto_one(cptr, ":%s %d %s :time connected " TIME_T_FMT " " TIME_T_FMT,
-      me.name, RPL_STATSDEBUG, name, sp->is_cti, sp->is_sti);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":accepts %u refused %u",
+            sp->is_ac, sp->is_ref);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":unknown commands %u prefixes %u", sp->is_unco, sp->is_unpf);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":nick collisions %u unknown closes %u", sp->is_kill, sp->is_ni);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":wrong direction %u empty %u", sp->is_wrdi, sp->is_empt);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":numerics seen %u mode fakes %u", sp->is_num, sp->is_fake);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":auth successes %u fails %u", sp->is_asuc, sp->is_abad);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":local connections %u",
+            sp->is_loc);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Client server");
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":connected %u %u",
+            sp->is_cl, sp->is_sv);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %u.%uK %u.%uK",
+            sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %u.%uK %u.%uK",
+            sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Tu %Tu",
+            sp->is_cti, sp->is_sti);
 }