1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2001-2014 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_map.c |
23 |
* \brief Includes required functions for processing the MAP command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "modules.h" |
30 |
#include "numeric.h" |
31 |
#include "send.h" |
32 |
#include "conf.h" |
33 |
#include "ircd.h" |
34 |
#include "parse.h" |
35 |
|
36 |
|
37 |
static void dump_map(struct Client *client, |
38 |
struct Client *server, |
39 |
unsigned int prompt_length) |
40 |
{ |
41 |
dlink_node *ptr = NULL; |
42 |
struct Client *target_p = NULL; |
43 |
static char prompt[64]; |
44 |
static char buf[IRCD_BUFSIZE]; |
45 |
char *p = prompt + prompt_length; |
46 |
unsigned int cnt = 0; |
47 |
unsigned int bufpos = 0; |
48 |
|
49 |
*p = '\0'; |
50 |
|
51 |
if (prompt_length > 60) |
52 |
sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name); |
53 |
else |
54 |
{ |
55 |
int dashes; |
56 |
|
57 |
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "%s", server->name); |
58 |
|
59 |
if (HasUMode(client, UMODE_OPER) && server->id[0]) |
60 |
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id); |
61 |
|
62 |
buf[bufpos++] = ' '; |
63 |
dashes = 50 - bufpos - prompt_length; |
64 |
for (; dashes > 0; --dashes) |
65 |
buf[bufpos++] = '-'; |
66 |
buf[bufpos++] = ' '; |
67 |
buf[bufpos++] = '|'; |
68 |
|
69 |
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users %5d (%1.2f%%)", |
70 |
dlink_list_length(&server->serv->client_list), 100 * |
71 |
(float)dlink_list_length(&server->serv->client_list) / |
72 |
(float)Count.total); |
73 |
sendto_one_numeric(client, &me, RPL_MAP, prompt, buf); |
74 |
} |
75 |
|
76 |
if (prompt_length > 0) |
77 |
{ |
78 |
*(p - 1) = ' '; |
79 |
|
80 |
if (*(p - 2) == '`') |
81 |
*(p - 2) = ' '; |
82 |
} |
83 |
|
84 |
if (prompt_length > 60) |
85 |
return; |
86 |
strcpy(p, "|-"); |
87 |
|
88 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
89 |
{ |
90 |
target_p = ptr->data; |
91 |
|
92 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
93 |
continue; |
94 |
|
95 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
96 |
if (!HasUMode(client, UMODE_OPER)) |
97 |
continue; |
98 |
|
99 |
++cnt; |
100 |
} |
101 |
|
102 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
103 |
{ |
104 |
target_p = ptr->data; |
105 |
|
106 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
107 |
continue; |
108 |
|
109 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
110 |
if (!HasUMode(client, UMODE_OPER)) |
111 |
continue; |
112 |
|
113 |
if (--cnt == 0) |
114 |
*p = '`'; |
115 |
dump_map(client, target_p, prompt_length + 2); |
116 |
} |
117 |
|
118 |
if (prompt_length > 0) |
119 |
*(p - 1) = '-'; |
120 |
} |
121 |
|
122 |
/*! \brief Sends a network topology map and notifies irc-operators |
123 |
* about the MAP request |
124 |
* |
125 |
* \param source_p Pointer to client to report to |
126 |
*/ |
127 |
static void |
128 |
do_map(struct Client *source_p) |
129 |
{ |
130 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
131 |
"MAP requested by %s (%s@%s) [%s]", |
132 |
source_p->name, source_p->username, |
133 |
source_p->host, source_p->servptr->name); |
134 |
dump_map(source_p, &me, 0); |
135 |
} |
136 |
|
137 |
/*! \brief MAP command handler |
138 |
* |
139 |
* \param source_p Pointer to allocated Client struct from which the message |
140 |
* originally comes from. This can be a local or remote client. |
141 |
* \param parc Integer holding the number of supplied arguments. |
142 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
143 |
* pointers. |
144 |
* \note Valid arguments for this command are: |
145 |
* - parv[0] = command |
146 |
*/ |
147 |
static int |
148 |
m_map(struct Client *source_p, int parc, char *parv[]) |
149 |
{ |
150 |
static time_t last_used = 0; |
151 |
|
152 |
if (ConfigServerHide.flatten_links) |
153 |
return m_not_oper(source_p, parc, parv); |
154 |
|
155 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
156 |
{ |
157 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
158 |
return 0; |
159 |
} |
160 |
|
161 |
last_used = CurrentTime; |
162 |
|
163 |
do_map(source_p); |
164 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
165 |
return 0; |
166 |
} |
167 |
|
168 |
/*! \brief MAP command handler |
169 |
* |
170 |
* \param source_p Pointer to allocated Client struct from which the message |
171 |
* originally comes from. This can be a local or remote client. |
172 |
* \param parc Integer holding the number of supplied arguments. |
173 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
174 |
* pointers. |
175 |
* \note Valid arguments for this command are: |
176 |
* - parv[0] = command |
177 |
*/ |
178 |
static int |
179 |
mo_map(struct Client *source_p, int parc, char *parv[]) |
180 |
{ |
181 |
do_map(source_p); |
182 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
183 |
return 0; |
184 |
} |
185 |
|
186 |
static struct Message map_msgtab = |
187 |
{ |
188 |
"MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
189 |
{ m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore } |
190 |
}; |
191 |
|
192 |
static void |
193 |
module_init(void) |
194 |
{ |
195 |
mod_add_cmd(&map_msgtab); |
196 |
} |
197 |
|
198 |
static void |
199 |
module_exit(void) |
200 |
{ |
201 |
mod_del_cmd(&map_msgtab); |
202 |
} |
203 |
|
204 |
struct module module_entry = |
205 |
{ |
206 |
.node = { NULL, NULL, NULL }, |
207 |
.name = NULL, |
208 |
.version = "$Revision$", |
209 |
.handle = NULL, |
210 |
.modinit = module_init, |
211 |
.modexit = module_exit, |
212 |
.flags = 0 |
213 |
}; |