ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_links.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (14 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 5300 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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