Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_links.c
blob9f07879b208cb11a2b182ccf5e19a184f0fa3a56
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_links.c: Shows what servers are currently connected.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "client.h"
27 #include "irc_string.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 "parse.h"
35 #include "modules.h"
36 #include "hook.h"
37 #include "cache.h"
39 static int m_links(struct Client *, struct Client *, int, const char **);
40 static int do_links(struct Client *, struct Client *, int, const char **);
42 struct Message links_msgtab = {
43 "LINKS", 0, 0, 0, MFLG_SLOW,
44 {mg_unreg, {m_links, 0}, {do_links, 0}, mg_ignore, mg_ignore, {m_links, 0}}
47 int doing_links_hook;
49 mapi_clist_av1 links_clist[] = { &links_msgtab, NULL };
50 mapi_hlist_av1 links_hlist[] = {
51 { "doing_links", &doing_links_hook },
52 { NULL, NULL }
55 DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision: 122 $");
57 static void send_links_cache(struct Client *source_p);
60 * m_links - LINKS message handler
61 * parv[0] = sender prefix
62 * parv[1] = servername mask
63 * or
64 * parv[0] = sender prefix
65 * parv[1] = server to query
66 * parv[2] = servername mask
68 static int
69 m_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
71 if(ConfigServerHide.flatten_links && !IsExemptShide(source_p) &&
72 !IsOperRouting(source_p))
73 send_links_cache(source_p);
74 else
75 do_links(client_p, source_p, parc, parv);
77 return 0;
80 static int
81 do_links(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
83 const char *mask = "";
84 struct Client *target_p;
85 char clean_mask[2 * HOSTLEN + 4];
86 hook_data hd;
88 dlink_node *ptr;
90 if(parc > 2)
92 if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
93 != HUNTED_ISME)
94 return 0;
96 mask = parv[2];
98 else if(parc == 2)
99 mask = parv[1];
101 if(*mask) /* only necessary if there is a mask */
102 mask = collapse(clean_string
103 (clean_mask, (const unsigned char *) mask, 2 * HOSTLEN));
105 hd.client = source_p;
106 hd.arg1 = mask;
107 hd.arg2 = NULL;
109 call_hook(doing_links_hook, &hd);
111 DLINK_FOREACH(ptr, global_serv_list.head)
113 target_p = ptr->data;
115 if(*mask && !match(mask, target_p->name))
116 continue;
118 /* We just send the reply, as if theyre here theres either no SHIDE,
119 * or theyre an oper..
121 sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS),
122 target_p->name, target_p->serv->up,
123 target_p->hopcount,
124 target_p->info[0] ? target_p->info : "(Unknown Location)");
127 sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS),
128 EmptyString(mask) ? "*" : mask);
130 return 0;
133 /* send_links_cache()
135 * inputs - client to send to
136 * outputs - the cached links, us, and RPL_ENDOFLINKS
137 * side effects -
139 static void
140 send_links_cache(struct Client *source_p)
142 dlink_node *ptr;
144 DLINK_FOREACH(ptr, links_cache_list.head)
146 sendto_one(source_p, ":%s 364 %s %s",
147 me.name, source_p->name, (const char *)ptr->data);
150 sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS),
151 me.name, me.name, 0, me.info);
153 sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS), "*");