Clean a bit - to be continued...
[seven-1.x.git] / modules / m_map.c
blob18ee70cc5c06d1bdaf8f128d3c2b641ebd70fa49
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_map.c: Sends an Undernet compatible map to a user.
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
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.
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.
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
23 #include "stdinc.h"
24 #include "client.h"
25 #include "modules.h"
26 #include "numeric.h"
27 #include "send.h"
28 #include "s_conf.h"
29 #include "sprintf_irc.h"
31 #define USER_COL 50 /* display | Users: %d at col 50 */
33 static int m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
34 static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
36 struct Message map_msgtab = {
37 "MAP", 0, 0, 0, MFLG_SLOW,
38 {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}}
41 mapi_clist_av1 map_clist[] = { &map_msgtab, NULL };
42 DECLARE_MODULE_AV1(map, NULL, NULL, map_clist, NULL, NULL, "$Revision: 122 $");
44 static void dump_map(struct Client *client_p, struct Client *root, char *pbuf);
46 static char buf[BUFSIZE];
48 /* m_map
49 ** parv[0] = sender prefix
51 static int
52 m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
54 if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) ||
55 ConfigFileEntry.map_oper_only)
57 m_not_oper(client_p, source_p, parc, parv);
58 return 0;
61 dump_map(client_p, &me, buf);
62 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
63 return 0;
67 ** mo_map
68 ** parv[0] = sender prefix
70 static int
71 mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
73 if(!IsOperRouting(source_p))
75 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name,
76 "routing");
77 return 0;
80 dump_map(client_p, &me, buf);
81 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
83 return 0;
87 ** dump_map
88 ** dumps server map, called recursively.
90 static void
91 dump_map(struct Client *client_p, struct Client *root_p, char *pbuf)
93 int cnt = 0, i = 0, len;
94 struct Client *server_p;
95 dlink_node *ptr;
96 *pbuf = '\0';
98 strlcat(pbuf, root_p->name, BUFSIZE);
99 if (has_id(root_p))
101 strlcat(pbuf, "[", BUFSIZE);
102 strlcat(pbuf, root_p->id, BUFSIZE);
103 strlcat(pbuf, "]", BUFSIZE);
105 len = strlen(buf);
106 buf[len] = ' ';
108 if(len < USER_COL)
110 for (i = len + 1; i < USER_COL; i++)
112 buf[i] = '-';
116 ircsnprintf(buf + USER_COL, BUFSIZE - USER_COL,
117 " | Users: %5lu (%4.1f%%)", dlink_list_length(&root_p->serv->users),
118 100 * (float) dlink_list_length(&root_p->serv->users) / (float) Count.total);
120 sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
122 if(root_p->serv->servers.head != NULL)
124 cnt += dlink_list_length(&root_p->serv->servers);
126 if(cnt)
128 if(pbuf > buf + 3)
130 pbuf[-2] = ' ';
131 if(pbuf[-3] == '`')
132 pbuf[-3] = ' ';
136 i = 1;
137 DLINK_FOREACH(ptr, root_p->serv->servers.head)
139 server_p = ptr->data;
140 *pbuf = ' ';
141 if(i < cnt)
142 *(pbuf + 1) = '|';
143 else
144 *(pbuf + 1) = '`';
146 *(pbuf + 2) = '-';
147 *(pbuf + 3) = ' ';
148 dump_map(client_p, server_p, pbuf + 4);
150 i++;