Provide /stats F to report even defaulted feature values.
[ircu2.10.12-pk.git] / ircd / ircd_features.c
index fcf92f1d7d8cb4cbd7e646a8e5a1af74fcc531f3..baaa2bd0e146c1763d735681c8bf57bffed8060c 100644 (file)
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* @file
+/** @file
  * @brief Implementation of configurable feature support.
  * @version $Id$
  */
 #include "s_bsd.h"
 #include "s_debug.h"
 #include "s_misc.h"
+#include "s_stats.h"
 #include "send.h"
 #include "struct.h"
 #include "sys.h"    /* FALSE bleah */
 #include "whowas.h"    /* whowas_realloc */
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <stdlib.h>
 #include <string.h>
 
+struct Client his;
+
 /** List of log output types that can be set */
 static struct LogTypes {
   char *type; /**< Settable name. */
   int (*set)(const char *, const char *); /**< Function to set the value. */
-  char *(*get)(const char *); /**< Functino to get the value. */
+  char *(*get)(const char *); /**< Function to get the value. */
 } logTypes[] = {
   { "FILE", log_set_file, log_get_file },
   { "FACILITY", log_set_facility, log_get_facility },
@@ -160,6 +163,20 @@ feature_log_reset(struct Client* from, const char* const* fields, int count)
   return 0;
 }
 
+/** Handle an update to FEAT_HIS_SERVERNAME. */
+static void
+feature_notify_servername(void)
+{
+  ircd_strncpy(cli_name(&his), feature_str(FEAT_HIS_SERVERNAME), HOSTLEN);
+}
+
+/** Handle an update to FEAT_HIS_SERVERINFO. */
+static void
+feature_notify_serverinfo(void)
+{
+  ircd_strncpy(cli_info(&his), feature_str(FEAT_HIS_SERVERINFO), REALLEN);
+}
+
 /** Report the value of a log setting.
  * @param[in] from &Client asking for details.
  * @param[in] fields Array of parameters to get.
@@ -191,16 +208,27 @@ feature_log_get(struct Client* from, const char* const* fields, int count)
   }
 }
 
+/** Update whether #me is a hub or not.
+ */
+static void
+feature_notify_hub(void)
+{
+  if (feature_bool(FEAT_HUB))
+    SetHub(&me);
+  else
+    ClearHub(&me);
+}
+
 /** Sets a feature to the given value.
  * @param[in] from Client trying to set parameters.
- * @param[in] fields Array of paraters to set.
+ * @param[in] fields Array of parameters to set.
  * @param[in] count Number of fields in \a count.
  * @return <0 to clear the feature mark, 0 to leave it, >0 to set the feature mark.
  */
 typedef int  (*feat_set_call)(struct Client* from, const char* const* fields, int count);
 /** Gets the value of a feature.
  * @param[in] from Client trying to get parameters.
- * @param[in] fields Array of paraters to set.
+ * @param[in] fields Array of parameters to set.
  * @param[in] count Number of fields in \a count.
  */
 typedef void (*feat_get_call)(struct Client* from, const char* const* fields, int count);
