6.3.1+customfmt patch

This patch will allow an administrator to define what format
user information is printed.  This information is shown in TRACE,
LTRACE, and some of the server notices.

The default for Hybrid 6 is "%s[%s@%s]", which has an issue with
the [ and ] characters appearing in the username.

Hybrid 7 uses "%s [%s@%s]", which disambiguates this and is
supported by current snapshots of TCM.

Other possible formats include "%s!%s@%s" and "%s(%s@%s)".  The
administrator is, of course, able to choose almost any format
he or she wishes, provided all fields are used and remain in
nick, username, hostname order.

-Hwy, 18 jan 2003
diff -uNrd ircd-hybrid-6.3.1.dist/include/config.h ircd-hybrid-6.3.1/include/config.h
--- ircd-hybrid-6.3.1.dist/include/config.h	Sun Feb 17 00:58:09 2002
+++ ircd-hybrid-6.3.1/include/config.h	Sat Jan 18 20:04:36 2003
@@ -191,6 +191,24 @@
  */
 #define  TS5_ONLY
 
+/* TRACE_USER_FMT
+ * This define lets you customize how users appear in TRACE and some of the
+ * server notices.  This setting allows an admin (providing the monitor
+ * bots permit) to disambiguate cases where [ can be part of the delimiters
+ * and a clients username.
+ *
+ * NOTE:  The order nick, username, hostname cannot be changed
+ * NOTE:  The default format is ambiguous but is needed for out-of-the-box
+ *        compatability with commonly used monitor bots and scripts.
+ *
+ * The standard Hybrid 6 format is "%s[%s@%s]"
+ * Current Hybrid 7 uses "%s [%s@%s]"
+ * A suggestion (and formerly used format) is "%s(%s@%s)"
+ * Another unambiguous option is "%s!%s@%s"
+ * The admin can use any other format he or she wishes.
+ */
+#define TRACE_USER_FMT "%s[%s@%s]"
+
 /* SLAVE_SERVERS - Use this to send LOCOPS and KLINES to servers you define
  * uses U: lines in ircd.conf, each server defined in an U: line
  * is sent a copy of the locally placed K-line, and will also
diff -uNrd ircd-hybrid-6.3.1.dist/include/config.h.dist ircd-hybrid-6.3.1/include/config.h.dist
--- ircd-hybrid-6.3.1.dist/include/config.h.dist	Sun Feb 17 00:58:09 2002
+++ ircd-hybrid-6.3.1/include/config.h.dist	Sat Jan 18 20:04:48 2003
@@ -191,6 +191,24 @@
  */
 #define  TS5_ONLY
 
