]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_map.c
ShadowIRCd 6.2.0-beta1
[irc/rqf/shadowircd.git] / modules / m_map.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_map.c: Sends an Undernet compatible map to a user.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
212380e3 22 */
23
24#include "stdinc.h"
25#include "client.h"
26#include "modules.h"
27#include "numeric.h"
28#include "send.h"
29#include "s_conf.h"
c0bc9fe3 30#include "scache.h"
212380e3 31
32#define USER_COL 50 /* display | Users: %d at col 50 */
33
34static int m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
35static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
36
37struct Message map_msgtab = {
38 "MAP", 0, 0, 0, MFLG_SLOW,
39 {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}}
40};
41
42mapi_clist_av1 map_clist[] = { &map_msgtab, NULL };
88520303 43DECLARE_MODULE_AV1(map, NULL, NULL, map_clist, NULL, NULL, "$Revision: 3368 $");
212380e3 44
45static void dump_map(struct Client *client_p, struct Client *root, char *pbuf);
46
47static char buf[BUFSIZE];
48
49/* m_map
212380e3 50*/
51static int
52m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
53{
54 if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) ||
55 ConfigFileEntry.map_oper_only)
56 {
57 m_not_oper(client_p, source_p, parc, parv);
58 return 0;
59 }
60
61 dump_map(client_p, &me, buf);
88520303 62 sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
212380e3 63 return 0;
64}
65
66/*
67** mo_map
212380e3 68*/
69static int
70mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
71{
72 dump_map(client_p, &me, buf);
c0bc9fe3 73 scache_send_missing(client_p);
88520303 74 sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
212380e3 75
76 return 0;
77}
78
79/*
80** dump_map
81** dumps server map, called recursively.
82*/
83static void
84dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
85{
d76c16d4 86 int cnt = 0, i = 0, len, frac;
212380e3 87 struct Client *server_p;
08d11e34 88 rb_dlink_node *ptr;
212380e3 89 *pbuf = '\0';
90
a64c5173 91 rb_strlcat(pbuf, root_p->name, BUFSIZE);
212380e3 92 if (has_id(root_p))
93 {
a64c5173
VY
94 rb_strlcat(pbuf, "[", BUFSIZE);
95 rb_strlcat(pbuf, root_p->id, BUFSIZE);
96 rb_strlcat(pbuf, "]", BUFSIZE);
212380e3 97 }
98 len = strlen(buf);
99 buf[len] = ' ';
100
101 if(len < USER_COL)
102 {
103 for (i = len + 1; i < USER_COL; i++)
104 {
105 buf[i] = '-';
106 }
107 }
108
d76c16d4 109 frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total;
581fa5c4 110 rb_snprintf(buf + USER_COL, BUFSIZE - USER_COL,
d76c16d4
JT
111 " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users),
112 frac / 10, frac % 10);
212380e3 113
88520303 114 sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
212380e3 115
116 if(root_p->serv->servers.head != NULL)
117 {
08d11e34 118 cnt += rb_dlink_list_length(&root_p->serv->servers);
212380e3 119
120 if(cnt)
121 {
122 if(pbuf > buf + 3)
123 {
124 pbuf[-2] = ' ';
125 if(pbuf[-3] == '`')
126 pbuf[-3] = ' ';
127 }
128 }
129 }
130 i = 1;
08d11e34 131 RB_DLINK_FOREACH(ptr, root_p->serv->servers.head)
212380e3 132 {
133 server_p = ptr->data;
134 *pbuf = ' ';
135 if(i < cnt)
136 *(pbuf + 1) = '|';
137 else
138 *(pbuf + 1) = '`';
139
140 *(pbuf + 2) = '-';
141 *(pbuf + 3) = ' ';
142 dump_map(client_p, server_p, pbuf + 4);
143
144 i++;
145 }
146}