added basic ssl support to ircu
[ircu2.10.12-pk.git] / ircd / userload.c
index b972025f67b54fa61e14b5fa20b1b40f2183c0be..6bc641b788cf69a7b7eb035d538435fa4ff41f63 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Userload module by Michael L. VanLoon (mlv) <michaelv@iastate.edu>
  * Written 2/93.  Originally grafted into irc2.7.2g 4/93.
- * 
+ *
  * Rewritten 9/97 by Carlo Wood (Run) <carlo@runaway.xs4all.nl>
  * because previous version used ridiculous amounts of memory
  * (stored all loads of the passed three days ~ 8 megs).
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
  */
+/** @file
+ * @brief Userload tracking and statistics.
+ * @version $Id$
+ */
+#include "config.h"
+
 #include "userload.h"
 #include "client.h"
 #include "ircd.h"
+#include "msg.h"
 #include "numnicks.h"
 #include "querycmds.h"
 #include "s_misc.h"
+#include "s_stats.h"
 #include "send.h"
 #include "struct.h"
 #include "sys.h"
 
 #include <stdio.h>
 #include <string.h>
-#include <sys/time.h>
+#include <time.h>
 
-struct current_load_st current_load;    /* The current load */
+struct current_load_st current_load;    /**< The current load */
 
-static struct current_load_st cspm_sum; /* Number of connections times number
+static struct current_load_st cspm_sum; /**< Number of connections times number
                                            of seconds per minute. */
-static struct current_load_st csph_sum; /* Number of connections times number
+static struct current_load_st csph_sum; /**< Number of connections times number
                                            of seconds per hour. */
-static struct current_load_st cspm[60]; /* Last 60 minutes */
-static struct current_load_st csph[72]; /* Last 72 hours */
+static struct current_load_st cspm[60]; /**< Last 60 minutes */
+static struct current_load_st csph[72]; /**< Last 72 hours */
 
-static int m_index, h_index;    /* Array indexes */
+static int m_index; /**< Next entry to use in #cspm. */
+static int h_index; /**< Next entry to use in #csph. */
 
-/*
- * update_load
- *
- * A new connection was added or removed.
+/** Update load average to reflect a change in the local client count.
  */
 void update_load(void)
 {
@@ -197,7 +201,13 @@ void update_load(void)
   last = CurrentTime;
 }
 
-void calc_load(struct Client *sptr)
+/** Statistics callback to display userload.
+ * @param[in] sptr Client requesting statistics.
+ * @param[in] sd Stats descriptor for request (ignored).
+ * @param[in] param Extra parameter from user (ignored).
+ */
+void
+calc_load(struct Client *sptr, const struct StatDesc *sd, char *param)
 {
   /* *INDENT-OFF* */
   static const char *header =
@@ -243,31 +253,16 @@ void calc_load(struct Client *sptr)
     times[i][2] /= 86400;
   }
 
-  if (MyUser(sptr) || Protocol(sptr->from) < 10)
-  {
-    sendto_one(sptr, ":%s NOTICE %s :%s", me.name, sptr->name, header);
-    for (i = 0; i < 3; ++i)
-      sendto_one(sptr,
-          ":%s NOTICE %s :%4d.%1d  %4d.%1d  %4d  %4d  %4d   %s",
-          me.name, sptr->name,
-          times[0][i] / 10, times[0][i] % 10,
-          times[1][i] / 10, times[1][i] % 10,
-          times[2][i], times[3][i], times[4][i], what[i]);
-  }
-  else
-  {
-    sendto_one(sptr, "%s NOTICE %s%s :%s",
-        NumServ(&me), NumNick(sptr), header);
-    for (i = 0; i < 3; ++i)
-      sendto_one(sptr,
-          "%s NOTICE %s%s :%4d.%1d  %4d.%1d  %4d  %4d  %4d   %s",
-          NumServ(&me), NumNick(sptr),
-          times[0][i] / 10, times[0][i] % 10,
-          times[1][i] / 10, times[1][i] % 10,
-          times[2][i], times[3][i], times[4][i], what[i]);
-  }
+  sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, header);
+  for (i = 0; i < 3; ++i)
+    sendcmdto_one(&me, CMD_NOTICE, sptr,
+                 "%C :%4d.%1d  %4d.%1d  %4d  %4d  %4d   %s", sptr,
+                 times[0][i] / 10, times[0][i] % 10,
+                 times[1][i] / 10, times[1][i] % 10,
+                 times[2][i], times[3][i], times[4][i], what[i]);
 }
 
+/** Initialize the userload statistics. */
 void initload(void)
 {
   memset(&current_load, 0, sizeof(current_load));