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 |
#include "s_user.h" |
35 |
|
36 |
|
37 |
|
38 |
static void dump_map(struct Client *client, |
39 |
struct Client *server, |
40 |
unsigned int prompt_length) |
41 |
{ |
42 |
dlink_node *ptr = NULL; |
43 |
struct Client *target_p = NULL; |
44 |
static char prompt[64]; |
45 |
char *p = prompt + prompt_length; |
46 |
int cnt = 0; |
47 |
|
48 |
*p = '\0'; |
49 |
|
50 |
if (prompt_length > 60) |
51 |
sendto_one(client, form_str(RPL_MAPMORE), me.name, |
52 |
client->name, prompt, server->name); |
53 |
else |
54 |
{ |
55 |
char buf[IRC_MAXSID + 3] = ""; /* +3 for [, ], \0 */ |
56 |
|
57 |
if (HasUMode(client, UMODE_OPER) && server->id[0]) |
58 |
snprintf(buf, sizeof(buf), "[%s]", server->id); |
59 |
|
60 |
sendto_one(client, form_str(RPL_MAP), me.name, client->name, |
61 |
prompt, server->name, buf, |
62 |
dlink_list_length(&server->serv->client_list), |
63 |
dlink_list_length(&server->serv->client_list) * 100 / Count.total); |
64 |
} |
65 |
|
66 |
if (prompt_length > 0) |
67 |
{ |
68 |
*(p - 1) = ' '; |
69 |
|
70 |
if (*(p - 2) == '`') |
71 |
*(p - 2) = ' '; |
72 |
} |
73 |
|
74 |
if (prompt_length > 60) |
75 |
return; |
76 |
strcpy(p, "|-"); |
77 |
|
78 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
79 |
{ |
80 |
target_p = ptr->data; |
81 |
|
82 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
83 |
if (!HasUMode(client, UMODE_OPER)) |
84 |
continue; |
85 |
|
86 |
++cnt; |
87 |
} |
88 |
|
89 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
90 |
{ |
91 |
target_p = ptr->data; |
92 |
|
93 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
94 |
if (!HasUMode(client, UMODE_OPER)) |
95 |
continue; |
96 |
|
97 |
if (--cnt == 0) |
98 |
*p = '`'; |
99 |
dump_map(client, target_p, prompt_length + 2); |
100 |
} |
101 |
|
102 |
if (prompt_length > 0) |
103 |
*(p - 1) = '-'; |
104 |
} |
105 |
|
106 |
/* m_map() |
107 |
* parv[0] = sender prefix |
108 |
*/ |
109 |
static void |
110 |
m_map(struct Client *client_p, struct Client *source_p, |
111 |
int parc, char *parv[]) |
112 |
{ |
113 |
static time_t last_used = 0; |
114 |
|
115 |
if (ConfigServerHide.flatten_links) |
116 |
{ |
117 |
m_not_oper(client_p, source_p, parc, parv); |
118 |
return; |
119 |
} |
120 |
|
121 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
122 |
{ |
123 |
/* safe enough to give this on a local connect only */ |
124 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
125 |
me.name, source_p->name); |
126 |
return; |
127 |
} |
128 |
|
129 |
last_used = CurrentTime; |
130 |
|
131 |
dump_map(source_p, &me, 0); |
132 |
sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name); |
133 |
} |
134 |
|
135 |
/* mo_map() |
136 |
* parv[0] = sender prefix |
137 |
*/ |
138 |
static void |
139 |
mo_map(struct Client *client_p, struct Client *source_p, |
140 |
int parc, char *parv[]) |
141 |
{ |
142 |
dump_map(source_p, &me, 0); |
143 |
sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name); |
144 |
} |
145 |
|
146 |
static struct Message map_msgtab = { |
147 |
"MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
148 |
{ m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore } |
149 |
}; |
150 |
|
151 |
static void |
152 |
module_init(void) |
153 |
{ |
154 |
mod_add_cmd(&map_msgtab); |
155 |
} |
156 |
|
157 |
static void |
158 |
module_exit(void) |
159 |
{ |
160 |
mod_del_cmd(&map_msgtab); |
161 |
} |
162 |
|
163 |
struct module module_entry = { |
164 |
.node = { NULL, NULL, NULL }, |
165 |
.name = NULL, |
166 |
.version = "$Revision$", |
167 |
.handle = NULL, |
168 |
.modinit = module_init, |
169 |
.modexit = module_exit, |
170 |
.flags = 0 |
171 |
}; |