]> jfr.im git - solanum.git/blame - modules/m_map.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_map.c
CommitLineData
212380e3
AC
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 *
88520303 22 * $Id: m_map.c 3368 2007-04-03 10:11:06Z nenolod $
212380e3
AC
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "modules.h"
28#include "numeric.h"
29#include "send.h"
30#include "s_conf.h"
c0bc9fe3 31#include "scache.h"
212380e3
AC
32
33#define USER_COL 50 /* display | Users: %d at col 50 */
34
428ca87b
AC
35static int m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
36static int mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
212380e3
AC
37
38struct Message map_msgtab = {
7baa37a9 39 "MAP", 0, 0, 0, 0,
212380e3
AC
40 {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}}
41};
42
43mapi_clist_av1 map_clist[] = { &map_msgtab, NULL };
88520303 44DECLARE_MODULE_AV1(map, NULL, NULL, map_clist, NULL, NULL, "$Revision: 3368 $");
212380e3
AC
45
46static void dump_map(struct Client *client_p, struct Client *root, char *pbuf);
e1fda0d8 47static void flattened_map(struct Client *client_p);
212380e3
AC
48
49static char buf[BUFSIZE];
50
51/* m_map
212380e3
AC
52*/
53static int
428ca87b 54m_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
55{
56 if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) ||
57 ConfigFileEntry.map_oper_only)
58 {
e1fda0d8
AC
59 flattened_map(client_p);
60 sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
212380e3
AC
61 return 0;
62 }
63
64 dump_map(client_p, &me, buf);
88520303 65 sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
212380e3
AC
66 return 0;
67}
68
69/*
70** mo_map
212380e3
AC
71*/
72static int
428ca87b 73mo_map(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
74{
75 dump_map(client_p, &me, buf);
c0bc9fe3 76 scache_send_missing(client_p);
88520303 77 sendto_one_numeric(client_p, RPL_MAPEND, form_str(RPL_MAPEND));
212380e3
AC
78
79 return 0;
80}
81
82/*
83** dump_map
84** dumps server map, called recursively.
85*/
86static void
87dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
88{
28d337da 89 int cnt = 0, i = 0, len, frac;
212380e3 90 struct Client *server_p;
5b96d9a6 91 rb_dlink_node *ptr;
212380e3
AC
92 *pbuf = '\0';
93
1f9de103 94 rb_strlcat(pbuf, root_p->name, BUFSIZE);
212380e3
AC
95 if (has_id(root_p))
96 {
1f9de103
VY
97 rb_strlcat(pbuf, "[", BUFSIZE);
98 rb_strlcat(pbuf, root_p->id, BUFSIZE);
99 rb_strlcat(pbuf, "]", BUFSIZE);
212380e3
AC
100 }
101 len = strlen(buf);
102 buf[len] = ' ';
103
104 if(len < USER_COL)
105 {
106 for (i = len + 1; i < USER_COL; i++)
107 {
108 buf[i] = '-';
109 }
110 }
111
28d337da 112 frac = (1000 * rb_dlink_list_length(&root_p->serv->users) + Count.total / 2) / Count.total;
5203cba5 113 snprintf(buf + USER_COL, BUFSIZE - USER_COL,
28d337da
JT
114 " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p->serv->users),
115 frac / 10, frac % 10);
212380e3 116
88520303 117 sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
212380e3
AC
118
119 if(root_p->serv->servers.head != NULL)
120 {
5b96d9a6 121 cnt += rb_dlink_list_length(&root_p->serv->servers);
212380e3
AC
122
123 if(cnt)
124 {
125 if(pbuf > buf + 3)
126 {
127 pbuf[-2] = ' ';
128 if(pbuf[-3] == '`')
129 pbuf[-3] = ' ';
130 }
131 }
132 }
133 i = 1;
5b96d9a6 134 RB_DLINK_FOREACH(ptr, root_p->serv->servers.head)
212380e3
AC
135 {
136 server_p = ptr->data;
137 *pbuf = ' ';
138 if(i < cnt)
139 *(pbuf + 1) = '|';
140 else
141 *(pbuf + 1) = '`';
142
143 *(pbuf + 2) = '-';
144 *(pbuf + 3) = ' ';
145 dump_map(client_p, server_p, pbuf + 4);
146
147 i++;
148 }
149}
e1fda0d8
AC
150
151/*
152 * flattened_map - display a version of map that doesn't give away routing
153 * information to users when flattened links is enabled.
154 */
155static void
156flattened_map(struct Client *client_p)
157{
158 char buf[BUFSIZE];
159 rb_dlink_node *ptr;
160 struct Client *target_p;
161 int i, len;
162 int cnt = 0;
163
164 /* First display me as the root */
165 rb_strlcpy(buf, me.name, BUFSIZE);
166 len = strlen(buf);
167 buf[len] = ' ';
168
169 if(len < USER_COL)
170 {
171 for (i = len + 1; i < USER_COL; i++)
172 {
173 buf[i] = '-';
174 }
175 }
176
177 snprintf(buf + USER_COL, BUFSIZE - USER_COL,
178 " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&me.serv->users),
179 100 * (float) rb_dlink_list_length(&me.serv->users) / (float) Count.total);
180
181 sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
182
183 /* Next, we run through every other server and list them */
184 RB_DLINK_FOREACH(ptr, global_serv_list.head)
185 {
186 target_p = ptr->data;
187
188 cnt++;
189
190 /* Skip ourselves, it's already counted */
191 if(IsMe(target_p))
192 continue;
193
194 /* if we're hidden, go on to the next leaf */
195 if(!ConfigServerHide.disable_hidden && IsHidden(target_p))
196 continue;
197
198 if (cnt == rb_dlink_list_length(&global_serv_list))
199 rb_strlcpy(buf, " `- ", BUFSIZE);
200 else
201 rb_strlcpy(buf, " |- ", BUFSIZE);
202
0e06053c 203 rb_strlcat(buf, target_p->name, BUFSIZE);
e1fda0d8
AC
204 len = strlen(buf);
205 buf[len] = ' ';
206
207 if(len < USER_COL)
208 {
209 for (i = len + 1; i < USER_COL; i++)
210 {
211 buf[i] = '-';
212 }
213 }
214
215 snprintf(buf + USER_COL, BUFSIZE - USER_COL,
216 " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&target_p->serv->users),
217 100 * (float) rb_dlink_list_length(&target_p->serv->users) / (float) Count.total);
218
219 sendto_one_numeric(client_p, RPL_MAP, form_str(RPL_MAP), buf);
220 }
221}