~ubuntu-branches/ubuntu/trusty/charybdis/trusty-proposed

« back to all changes in this revision

Viewing changes to extensions/m_findforwards.c

  • Committer: Package Import Robot
  • Author(s): Antoine Beaupré
  • Date: 2011-11-10 23:07:37 UTC
  • Revision ID: package-import@ubuntu.com-20111110230737-kqo6qsglp5oh02hr
Tags: upstream-3.3.0
Import upstream version 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "channel.h"
 
24
#include "client.h"
 
25
#include "hash.h"
 
26
#include "match.h"
 
27
#include "ircd.h"
 
28
#include "numeric.h"
 
29
#include "s_user.h"
 
30
#include "s_conf.h"
 
31
#include "s_newconf.h"
 
32
#include "send.h"
 
33
#include "msg.h"
 
34
#include "parse.h"
 
35
#include "modules.h"
 
36
#include "packet.h"
 
37
 
 
38
static int m_findforwards(struct Client *client_p, struct Client *source_p,
 
39
                        int parc, const char *parv[]);
 
40
 
 
41
struct Message findforwards_msgtab = {
 
42
        "FINDFORWARDS", 0, 0, 0, MFLG_SLOW,
 
43
        {mg_unreg, {m_findforwards, 2}, mg_ignore, mg_ignore, mg_ignore, {m_findforwards, 2}}
 
44
};
 
45
 
 
46
mapi_clist_av1 findforwards_clist[] = { &findforwards_msgtab, NULL };
 
47
 
 
48
DECLARE_MODULE_AV1(findforwards, NULL, NULL, findforwards_clist, NULL, NULL, "$Revision: 986 $");
 
49
 
 
50
/*
 
51
** mo_findforwards
 
52
**      parv[1] = channel
 
53
*/
 
54
static int
 
55
m_findforwards(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
56
{
 
57
        static time_t last_used = 0;
 
58
        struct Channel *chptr;
 
59
        struct membership *msptr;
 
60
        rb_dlink_node *ptr;
 
61
        char buf[414];
 
62
        char *p = buf, *end = buf + sizeof buf - 1;
 
63
        *p = '\0';
 
64
 
 
65
        /* Allow ircops to search for forwards to nonexistent channels */
 
66
        if(!IsOper(source_p))
 
67
        {
 
68
                if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL)
 
69
                {
 
70
                        sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
 
71
                                        form_str(ERR_NOTONCHANNEL), parv[1]);
 
72
                        return 0;
 
73
                }
 
74
 
 
75
                if(!is_chanop(msptr))
 
76
                {
 
77
                        sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
 
78
                                        me.name, source_p->name, parv[1]);
 
79
                        return 0;
 
80
                }
 
81
 
 
82
                if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
 
83
                {
 
84
                        sendto_one(source_p, form_str(RPL_LOAD2HI),
 
85
                                        me.name, source_p->name, "FINDFORWARDS");
 
86
                        return 0;
 
87
                }
 
88
                else
 
89
                        last_used = rb_current_time();
 
90
        }
 
91
        
 
92
        RB_DLINK_FOREACH(ptr, global_channel_list.head)
 
93
        {
 
94
                chptr = ptr->data;
 
95
                if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1]))
 
96
                {
 
97
                        if(p + strlen(chptr->chname) >= end - 13)
 
98
                        {
 
99
                                strcpy(p, "<truncated> ");
 
100
                                p += 12;
 
101
                                break;
 
102
                        }
 
103
                        strcpy(p, chptr->chname);
 
104
                        p += strlen(chptr->chname);
 
105
                        *p++ = ' ';
 
106
                }
 
107
        }
 
108
 
 
109
        if(buf[0])
 
110
                *(--p) = '\0';
 
111
 
 
112
        sendto_one_notice(source_p, ":Forwards for %s: %s", parv[1], buf);
 
113
 
 
114
        return 0;
 
115
}