ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_links.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5344 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

# Content
1 /*
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 * $Id$
23 */
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
39 static void do_links(struct Client *, int, char *[]);
40 static void m_links(struct Client *, struct Client *, int, char *[]);
41 static void mo_links(struct Client *, struct Client *, int, char *[]);
42 static void ms_links(struct Client *, struct Client *, int, char *[]);
43
44 struct Message links_msgtab = {
45 "LINKS", 0, 0, 0, 0, MFLG_SLOW, 0,
46 {m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore}
47 };
48
49 const char *_version = "$Revision$";
50
51 void
52 _modinit(void)
53 {
54 mod_add_cmd(&links_msgtab);
55 }
56
57 void
58 _moddeinit(void)
59 {
60 mod_del_cmd(&links_msgtab);
61 }
62
63 static void
64 do_links(struct Client *source_p, int parc, char *parv[])
65 {
66 sendto_realops_flags(UMODE_SPY, L_ALL,
67 "LINKS requested by %s (%s@%s) [%s]",
68 source_p->name,
69 source_p->username, source_p->host,
70 source_p->servptr->name);
71
72 if (IsOper(source_p) || !ConfigServerHide.flatten_links)
73 {
74 const char *mask = (parc > 2 ? parv[2] : parv[1]);
75 const char *me_name, *nick, *p;
76 struct Client *target_p;
77 dlink_node *ptr;
78
79 me_name = ID_or_name(&me, source_p->from);
80 nick = ID_or_name(source_p, source_p->from);
81
82 DLINK_FOREACH(ptr, global_serv_list.head)
83 {
84 target_p = ptr->data;
85
86 if (!EmptyString(mask) && !match(mask, target_p->name))
87 continue;
88
89 if (target_p->info[0])
90 {
91 if ((p = strchr(target_p->info, ']')))
92 p += 2; /* skip the nasty [IP] part */
93 else
94 p = target_p->info;
95 }
96 else
97 p = "(Unknown Location)";
98
99 /* We just send the reply, as if they are here there's either no SHIDE,
100 * or they're an oper..
101 */
102 sendto_one(source_p, form_str(RPL_LINKS),
103 me_name, nick,
104 target_p->name, target_p->servptr->name,
105 target_p->hopcount, p);
106 }
107
108 sendto_one(source_p, form_str(RPL_ENDOFLINKS),
109 me_name, nick,
110 EmptyString(mask) ? "*" : mask);
111 }
112 else
113 {
114 /*
115 * Print our own info so at least it looks like a normal links
116 * then print out the file (which may or may not be empty)
117 */
118 sendto_one(source_p, form_str(RPL_LINKS),
119 ID_or_name(&me, source_p->from),
120 ID_or_name(source_p, source_p->from),
121 me.name, me.name, 0, me.info);
122 send_message_file(source_p, &ConfigFileEntry.linksfile);
123 sendto_one(source_p, form_str(RPL_ENDOFLINKS),
124 ID_or_name(&me, source_p->from),
125 ID_or_name(source_p, source_p->from), "*");
126 }
127 }
128
129 /*
130 * m_links - LINKS message handler
131 * parv[0] = sender prefix
132 * parv[1] = servername mask
133 * or
134 * parv[0] = sender prefix
135 * parv[1] = server to query
136 * parv[2] = servername mask
137 */
138 static void
139 m_links(struct Client *client_p, struct Client *source_p,
140 int parc, char *parv[])
141 {
142 static time_t last_used = 0;
143
144 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
145 {
146 sendto_one(source_p, form_str(RPL_LOAD2HI),
147 me.name, source_p->name);
148 return;
149 }
150
151 last_used = CurrentTime;
152
153 if (!ConfigServerHide.flatten_links)
154 {
155 mo_links(client_p, source_p, parc, parv);
156 return;
157 }
158
159 do_links(source_p, parc, parv);
160 }
161
162 static void
163 mo_links(struct Client *client_p, struct Client *source_p,
164 int parc, char *parv[])
165 {
166 if (parc > 2)
167 if (!ConfigFileEntry.disable_remote || IsOper(source_p))
168 if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1,
169 parc, parv) != HUNTED_ISME)
170 return;
171
172 do_links(source_p, parc, parv);
173 }
174
175 /*
176 * ms_links - LINKS message handler
177 * parv[0] = sender prefix
178 * parv[1] = servername mask
179 * or
180 * parv[0] = sender prefix
181 * parv[1] = server to query
182 * parv[2] = servername mask
183 */
184 static void
185 ms_links(struct Client *client_p, struct Client *source_p,
186 int parc, char *parv[])
187 {
188 if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1,
189 parc, parv) != HUNTED_ISME)
190 return;
191
192 if (IsClient(source_p))
193 m_links(client_p, source_p, parc, parv);
194 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision