]> jfr.im git - solanum.git/blobdiff - modules/m_map.c
buildsystem: honor $DESTDIR in install-data-hook
[solanum.git] / modules / m_map.c
index f8c87acfac4798692aa08a705b91a1c3b3642dad..2f8c7ad2b217bc9e55a63a394bbce2d7c44ddf5b 100644 (file)
 #include "numeric.h"
 #include "send.h"
 #include "s_conf.h"
-#include "sprintf_irc.h"
 #include "scache.h"
 
 #define USER_COL       50      /* display | Users: %d at col 50 */
 
-static int m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
-static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
 
 struct Message map_msgtab = {
-       "MAP", 0, 0, 0, MFLG_SLOW,
+       "MAP", 0, 0, 0, 0,
        {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}}
 };
 
@@ -45,19 +44,20 @@ mapi_clist_av1 map_clist[] = { &map_msgtab, NULL };
 DECLARE_MODULE_AV1(map, NULL, NULL, map_clist, NULL, NULL, "$Revision: 3368 $");
 
 static void dump_map(struct Client *client_p, struct Client *root, char *pbuf);
+static void flattened_map(struct Client *client_p);
 
 static char buf[BUFSIZE];
 
 /* m_map
-**     parv[0] = sender prefix
 */
 static int
-m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) ||
           ConfigFileEntry.map_oper_only)
        {
-               m_not_oper(client_p, source_p, parc, parv);
+               flattened_map(client_p);
+               sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
                return 0;
        }
 
@@ -68,10 +68,9 @@ m_map(struct Client *client_p, struct Client *source_p, int parc, const char *pa
 
 /*
 ** mo_map
-**      parv[0] = sender prefix
 */
 static int
-mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        dump_map(client_p, &me, buf);
        scache_send_missing(client_p);
@@ -87,17 +86,17 @@ mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *p
 static void
 dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
 {
-       int cnt = 0, i = 0, len;
+       int cnt = 0, i = 0, len, frac;
        struct Client *server_p;
        rb_dlink_node *ptr;
        *pbuf = '\0';
 
-       strlcat(pbuf, root_p->name, BUFSIZE);
+       rb_strlcat(pbuf, root_p->name, BUFSIZE);
        if (has_id(root_p))
        {
-               strlcat(pbuf, "[", BUFSIZE);
-               strlcat(pbuf, root_p->id, BUFSIZE);
-               strlcat(pbuf, "]", BUFSIZE);
+               rb_strlcat(pbuf, "[", BUFSIZE);
+               rb_strlcat(pbuf, root_p->id, BUFSIZE);
+               rb_strlcat(pbuf, "]", BUFSIZE);
        }
        len = strlen(buf);
        buf[len] = ' ';
@@ -110,9 +109,10 @@ dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
                }
        }
 
-       rb_snprintf(buf + USER_COL, BUFSIZE - USER_COL,
-                " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&root_p->serv->users),
-                100 * (float) rb_dlink_list_length(&root_p->serv->users) / (float) Count.total);
+       frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total;
+       snprintf(buf + USER_COL, BUFSIZE - USER_COL,
+                " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users),
+                frac / 10, frac % 10);
 
        sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
 
@@ -147,3 +147,75 @@ dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
                i++;
        }
 }
+
+/*
+ * flattened_map - display a version of map that doesn't give away routing
+ *                 information to users when flattened links is enabled.
+ */
+static void
+flattened_map(struct Client *client_p)
+{
+       char buf[BUFSIZE];
+       rb_dlink_node *ptr;
+       struct Client *target_p;
+       int i, len;
+       int cnt = 0;
+
+       /* First display me as the root */
+       rb_strlcpy(buf, me.name, BUFSIZE);
+       len = strlen(buf);
+       buf[len] = ' ';
+
+       if(len < USER_COL)
+       {
+               for (i = len + 1; i < USER_COL; i++)
+               {
+                       buf[i] = '-';
+               }
+       }
+
+       snprintf(buf + USER_COL, BUFSIZE - USER_COL,
+               " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&me.serv->users),
+               100 * (float) rb_dlink_list_length(&me.serv->users) / (float) Count.total);
+
+       sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
+
+       /* Next, we run through every other server and list them */
+       RB_DLINK_FOREACH(ptr, global_serv_list.head)
+       {
+               target_p = ptr->data;
+
+               cnt++;
+
+               /* Skip ourselves, it's already counted */
+               if(IsMe(target_p))
+                       continue;
+
+               /* if we're hidden, go on to the next leaf */
+               if(!ConfigServerHide.disable_hidden && IsHidden(target_p))
+                       continue;
+
+               if (cnt == rb_dlink_list_length(&global_serv_list))
+                       rb_strlcpy(buf, " `- ", BUFSIZE);
+               else
+                       rb_strlcpy(buf, " |- ", BUFSIZE);
+
+               rb_strlcat(buf, target_p->name, BUFSIZE);
+               len = strlen(buf);
+               buf[len] = ' ';
+
+               if(len < USER_COL)
+               {
+                       for (i = len + 1; i < USER_COL; i++)
+                       {
+                               buf[i] = '-';
+                       }
+               }
+
+               snprintf(buf + USER_COL, BUFSIZE - USER_COL,
+                       " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&target_p->serv->users),
+                       100 * (float) rb_dlink_list_length(&target_p->serv->users) / (float) Count.total);
+
+               sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
+       }
+}