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