@@ -282,7 +310,7 @@ static struct FeatureDesc {
   F_S(PROVIDER, FEAT_NULL, 0, 0),
   F_B(KILL_IPMISMATCH, FEAT_OPER, 0, 0),
   F_B(IDLE_FROM_MSG, 0, 1, 0),
-  F_B(HUB, 0, 0, 0),
+  F_B(HUB, 0, 0, feature_notify_hub),
   F_B(WALLOPS_OPER_ONLY, 0, 0, 0),
   F_B(NODNS, 0, 0, 0),
   F_N(RANDOM_SEED, FEAT_NODISP, random_seed_set, 0, 0, 0, 0, 0, 0),
@@ -293,8 +321,10 @@ static struct FeatureDesc {
   F_S(HIDDEN_IP, 0, "127.0.0.1", 0),
   F_B(CONNEXIT_NOTICES, 0, 0, 0),
   F_B(OPLEVELS, 0, 1, 0),
+  F_B(ZANNELS, 0, 1, 0),
   F_B(LOCAL_CHANNELS, 0, 1, 0),
   F_B(TOPIC_BURST, 0, 0, 0),
+  F_B(DISABLE_GLINES, 0, 0, 0),
 
   /* features that probably should not be touched */
   F_I(KILLCHASETIMELIMIT, 0, 30, 0),
@@ -316,6 +346,7 @@ static struct FeatureDesc {
   F_I(IPCHECK_CLONE_LIMIT, 0, 4, 0),
   F_I(IPCHECK_CLONE_PERIOD, 0, 40, 0),
   F_I(IPCHECK_CLONE_DELAY, 0, 600, 0),
+  F_I(CHANNELLEN, 0, 200, 0),
 
   /* Some misc. default paths */
   F_S(MPATH, FEAT_CASE | FEAT_MYOPER, "ircd.motd", motd_init),
@@ -342,16 +373,18 @@ static struct FeatureDesc {
   F_B(HIS_MAP, 0, 1, 0),
   F_B(HIS_LINKS, 0, 1, 0),
   F_B(HIS_TRACE, 0, 1, 0),
-  F_B(HIS_STATS_l, 0, 1, 0),
-  F_B(HIS_STATS_L, 0, 1, 0),
   F_B(HIS_STATS_a, 0, 1, 0),
   F_B(HIS_STATS_c, 0, 1, 0),
-  F_B(HIS_STATS_g, 0, 1, 0),
-  F_B(HIS_STATS_h, 0, 1, 0),
-  F_B(HIS_STATS_k, 0, 1, 0),
+  F_B(HIS_STATS_d, 0, 1, 0),
+  F_B(HIS_STATS_e, 0, 1, 0),
   F_B(HIS_STATS_f, 0, 1, 0),
+  F_B(HIS_STATS_g, 0, 1, 0),
   F_B(HIS_STATS_i, 0, 1, 0),
   F_B(HIS_STATS_j, 0, 1, 0),
+  F_B(HIS_STATS_J, 0, 1, 0),
+  F_B(HIS_STATS_k, 0, 1, 0),
+  F_B(HIS_STATS_l, 0, 1, 0),
+  F_B(HIS_STATS_L, 0, 1, 0),
   F_B(HIS_STATS_M, 0, 1, 0),
   F_B(HIS_STATS_m, 0, 1, 0),
   F_B(HIS_STATS_o, 0, 1, 0),
@@ -359,8 +392,6 @@ static struct FeatureDesc {
   F_B(HIS_STATS_q, 0, 1, 0),
   F_B(HIS_STATS_R, 0, 1, 0),
   F_B(HIS_STATS_r, 0, 1, 0),
-  F_B(HIS_STATS_d, 0, 1, 0),
-  F_B(HIS_STATS_e, 0, 1, 0),
   F_B(HIS_STATS_t, 0, 1, 0),
   F_B(HIS_STATS_T, 0, 1, 0),
   F_B(HIS_STATS_u, 0, 0, 0),
@@ -370,23 +401,26 @@ static struct FeatureDesc {
   F_B(HIS_STATS_x, 0, 1, 0),
   F_B(HIS_STATS_y, 0, 1, 0),
   F_B(HIS_STATS_z, 0, 1, 0),
+  F_B(HIS_STATS_IAUTH, 0, 1, 0),
   F_B(HIS_WHOIS_SERVERNAME, 0, 1, 0),
   F_B(HIS_WHOIS_IDLETIME, 0, 1, 0),
   F_B(HIS_WHOIS_LOCALCHAN, 0, 1, 0),
   F_B(HIS_WHO_SERVERNAME, 0, 1, 0),
   F_B(HIS_WHO_HOPCOUNT, 0, 1, 0),
+  F_B(HIS_MODEWHO, 0, 1, 0),
   F_B(HIS_BANWHO, 0, 1, 0),
   F_B(HIS_KILLWHO, 0, 1, 0),
   F_B(HIS_REWRITE, 0, 1, 0),
   F_I(HIS_REMOTE, 0, 1, 0),
   F_B(HIS_NETSPLIT, 0, 1, 0),
-  F_S(HIS_SERVERNAME, 0, "*.undernet.org", 0),
-  F_S(HIS_SERVERINFO, 0, "The Undernet Underworld", 0),
+  F_S(HIS_SERVERNAME, 0, "*.undernet.org", feature_notify_servername),
+  F_S(HIS_SERVERINFO, 0, "The Undernet Underworld", feature_notify_serverinfo),
   F_S(HIS_URLSERVERS, 0, "http://www.undernet.org/servers.php", 0),
 
   /* Misc. random stuff */
   F_S(NETWORK, 0, "UnderNet", 0),
   F_S(URL_CLIENTS, 0, "ftp://ftp.undernet.org/pub/irc/clients", 0),
+  F_S(URLREG, 0, "http://cservice.undernet.org/live/", 0),
 
 #undef F_S
 #undef F_B
@@ -568,6 +602,9 @@ feature_set(struct Client* from, const char* const* fields, int count)
 
     if (change && feat->notify) /* call change notify function */
       (*feat->notify)();
+
+    if (from)
+      return feature_get(from, fields, count);
   }
 
   return 0;
@@ -631,6 +668,9 @@ feature_reset(struct Client* from, const char* const* fields, int count)
 
     if (change && feat->notify) /* call change notify function */
       (*feat->notify)();
+
+    if (from)
+      return feature_get(from, fields, count);
   }
 
   return 0;
@@ -765,6 +805,11 @@ feature_init(void)
       break;
     }
   }
+
+  cli_magic(&his) = CLIENT_MAGIC;
+  cli_status(&his) = STAT_SERVER;
+  feature_notify_servername();
+  feature_notify_serverinfo();
 }
 
 /** Report all F-lines to a user.
@@ -775,6 +820,8 @@ feature_init(void)
 void
 feature_report(struct Client* to, const struct StatDesc* sd, char* param)
 {
+  char changed;
+  int report;
   int i;
 
   for (i = 0; features[i].type; i++) {
@@ -783,33 +830,36 @@ feature_report(struct Client* to, const struct StatDesc* sd, char* param)
        (features[i].flags & FEAT_OPER && !IsAnOper(to)))
       continue; /* skip this one */
 
+    changed = (features[i].flags & FEAT_MARK) ? 'F' : 'f';
+    report = (features[i].flags & FEAT_MARK) || sd->sd_funcdata;
+
     switch (features[i].flags & FEAT_MASK) {
     case FEAT_NONE:
       if (features[i].report) /* let the callback handle this */
-       (*features[i].report)(to, features[i].flags & FEAT_MARK ? 1 : 0);
+       (*features[i].report)(to, report);
       break;
 
 
     case FEAT_INT: /* Report an F-line with integer values */
-      if (features[i].flags & FEAT_MARK) /* it's been changed */
-       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %d",
-                  features[i].type, features[i].v_int);
+      if (report) /* it's been changed */
+       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "%c %s %d",
+                  changed, features[i].type, features[i].v_int);
       break;
 
     case FEAT_BOOL: /* Report an F-line with boolean values */
-      if (features[i].flags & FEAT_MARK) /* it's been changed */
-       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %s",
-                  features[i].type, features[i].v_int ? "TRUE" : "FALSE");
+      if (report) /* it's been changed */
+       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "%c %s %s",
+                  changed, features[i].type, features[i].v_int ? "TRUE" : "FALSE");
       break;
 
     case FEAT_STR: /* Report an F-line with string values */
-      if (features[i].flags & FEAT_MARK) { /* it's been changed */
+      if (report) { /* it's been changed */
        if (features[i].v_str)
-         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %s",
-                    features[i].type, features[i].v_str);
+         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "%c %s %s",
+                    changed, features[i].type, features[i].v_str);
        else /* Actually, F:<type> would reset it; you want F:<type>: */
-         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s",
-                    features[i].type);
+         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "%c %s",
+                    changed, features[i].type);
       }
       break;
     }