Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_misc.c
index a21707544bef90f899b106f03d1c3007ae30fc1a..766043286ef5dd312a743f50f500bb89d4b95f55 100644 (file)
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_features.h"
 #include "ircd_log.h"
-#include "ircd_policy.h"
 #include "ircd_reply.h"
+#include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "list.h"
+#include "map.h"
 #include "match.h"
 #include "msg.h"
 #include "numeric.h"
@@ -46,9 +48,9 @@
 #include "s_bsd.h"
 #include "s_conf.h"
 #include "s_debug.h"
+#include "s_stats.h"
 #include "s_user.h"
 #include "send.h"
-#include "sprintf_irc.h"
 #include "struct.h"
 #include "support.h"
 #include "sys.h"
@@ -168,8 +170,9 @@ const char* get_client_name(const struct Client* sptr, int showip)
 
   if (MyConnect(sptr)) {
     if (showip)
-      sprintf_irc(nbuf, "%s[%s@%s]", cli_name(sptr),
-            (IsIdented(sptr)) ? cli_username(sptr) : "", cli_sock_ip(sptr));
+      ircd_snprintf(0, nbuf, sizeof(nbuf), "%s[%s@%s]", cli_name(sptr),
+                    IsIdented(sptr) ? cli_username(sptr) : "unknown",
+                    cli_sock_ip(sptr));
     else
         return cli_name(sptr);
     return nbuf;
@@ -233,7 +236,7 @@ static void exit_one_client(struct Client* bcptr, const char* comment)
      * 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);
+    sendcmdto_common_channels_butone(bcptr, CMD_QUIT, NULL, ":%s", comment);
 
     remove_user_from_all_channels(bcptr);
 
@@ -245,6 +248,10 @@ static void exit_one_client(struct Client* bcptr, const char* comment)
     while ((lp = cli_user(bcptr)->silence))
       del_silence(bcptr, lp->value.cp);
 
+    /* Clean up snotice lists */
+    if (MyUser(bcptr))
+      set_snomask(bcptr, ~0, SNO_DEL);
+
     if (IsInvisible(bcptr))
       --UserStats.inv_clients;
     if (IsOper(bcptr))
@@ -385,8 +392,16 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
 
   char comment1[HOSTLEN + HOSTLEN + 2];
   assert(killer);
