1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 2001-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
michael |
2820 |
/*! \file m_map.c |
23 |
|
|
* \brief Includes required functions for processing the MAP command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "modules.h" |
30 |
|
|
#include "numeric.h" |
31 |
|
|
#include "send.h" |
32 |
michael |
1309 |
#include "conf.h" |
33 |
adx |
30 |
#include "ircd.h" |
34 |
|
|
#include "irc_string.h" |
35 |
michael |
1243 |
#include "parse.h" |
36 |
adx |
30 |
|
37 |
michael |
889 |
|
38 |
michael |
1851 |
static void dump_map(struct Client *client, |
39 |
|
|
struct Client *server, |
40 |
|
|
unsigned int prompt_length) |
41 |
adx |
30 |
{ |
42 |
michael |
1851 |
dlink_node *ptr = NULL; |
43 |
|
|
struct Client *target_p = NULL; |
44 |
|
|
static char prompt[64]; |
45 |
michael |
2989 |
static char buf[IRCD_BUFSIZE]; |
46 |
michael |
1851 |
char *p = prompt + prompt_length; |
47 |
|
|
int cnt = 0; |
48 |
michael |
2989 |
int bufpos = 0; |
49 |
adx |
30 |
|
50 |
michael |
1851 |
*p = '\0'; |
51 |
adx |
30 |
|
52 |
michael |
1851 |
if (prompt_length > 60) |
53 |
michael |
3109 |
sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name); |
54 |
michael |
1851 |
else |
55 |
adx |
30 |
{ |
56 |
michael |
2989 |
int dashes; |
57 |
adx |
30 |
|
58 |
michael |
2989 |
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "%s", server->name); |
59 |
|
|
|
60 |
michael |
1851 |
if (HasUMode(client, UMODE_OPER) && server->id[0]) |
61 |
michael |
2989 |
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id); |
62 |
michael |
889 |
|
63 |
michael |
2989 |
buf[bufpos++] = ' '; |
64 |
|
|
dashes = 50 - bufpos - prompt_length; |
65 |
|
|
for (; dashes > 0; --dashes) |
66 |
|
|
buf[bufpos++] = '-'; |
67 |
|
|
buf[bufpos++] = ' '; |
68 |
|
|
buf[bufpos++] = '|'; |
69 |
|
|
|
70 |
|
|
bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users %5d (%1.2f%%)", |
71 |
|
|
dlink_list_length(&server->serv->client_list), 100 * |
72 |
|
|
(float)dlink_list_length(&server->serv->client_list) / |
73 |
|
|
(float)Count.total); |
74 |
michael |
3109 |
sendto_one_numeric(client, &me, RPL_MAP, prompt, buf); |
75 |
michael |
1851 |
} |
76 |
michael |
889 |
|
77 |
michael |
1851 |
if (prompt_length > 0) |
78 |
|
|
{ |
79 |
|
|
*(p - 1) = ' '; |
80 |
adx |
30 |
|
81 |
michael |
1851 |
if (*(p - 2) == '`') |
82 |
|
|
*(p - 2) = ' '; |
83 |
|
|
} |
84 |
adx |
30 |
|
85 |
michael |
1851 |
if (prompt_length > 60) |
86 |
|
|
return; |
87 |
|
|
strcpy(p, "|-"); |
88 |
adx |
30 |
|
89 |
michael |
1851 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
90 |
adx |
30 |
{ |
91 |
michael |
1851 |
target_p = ptr->data; |
92 |
adx |
30 |
|
93 |
michael |
2751 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
94 |
|
|
continue; |
95 |
|
|
|
96 |
michael |
1851 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
97 |
|
|
if (!HasUMode(client, UMODE_OPER)) |
98 |
|
|
continue; |
99 |
adx |
30 |
|
100 |
michael |
1851 |
++cnt; |
101 |
adx |
30 |
} |
102 |
|
|
|
103 |
michael |
1851 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
104 |
adx |
30 |
{ |
105 |
michael |
1851 |
target_p = ptr->data; |
106 |
adx |
30 |
|
107 |
michael |
2751 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
108 |
|
|
continue; |
109 |
|
|
|
110 |
michael |
1851 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
111 |
|
|
if (!HasUMode(client, UMODE_OPER)) |
112 |
|
|
continue; |
113 |
michael |
889 |
|
114 |
michael |
1851 |
if (--cnt == 0) |
115 |
|
|
*p = '`'; |
116 |
|
|
dump_map(client, target_p, prompt_length + 2); |
117 |
|
|
} |
118 |
michael |
889 |
|
119 |
michael |
1851 |
if (prompt_length > 0) |
120 |
|
|
*(p - 1) = '-'; |
121 |
adx |
30 |
} |
122 |
michael |
1230 |
|
123 |
|
|
/* m_map() |
124 |
michael |
3096 |
* parv[0] = command |
125 |
michael |
1230 |
*/ |
126 |
michael |
2820 |
static int |
127 |
michael |
3156 |
m_map(struct Client *source_p, int parc, char *parv[]) |
128 |
michael |
1230 |
{ |
129 |
|
|
static time_t last_used = 0; |
130 |
|
|
|
131 |
|
|
if (ConfigServerHide.flatten_links) |
132 |
michael |
3156 |
return m_not_oper(source_p, parc, parv); |
133 |
michael |
1230 |
|
134 |
|
|
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
135 |
|
|
{ |
136 |
|
|
/* safe enough to give this on a local connect only */ |
137 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
138 |
michael |
2820 |
return 0; |
139 |
michael |
1230 |
} |
140 |
|
|
|
141 |
|
|
last_used = CurrentTime; |
142 |
|
|
|
143 |
michael |
1851 |
dump_map(source_p, &me, 0); |
144 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
145 |
michael |
2820 |
return 0; |
146 |
michael |
1230 |
} |
147 |
|
|
|
148 |
|
|
/* mo_map() |
149 |
michael |
3096 |
* parv[0] = command |
150 |
michael |
1230 |
*/ |
151 |
michael |
2820 |
static int |
152 |
michael |
3156 |
mo_map(struct Client *source_p, int parc, char *parv[]) |
153 |
michael |
1230 |
{ |
154 |
michael |
1851 |
dump_map(source_p, &me, 0); |
155 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
156 |
michael |
2820 |
return 0; |
157 |
michael |
1230 |
} |
158 |
|
|
|
159 |
michael |
2820 |
static struct Message map_msgtab = |
160 |
|
|
{ |
161 |
michael |
1230 |
"MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
162 |
|
|
{ m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore } |
163 |
|
|
}; |
164 |
|
|
|
165 |
|
|
static void |
166 |
|
|
module_init(void) |
167 |
|
|
{ |
168 |
|
|
mod_add_cmd(&map_msgtab); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
static void |
172 |
|
|
module_exit(void) |
173 |
|
|
{ |
174 |
|
|
mod_del_cmd(&map_msgtab); |
175 |
|
|
} |
176 |
|
|
|
177 |
michael |
2820 |
struct module module_entry = |
178 |
|
|
{ |
179 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
180 |
|
|
.name = NULL, |
181 |
|
|
.version = "$Revision$", |
182 |
|
|
.handle = NULL, |
183 |
|
|
.modinit = module_init, |
184 |
|
|
.modexit = module_exit, |
185 |
|
|
.flags = 0 |
186 |
|
|
}; |