1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_links.c: Shows what servers are currently connected. |
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 "handlers.h" |
27 |
|
|
#include "client.h" |
28 |
|
|
#include "irc_string.h" |
29 |
|
|
#include "ircd.h" |
30 |
|
|
#include "numeric.h" |
31 |
|
|
#include "s_serv.h" |
32 |
|
|
#include "send.h" |
33 |
|
|
#include "s_conf.h" |
34 |
|
|
#include "msg.h" |
35 |
|
|
#include "motd.h" |
36 |
|
|
#include "parse.h" |
37 |
|
|
#include "modules.h" |
38 |
|
|
#include "hook.h" |
39 |
|
|
|
40 |
|
|
static void do_links(struct Client *, int, char **); |
41 |
|
|
static void m_links(struct Client*, struct Client*, int, char**); |
42 |
|
|
static void mo_links(struct Client*, struct Client*, int, char**); |
43 |
|
|
static void ms_links(struct Client*, struct Client*, int, char**); |
44 |
|
|
|
45 |
|
|
struct Message links_msgtab = { |
46 |
|
|
"LINKS", 0, 0, 0, 0, MFLG_SLOW, 0, |
47 |
|
|
{m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore} |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
#ifndef STATIC_MODULES |
51 |
knight |
31 |
const char *_version = "$Revision$"; |
52 |
adx |
30 |
static struct Callback *links_cb; |
53 |
|
|
|
54 |
|
|
static void * |
55 |
|
|
va_links(va_list args) |
56 |
|
|
{ |
57 |
|
|
struct Client *source_p = va_arg(args, struct Client *); |
58 |
|
|
int parc = va_arg(args, int); |
59 |
|
|
char **parv = va_arg(args, char **); |
60 |
|
|
|
61 |
|
|
do_links(source_p, parc, parv); |
62 |
|
|
return NULL; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void |
66 |
|
|
_modinit(void) |
67 |
|
|
{ |
68 |
|
|
links_cb = register_callback("doing_links", va_links); |
69 |
|
|
mod_add_cmd(&links_msgtab); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
void |
73 |
|
|
_moddeinit(void) |
74 |
|
|
{ |
75 |
|
|
mod_del_cmd(&links_msgtab); |
76 |
|
|
uninstall_hook(links_cb, va_links); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
#endif |
80 |
|
|
|
81 |
|
|
static void |
82 |
|
|
do_links(struct Client *source_p, int parc, char **parv) |
83 |
|
|
{ |
84 |
|
|
if (IsOper(source_p) || !ConfigServerHide.flatten_links) |
85 |
|
|
{ |
86 |
michael |
1045 |
const char *mask = (parc > 2 ? parv[2] : parv[1]); |
87 |
adx |
30 |
const char *me_name, *nick, *p; |
88 |
|
|
struct Client *target_p; |
89 |
|
|
dlink_node *ptr; |
90 |
|
|
|
91 |
|
|
me_name = ID_or_name(&me, source_p->from); |
92 |
|
|
nick = ID_or_name(source_p, source_p->from); |
93 |
|
|
|
94 |
|
|
DLINK_FOREACH(ptr, global_serv_list.head) |
95 |
|
|
{ |
96 |
|
|
target_p = ptr->data; |
97 |
|
|
|
98 |
michael |
575 |
if (!EmptyString(mask) && !match(mask, target_p->name)) |
99 |
adx |
30 |
continue; |
100 |
michael |
575 |
|
101 |
adx |
30 |
if (target_p->info[0]) |
102 |
|
|
{ |
103 |
|
|
if ((p = strchr(target_p->info, ']'))) |
104 |
|
|
p += 2; /* skip the nasty [IP] part */ |
105 |
|
|
else |
106 |
|
|
p = target_p->info; |
107 |
|
|
} |
108 |
|
|
else |
109 |
|
|
p = "(Unknown Location)"; |
110 |
|
|
|
111 |
|
|
/* We just send the reply, as if they are here there's either no SHIDE, |
112 |
|
|
* or they're an oper.. |
113 |
|
|
*/ |
114 |
|
|
sendto_one(source_p, form_str(RPL_LINKS), |
115 |
|
|
me_name, nick, |
116 |
|
|
target_p->name, target_p->servptr->name, |
117 |
|
|
target_p->hopcount, p); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFLINKS), |
121 |
|
|
me_name, nick, |
122 |
|
|
EmptyString(mask) ? "*" : mask); |
123 |
|
|
} |
124 |
|
|
else { |
125 |
|
|
/* |
126 |
|
|
* Print our own info so at least it looks like a normal links |
127 |
|
|
* then print out the file (which may or may not be empty) |
128 |
|
|
*/ |
129 |
|
|
sendto_one(source_p, form_str(RPL_LINKS), |
130 |
|
|
ID_or_name(&me, source_p->from), |
131 |
|
|
ID_or_name(source_p, source_p->from), |
132 |
|
|
me.name, me.name, 0, me.info); |
133 |
|
|
send_message_file(source_p, &ConfigFileEntry.linksfile); |
134 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFLINKS), |
135 |
adx |
103 |
ID_or_name(&me, source_p->from), |
136 |
|
|
ID_or_name(source_p, source_p->from), "*"); |
137 |
adx |
30 |
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
/* |
141 |
|
|
* m_links - LINKS message handler |
142 |
|
|
* parv[0] = sender prefix |
143 |
|
|
* parv[1] = servername mask |
144 |
|
|
* or |
145 |
|
|
* parv[0] = sender prefix |
146 |
|
|
* parv[1] = server to query |
147 |
|
|
* parv[2] = servername mask |
148 |
|
|
*/ |
149 |
|
|
static void |
150 |
|
|
m_links(struct Client *client_p, struct Client *source_p, |
151 |
|
|
int parc, char *parv[]) |
152 |
|
|
{ |
153 |
adx |
269 |
static time_t last_used = 0; |
154 |
|
|
|
155 |
|
|
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
156 |
|
|
{ |
157 |
|
|
sendto_one(source_p, form_str(RPL_LOAD2HI), |
158 |
|
|
me.name, source_p->name); |
159 |
|
|
return; |
160 |
|
|
} |
161 |
|
|
else |
162 |
|
|
last_used = CurrentTime; |
163 |
|
|
|
164 |
adx |
30 |
if (!ConfigServerHide.flatten_links) |
165 |
|
|
{ |
166 |
|
|
mo_links(client_p, source_p, parc, parv); |
167 |
|
|
return; |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
#ifdef STATIC_MODULES |
171 |
|
|
do_links(source_p, parc, parv); |
172 |
|
|
#else |
173 |
|
|
execute_callback(links_cb, source_p, parc, parv); |
174 |
|
|
#endif |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
static void |
178 |
|
|
mo_links(struct Client *client_p, struct Client *source_p, |
179 |
|
|
int parc, char *parv[]) |
180 |
|
|
{ |
181 |
|
|
if (parc > 2) |
182 |
|
|
if (!ConfigFileEntry.disable_remote || IsOper(source_p)) |
183 |
|
|
{ |
184 |
|
|
if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv) |
185 |
|
|
!= HUNTED_ISME) |
186 |
|
|
return; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
#ifdef STATIC_MODULES |
190 |
|
|
do_links(source_p, parc, parv); |
191 |
|
|
#else |
192 |
|
|
execute_callback(links_cb, source_p, parc, parv); |
193 |
|
|
#endif |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
/* |
197 |
|
|
* ms_links - LINKS message handler |
198 |
|
|
* parv[0] = sender prefix |
199 |
|
|
* parv[1] = servername mask |
200 |
|
|
* or |
201 |
|
|
* parv[0] = sender prefix |
202 |
|
|
* parv[1] = server to query |
203 |
|
|
* parv[2] = servername mask |
204 |
|
|
*/ |
205 |
|
|
static void |
206 |
|
|
ms_links(struct Client *client_p, struct Client *source_p, |
207 |
|
|
int parc, char *parv[]) |
208 |
|
|
{ |
209 |
|
|
if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv) |
210 |
|
|
!= HUNTED_ISME) |
211 |
|
|
return; |
212 |
|
|
|
213 |
|
|
if (IsClient(source_p)) |
214 |
|
|
m_links(client_p, source_p, parc, parv); |
215 |
|
|
} |