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