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

« back to all changes in this revision

Viewing changes to modules/m_help.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
 *  ircd-ratbox: A slightly useful ircd.
 
3
 *  m_help.c: Provides help information to a user/operator.
 
4
 *
 
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
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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
 
23
 *
 
24
 *  $Id: m_help.c 254 2005-09-21 23:35:12Z nenolod $
 
25
 */
 
26
 
 
27
#include "stdinc.h"
 
28
#include "client.h"
 
29
#include "ircd.h"
 
30
#include "msg.h"
 
31
#include "numeric.h"
 
32
#include "send.h"
 
33
#include "s_conf.h"
 
34
#include "logger.h"
 
35
#include "parse.h"
 
36
#include "modules.h"
 
37
#include "hash.h"
 
38
#include "cache.h"
 
39
#include "irc_dictionary.h"
 
40
 
 
41
static int m_help(struct Client *, struct Client *, int, const char **);
 
42
static int mo_help(struct Client *, struct Client *, int, const char **);
 
43
static int mo_uhelp(struct Client *, struct Client *, int, const char **);
 
44
static void dohelp(struct Client *, int, const char *);
 
45
 
 
46
struct Message help_msgtab = {
 
47
        "HELP", 0, 0, 0, MFLG_SLOW,
 
48
        {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}}
 
49
};
 
50
struct Message uhelp_msgtab = {
 
51
        "UHELP", 0, 0, 0, MFLG_SLOW,
 
52
        {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}}
 
53
};
 
54
 
 
55
mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL };
 
56
DECLARE_MODULE_AV1(help, NULL, NULL, help_clist, NULL, NULL, "$Revision: 254 $");
 
57
 
 
58
/*
 
59
 * m_help - HELP message handler
 
60
 */
 
61
static int
 
62
m_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
63
{
 
64
        dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
 
65
 
 
66
        return 0;
 
67
}
 
68
 
 
69
/*
 
70
 * mo_help - HELP message handler
 
71
 */
 
72
static int
 
73
mo_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
74
{
 
75
        dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL);
 
76
        return 0;
 
77
}
 
78
 
 
79
/*
 
80
 * mo_uhelp - HELP message handler
 
81
 * This is used so that opers can view the user help file without deopering
 
82
 */
 
83
static int
 
84
mo_uhelp(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 
85
{
 
86
        dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
 
87
        return 0;
 
88
}
 
89
 
 
90
static void
 
91
dohelp(struct Client *source_p, int flags, const char *topic)
 
92
{
 
93
        static const char ntopic[] = "index";
 
94
        struct cachefile *hptr;
 
95
        struct cacheline *lineptr;
 
96
        rb_dlink_node *ptr;
 
97
        rb_dlink_node *fptr;
 
98
 
 
99
        if(EmptyString(topic))
 
100
                topic = ntopic;
 
101
 
 
102
        hptr = irc_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic);
 
103
 
 
104
        if(hptr == NULL || !(hptr->flags & flags))
 
105
        {
 
106
                sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
 
107
                           me.name, source_p->name, topic);
 
108
                return;
 
109
        }
 
110
 
 
111
        fptr = hptr->contents.head;
 
112
        lineptr = fptr->data;
 
113
 
 
114
        /* first line cant be empty */
 
115
        sendto_one(source_p, form_str(RPL_HELPSTART),
 
116
                   me.name, source_p->name, topic, lineptr->data);
 
117
 
 
118
        RB_DLINK_FOREACH(ptr, fptr->next)
 
119
        {
 
120
                lineptr = ptr->data;
 
121
 
 
122
                sendto_one(source_p, form_str(RPL_HELPTXT),
 
123
                           me.name, source_p->name, topic, lineptr->data);
 
124
        }
 
125
 
 
126
        sendto_one(source_p, form_str(RPL_ENDOFHELP),
 
127
                   me.name, source_p->name, topic);
 
128
        return;
 
129
}