+/* TRACE_USER_FMT
+ * This define lets you customize how users appear in TRACE and some of the
+ * server notices.  This setting allows an admin (providing the monitor
+ * bots permit) to disambiguate cases where [ can be part of the delimiters
+ * and a clients username.
+ *
+ * NOTE:  The order nick, username, hostname cannot be changed
+ * NOTE:  The default format is ambiguous but is needed for out-of-the-box
+ *        compatability with commonly used monitor bots and scripts.
+ *
+ * The standard Hybrid 6 format is "%s[%s@%s]"
+ * Current Hybrid 7 uses "%s [%s@%s]"
+ * A suggestion (and formerly used format) is "%s(%s@%s)"
+ * Another unambiguous option is "%s!%s@%s"
+ * The admin can use any other format he or she wishes.
+ */
+#define TRACE_USER_FMT "%s[%s@%s]"
+
 /* SLAVE_SERVERS - Use this to send LOCOPS and KLINES to servers you define
  * uses U: lines in ircd.conf, each server defined in an U: line
  * is sent a copy of the locally placed K-line, and will also
diff -uNrd ircd-hybrid-6.3.1.dist/include/s_misc.h ircd-hybrid-6.3.1/include/s_misc.h
--- ircd-hybrid-6.3.1.dist/include/s_misc.h	Thu Dec 13 18:16:34 2001
+++ ircd-hybrid-6.3.1/include/s_misc.h	Sat Jan 18 19:32:51 2003
@@ -18,6 +18,6 @@
 extern char    *small_file_date(time_t);
 
 extern char *make_isupport();
+extern char *trace_user_fmt(char *, char *, char *);
 #endif
-
 
diff -uNrd ircd-hybrid-6.3.1.dist/src/.depend ircd-hybrid-6.3.1/src/.depend
--- ircd-hybrid-6.3.1.dist/src/.depend	Thu Dec  6 23:13:29 2001
+++ ircd-hybrid-6.3.1/src/.depend	Sat Jan 18 19:57:55 2003
@@ -399,13 +399,13 @@
 s_log.o: s_log.c ../include/s_log.h ../include/irc_string.h \
  ../include/ircd_defs.h ../include/config.h ../include/setup.h \
  ../include/ircd.h ../include/s_misc.h
-s_misc.o: s_misc.c ../include/s_misc.h ../include/client.h \
+s_misc.o: s_misc.c ../include/s_misc.h ../include/channel.h \
  ../include/config.h ../include/setup.h ../include/ircd_defs.h \
- ../include/dbuf.h ../include/common.h ../include/irc_string.h \
- ../include/ircd.h ../include/numeric.h ../include/res.h \
- ../include/fileio.h ../include/../adns/adns.h ../include/s_bsd.h \
- ../include/s_conf.h ../include/motd.h ../include/s_serv.h \
- ../include/send.h ../include/struct.h
+ ../include/client.h ../include/dbuf.h ../include/common.h \
+ ../include/irc_string.h ../include/ircd.h ../include/numeric.h \
+ ../include/res.h ../include/fileio.h ../include/../adns/adns.h \
+ ../include/s_bsd.h ../include/s_conf.h ../include/motd.h \
+ ../include/s_serv.h ../include/send.h ../include/struct.h
 s_serv.o: s_serv.c ../include/s_serv.h ../include/config.h \
  ../include/setup.h ../include/channel.h ../include/ircd_defs.h \
  ../include/class.h ../include/client.h ../include/dbuf.h \
@@ -430,8 +430,9 @@
  ../include/motd.h ../include/msg.h ../include/numeric.h \
  ../include/s_bsd.h ../include/res.h ../include/fileio.h \
  ../include/../adns/adns.h ../include/s_conf.h ../include/s_log.h \
- ../include/s_serv.h ../include/s_stats.h ../include/scache.h \
- ../include/send.h ../include/struct.h ../include/whowas.h
+ ../include/s_misc.h ../include/s_serv.h ../include/s_stats.h \
+ ../include/scache.h ../include/send.h ../include/struct.h \
+ ../include/whowas.h
 s_zip.o: s_zip.c ../include/client.h ../include/config.h \
  ../include/setup.h ../include/ircd_defs.h ../include/dbuf.h \
  ../include/s_zip.h ../include/irc_string.h ../include/packet.h \
@@ -451,7 +452,7 @@
  ../include/res.h ../include/fileio.h ../include/../adns/adns.h \
  ../include/s_serv.h ../include/s_zip.h ../include/sprintf_irc.h \
  ../include/struct.h ../include/s_conf.h ../include/motd.h \
- ../include/s_debug.h ../include/s_log.h
+ ../include/s_debug.h ../include/s_log.h ../include/s_misc.h
 sprintf_irc.o: sprintf_irc.c ../include/sprintf_irc.h
 whowas.o: whowas.c ../include/whowas.h ../include/ircd_defs.h \
  ../include/config.h ../include/setup.h ../include/client.h \
diff -uNrd ircd-hybrid-6.3.1.dist/src/client.c ircd-hybrid-6.3.1/src/client.c
--- ircd-hybrid-6.3.1.dist/src/client.c	Sun Feb 17 00:58:13 2002
+++ ircd-hybrid-6.3.1/src/client.c	Sat Jan 18 19:51:46 2003
@@ -1114,17 +1114,29 @@
         {
           case SHOW_IP:
 #ifndef SERVERHIDE
-            ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
-              client->sockhost);
+            if (IsPerson(client))
+              ircsprintf(nbuf, TRACE_USER_FMT, client->name, client->username,
+                client->sockhost);
+            else
+              ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
+                client->sockhost);
             break;
 #endif
           case MASK_IP:
-            ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
-              client->username);
+            if (IsPerson(client))
+              ircsprintf(nbuf, TRACE_USER_FMT, client->name, client->username,
+                "255.255.255.255");
+            else
+              ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
+                client->username);
             break;
           default:
-            ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
-              client->host);
+            if (IsPerson(client))
+              ircsprintf(nbuf, TRACE_USER_FMT, client->name, client->username,
+                client->host);
+            else
+              ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
+                client->host);
         }
       return nbuf;
     }
@@ -1147,9 +1159,13 @@
     return get_client_name(client, FALSE);
   else
     {
-      ircsprintf(nbuf, "%s[%-.*s@%-.*s]",
-                 client->name, USERLEN, client->username,
-                 HOSTLEN, client->host);
+      if (IsPerson(client))
+        ircsprintf(nbuf, TRACE_USER_FMT, client->name, client->username,
+          client->host);
+      else
+        ircsprintf(nbuf, "%s[%-.*s@%-.*s]",
+                   client->name, USERLEN, client->username,
+                   HOSTLEN, client->host);
     }
   return nbuf;
 }
diff -uNrd ircd-hybrid-6.3.1.dist/src/s_misc.c ircd-hybrid-6.3.1/src/s_misc.c
--- ircd-hybrid-6.3.1.dist/src/s_misc.c	Sun Feb 17 13:16:03 2002
+++ ircd-hybrid-6.3.1/src/s_misc.c	Sat Jan 18 19:31:32 2003
@@ -225,4 +225,17 @@
   return tisupport;
 }
 
+/* Return a pointer to a static string, containing the user specified
+ * nick!user@host format for TRACE and a few other functions.
+ */
+char *trace_user_fmt(char *nick, char *username, char *hostname)
+{
+  /* At LEAST 5 extra bytes are needed, to fit "nick [user@host]" and the
+  ** terminating \0.  10 extra should be sufficient.
+  */
+  static char userbuf[NICKLEN + USERLEN + HOSTLEN + 10];
+
+  ircsprintf(userbuf, TRACE_USER_FMT, nick, username, hostname);
 
+  return userbuf;
+}
diff -uNrd ircd-hybrid-6.3.1.dist/src/s_user.c ircd-hybrid-6.3.1/src/s_user.c
--- ircd-hybrid-6.3.1.dist/src/s_user.c	Wed Jan 23 13:39:08 2002
+++ ircd-hybrid-6.3.1/src/s_user.c	Sat Jan 18 19:55:31 2003
@@ -41,6 +41,7 @@
 #include "s_bsd.h"
 #include "s_conf.h"
 #include "s_log.h"