-  if (MyConnect(victim)) {
-    cli_flags(victim) |= FLAGS_CLOSING;
+  if (MyConnect(victim))
+  {
+    SetFlag(victim, FLAG_CLOSING);
+
+    if (feature_bool(FEAT_CONNEXIT_NOTICES) && IsUser(victim))
+      sendto_opmask_butone(0, SNO_CONNEXIT,
+                           "Client exiting: %s (%s@%s) [%s] [%s]",
+                           cli_name(victim), cli_user(victim)->username,
+                           cli_user(victim)->host, comment,
+                           ircd_ntoa((const char*) &(cli_ip(victim))));
     update_load();
 
     on_for = CurrentTime - cli_firsttime(victim);
@@ -403,9 +418,16 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
       if (IsServer(victim) || IsHandshake(victim))
        sendcmdto_one(killer, CMD_SQUIT, victim, "%s 0 :%s", cli_name(&me), comment);
       else if (!IsConnecting(victim)) {
-        if (!IsDead(victim))
-         sendrawto_one(victim, MSG_ERROR " :Closing Link: %s by %s (%s)",
-                       cli_name(victim), cli_name(killer), comment);
+        if (!IsDead(victim)) {
+         if (IsServer(victim))
+           sendcmdto_one(killer, CMD_ERROR, victim,
+                         ":Closing Link: %s by %s (%s)", cli_name(victim),
+                         cli_name(killer), comment);
+         else
+           sendrawto_one(victim, MSG_ERROR " :Closing Link: %s by %s (%s)",
+                         cli_name(victim), IsServer(killer) ? cli_name(&me) :
+                         cli_name(killer), comment);
+       }
       }
       if ((IsServer(victim) || IsHandshake(victim) || IsConnecting(victim)) &&
           (killer == &me || (IsServer(killer) &&
@@ -444,13 +466,15 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
 
   if (IsServer(victim))
   {
-#ifdef HEAD_IN_SAND_NETSPLIT
-    strcpy(comment1, "*.net *.split");
-#else
-    strcpy(comment1, cli_name(cli_serv(victim)->up));
-    strcat(comment1, " ");
-    strcat(comment1, cli_name(victim));
-#endif
+    if (feature_bool(FEAT_HIS_NETSPLIT))
+      strcpy(comment1, "*.net *.split");
+    else
+    {
+      strcpy(comment1, cli_name(cli_serv(victim)->up));
+      strcat(comment1, " ");
+      strcat(comment1, cli_name(victim));
+    }
+
     if (IsUser(killer))
       sendto_opmask_butone(killer, SNO_OLDSNO, "%s SQUIT by %s [%s]:",
                           (cli_user(killer)->server == victim ||
@@ -462,8 +486,11 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
       sendto_opmask_butone(0, SNO_OLDSNO, "Received SQUIT %s from %s :",
                           cli_name(victim), IsServer(killer) ? cli_name(killer) :
                           get_client_name(killer, HIDE_IP));
-    sendto_opmask_butone(0, SNO_NETWORK, "Net break: %s (%s)", comment1,
-                        comment);
+    sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
+                        cli_serv(victim)->up, victim, comment);
+
+    if (feature_bool(FEAT_HIS_MAP) || feature_bool(FEAT_HIS_LINKS))
+      map_update(victim);
   }
 
   /*
@@ -471,11 +498,12 @@ int exit_client(struct Client *cptr,    /* Connection being handled by
    * except the source:
    */
   for (dlp = cli_serv(&me)->down; dlp; dlp = dlp->next) {
-    if (dlp->value.cptr != cli_from(killer) && dlp->value.cptr != victim) {
+    if (dlp->value.cptr != cli_from(killer) && dlp->value.cptr != victim)
+    {
       if (IsServer(victim))
        sendcmdto_one(killer, CMD_SQUIT, dlp->value.cptr, "%s %Tu :%s",
                      cli_name(victim), cli_serv(victim)->timestamp, comment);
-      else if (IsUser(victim) && 0 == (cli_flags(victim) & FLAGS_KILLED))
+      else if (IsUser(victim) && !HasFlag(victim, FLAG_KILLED))
        sendcmdto_one(victim, CMD_QUIT, dlp->value.cptr, ":%s", comment);
     }
   }
@@ -498,7 +526,7 @@ int vexit_client_msg(struct Client *cptr, struct Client *bcptr, struct Client *s
     const char *pattern, va_list vl)
 {
   char msgbuf[1024];
-  vsprintf_irc(msgbuf, pattern, vl);
+  ircd_vsnprintf(0, msgbuf, sizeof(msgbuf), pattern, vl);
   return exit_client(cptr, bcptr, sptr, msgbuf);
 }
 
@@ -509,7 +537,7 @@ int exit_client_msg(struct Client *cptr, struct Client *bcptr,
   char msgbuf[1024];
 
   va_start(vl, pattern);
-  vsprintf_irc(msgbuf, pattern, vl);
+  ircd_vsnprintf(0, msgbuf, sizeof(msgbuf), pattern, vl);
   va_end(vl);
 
   return exit_client(cptr, bcptr, sptr, msgbuf);
@@ -520,7 +548,7 @@ void initstats(void)
   memset(&ircst, 0, sizeof(ircst));
 }
 
-void tstats(struct Client *cptr, char *name)
+void tstats(struct Client *cptr, struct StatDesc *sd, int stat, char *param)
 {
   struct Client *acptr;
   int i;