ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_links.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 5520 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


File Contents

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

Properties

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