+#include "s_misc.h"
 #include "s_serv.h"
 #include "s_stats.h"
 #include "scache.h"
@@ -876,9 +877,10 @@
                      ":%s KILL %s :%s GHOST (no server %s on the net)",
                      me.name,
                      sptr->name, me.name, user->server);
-          sendto_realops("No server %s for user %s[%s@%s] from %s",
-                          user->server, sptr->name, sptr->username,
-                          sptr->host, sptr->from->name);
+          sendto_realops("No server %s for user %s from %s",
+                          user->server,
+                          trace_user_fmt(sptr->name, sptr->username,
+                          sptr->host), sptr->from->name);
           sptr->flags |= FLAGS_KILLED;
           return exit_client(sptr, sptr, &me, "Ghosted Client");
         }
diff -uNrd ircd-hybrid-6.3.1.dist/src/send.c ircd-hybrid-6.3.1/src/send.c
--- ircd-hybrid-6.3.1.dist/src/send.c	Sat Feb  2 15:58:30 2002
+++ ircd-hybrid-6.3.1/src/send.c	Sat Jan 18 19:57:32 2003
@@ -36,6 +36,7 @@
 #include "s_conf.h"
 #include "s_debug.h"
 #include "s_log.h"
+#include "s_misc.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -1314,14 +1315,15 @@
           return;
         }
 
-      sendto_realops("Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
-                 to->name, to->username, to->host,
-                 from->name, from->username, from->host,
+      sendto_realops("Ghosted: %s from %s (%s)",
+                 trace_user_fmt(to->name, to->username, to->host),
+                 trace_user_fmt(from->name, from->username, from->host),
                  to->from->name);
       
-      sendto_serv_butone(NULL, ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
-                         me.name, to->name, me.name, to->name,
-                         to->username, to->host, to->from->name);
+      sendto_serv_butone(NULL, ":%s KILL %s :%s (%s Ghosted %s)",
+                         me.name, to->name, me.name,
+                         trace_user_fmt(to->name, to->username, to->host),
+                         to->from->name);
 
       to->flags |= FLAGS_KILLED;
 
