]> jfr.im git - irc/rqf/shadowircd.git/blob - extensions/m_findforwards.c
[svn] - the new plan:
[irc/rqf/shadowircd.git] / extensions / m_findforwards.c
1 /*
2 * IRC - Internet Relay Chat, contrib/m_findforwards.c
3 * Copyright (C) 2002 Hybrid Development Team
4 * Copyright (C) 2004 ircd-ratbox Development Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: m_findforwards.c 986 2006-03-08 00:10:46Z jilles $
21 */
22 #include "stdinc.h"
23 #include "tools.h"
24 #include "channel.h"
25 #include "client.h"
26 #include "hash.h"
27 #include "irc_string.h"
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "s_user.h"
31 #include "s_conf.h"
32 #include "s_newconf.h"
33 #include "send.h"
34 #include "msg.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "packet.h"
38
39 static int m_findforwards(struct Client *client_p, struct Client *source_p,
40 int parc, const char *parv[]);
41
42 struct Message findforwards_msgtab = {
43 "FINDFORWARDS", 0, 0, 0, MFLG_SLOW,
44 {mg_unreg, {m_findforwards, 2}, mg_ignore, mg_ignore, mg_ignore, {m_findforwards, 2}}
45 };
46
47 mapi_clist_av1 findforwards_clist[] = { &findforwards_msgtab, NULL };
48
49 DECLARE_MODULE_AV1(findforwards, NULL, NULL, findforwards_clist, NULL, NULL, "$Revision: 986 $");
50
51 /*
52 ** mo_findforwards
53 ** parv[0] = sender prefix
54 ** parv[1] = channel
55 */
56 static int
57 m_findforwards(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
58 {
59 static time_t last_used = 0;
60 struct Channel *chptr;
61 struct membership *msptr;
62 dlink_node *ptr;
63 char buf[414];
64 char *p = buf, *end = buf + sizeof buf - 1;
65 *p = '\0';
66
67 /* Allow ircops to search for forwards to nonexistent channels */
68 if(!IsOper(source_p))
69 {
70 if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL)
71 {
72 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
73 form_str(ERR_NOTONCHANNEL), parv[1]);
74 return 0;
75 }
76
77 if(!is_chanop(msptr))
78 {
79 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
80 me.name, source_p->name, parv[1]);
81 return 0;
82 }
83
84 if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
85 {
86 sendto_one(source_p, form_str(RPL_LOAD2HI),
87 me.name, source_p->name, "FINDFORWARDS");
88 return 0;
89 }
90 else
91 last_used = CurrentTime;
92 }
93
94 DLINK_FOREACH(ptr, global_channel_list.head)
95 {
96 chptr = ptr->data;
97 if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1]))
98 {
99 if(p + strlen(chptr->chname) >= end - 13)
100 {
101 strcpy(p, "<truncated> ");
102 p += 12;
103 break;
104 }
105 strcpy(p, chptr->chname);
106 p += strlen(chptr->chname);
107 *p++ = ' ';
108 }
109 }
110
111 if(buf[0])
112 *(--p) = '\0';
113
114 sendto_one_notice(source_p, ":Forwards for %s: %s", parv[1], buf);
115
116 return 0;
117 }