2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_map.c: Sends an Undernet compatible map to a user.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "s_conf.h"
|
2007-11-23 23:38:54 +01:00
|
|
|
#include "scache.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
#define USER_COL 50 /* display | Users: %d at col 50 */
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char map_desc[] = "Provides the MAP command to view network topology information";
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message map_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"MAP", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 map_clist[] = { &map_msgtab, NULL };
|
2016-03-07 09:34:00 +01:00
|
|
|
|
2016-03-07 09:37:33 +01:00
|
|
|
DECLARE_MODULE_AV2(map, NULL, NULL, map_clist, NULL, NULL, NULL, NULL, map_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static void dump_map(struct Client *client_p, struct Client *root, char *pbuf);
|
2015-12-12 16:24:37 +01:00
|
|
|
static void flattened_map(struct Client *client_p);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
|
|
|
|
/* m_map
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) ||
|
|
|
|
ConfigFileEntry.map_oper_only)
|
|
|
|
{
|
2015-12-12 16:24:37 +01:00
|
|
|
flattened_map(client_p);
|
|
|
|
sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dump_map(client_p, &me, buf);
|
2007-04-03 12:11:06 +02:00
|
|
|
sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** mo_map
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
dump_map(client_p, &me, buf);
|
2007-11-23 23:38:54 +01:00
|
|
|
scache_send_missing(client_p);
|
2007-04-03 12:11:06 +02:00
|
|
|
sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** dump_map
|
|
|
|
** dumps server map, called recursively.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
|
|
|
|
{
|
2008-04-03 22:55:09 +02:00
|
|
|
int cnt = 0, i = 0, len, frac;
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Client *server_p;
|
2008-04-01 22:18:48 +02:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
*pbuf = '\0';
|
|
|
|
|
2008-04-20 06:44:04 +02:00
|
|
|
rb_strlcat(pbuf, root_p->name, BUFSIZE);
|
2007-01-25 07:40:21 +01:00
|
|
|
if (has_id(root_p))
|
|
|
|
{
|
2008-04-20 06:44:04 +02:00
|
|
|
rb_strlcat(pbuf, "[", BUFSIZE);
|
|
|
|
rb_strlcat(pbuf, root_p->id, BUFSIZE);
|
|
|
|
rb_strlcat(pbuf, "]", BUFSIZE);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
len = strlen(buf);
|
|
|
|
buf[len] = ' ';
|
|
|
|
|
|
|
|
if(len < USER_COL)
|
|
|
|
{
|
|
|
|
for (i = len + 1; i < USER_COL; i++)
|
|
|
|
{
|
|
|
|
buf[i] = '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-03 22:55:09 +02:00
|
|
|
frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total;
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(buf + USER_COL, BUFSIZE - USER_COL,
|
2008-04-03 22:55:09 +02:00
|
|
|
" | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users),
|
|
|
|
frac / 10, frac % 10);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2007-04-03 12:11:06 +02:00
|
|
|
sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(root_p->serv->servers.head != NULL)
|
|
|
|
{
|
2008-04-01 22:18:48 +02:00
|
|
|
cnt += rb_dlink_list_length(&root_p->serv->servers);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(cnt)
|
|
|
|
{
|
|
|
|
if(pbuf > buf + 3)
|
|
|
|
{
|
|
|
|
pbuf[-2] = ' ';
|
|
|
|
if(pbuf[-3] == '`')
|
|
|
|
pbuf[-3] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i = 1;
|
2008-04-01 22:18:48 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, root_p->serv->servers.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
server_p = ptr->data;
|
|
|
|
*pbuf = ' ';
|
|
|
|
if(i < cnt)
|
|
|
|
*(pbuf + 1) = '|';
|
|
|
|
else
|
|
|
|
*(pbuf + 1) = '`';
|
|
|
|
|
|
|
|
*(pbuf + 2) = '-';
|
|
|
|
*(pbuf + 3) = ' ';
|
|
|
|
dump_map(client_p, server_p, pbuf + 4);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2015-12-12 16:24:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2016-03-23 03:53:56 +01:00
|
|
|
unsigned long cnt = 0;
|
2015-12-12 16:24:37 +01:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2015-12-30 09:34:27 +01:00
|
|
|
rb_strlcat(buf, target_p->name, BUFSIZE);
|
2015-12-12 16:24:37 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|