IPv6 support (hopefully with fewer future transition pains)
[ircu2.10.12-pk.git] / ircd / s_misc.c
index 99ed512d81e0694881b0f5570857fb30ae6cddcb..16162a6de1ec40469fc6f874aa0cb8bb1ef21a66 100644 (file)
@@ -31,8 +31,9 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_auth.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"
@@ -47,6 +48,7 @@
 #include "s_bsd.h"
 #include "s_conf.h"
 #include "s_debug.h"
+#include "s_stats.h"
 #include "s_user.h"
 #include "send.h"
 #include "struct.h"
@@ -169,7 +171,8 @@ const char* get_client_name(const struct Client* sptr, int showip)
   if (MyConnect(sptr)) {
     if (showip)
       ircd_snprintf(0, nbuf, sizeof(nbuf), "%s[%s@%s]", cli_name(sptr),
-            (IsIdented(sptr)) ? cli_username(sptr) : "", cli_sock_ip(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))
@@ -289,6 +296,8 @@ static void exit_one_client(struct Client* bcptr, const char* comment)
     assert(!IsServer(bcptr));
     /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
     RemoveYXXClient(cli_user(bcptr)->server, cli_yxx(bcptr));
+    if (IsIAuthed(bcptr) || cli_iauth(bcptr))
+        iauth_exit_client(bcptr);
   }
 
   /* Remove bcptr from the client list */
@@ -385,17 +394,29 @@ 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] <%s%s>",
+                           cli_name(victim), cli_user(victim)->username,
+                           cli_user(victim)->host, comment,
+                           ircd_ntoa(&cli_ip(victim)),
+                           NumNick(victim) /* two %s's */);
     update_load();
 
     on_for = CurrentTime - cli_firsttime(victim);
 
     if (IsUser(victim))
-      log_write(LS_USER, L_TRACE, 0, "%s (%3d:%02d:%02d): %s@%s (%s)",
-               myctime(cli_firsttime(victim)), on_for / 3600,
-               (on_for % 3600) / 60, on_for % 60, cli_user(victim)->username,
-               cli_sockhost(victim), cli_name(victim));
+      log_write(LS_USER, L_TRACE, 0, "%Tu %i %s@%s %s %s %s%s %s :%s",
+               cli_firsttime(victim), on_for,
+               cli_user(victim)->username, cli_sockhost(victim),
+                ircd_ntoa(&cli_ip(victim)),
+                IsAccount(victim) ? cli_username(victim) : "0",
+                NumNick(victim), /* two %s's */
+                cli_name(victim), cli_info(victim));
 
     if (victim != cli_from(killer)  /* The source knows already */
         && IsClient(victim))    /* Not a Ping struct or Log file */
@@ -403,9 +424,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 +472,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 ||
@@ -471,11 +501,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);
     }
   }
@@ -520,7 +551,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;