]> jfr.im git - solanum.git/blame - modules/m_help.c
Add ACCOUNTEXTBAN ISUPPORT token
[solanum.git] / modules / m_help.c
CommitLineData
212380e3
AC
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
212380e3
AC
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "ircd.h"
28#include "msg.h"
29#include "numeric.h"
30#include "send.h"
31#include "s_conf.h"
4016731b 32#include "logger.h"
212380e3
AC
33#include "parse.h"
34#include "modules.h"
35#include "hash.h"
36#include "cache.h"
a4bf26dd 37#include "rb_dictionary.h"
212380e3 38
eeabf33a
EM
39static const char help_desc[] =
40 "Provides the help facility for commands, modes, and server concepts";
41
3c7d6fcc
EM
42static void m_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
43static void mo_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
44static void mo_uhelp(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
45static void dohelp(struct Client *, int, const char *);
46
47struct Message help_msgtab = {
7baa37a9 48 "HELP", 0, 0, 0, 0,
212380e3
AC
49 {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}}
50};
51struct Message uhelp_msgtab = {
7baa37a9 52 "UHELP", 0, 0, 0, 0,
212380e3
AC
53 {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}}
54};
55
56mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL };
9fd8e7cb 57
9fd8e7cb 58DECLARE_MODULE_AV2(help, NULL, NULL, help_clist, NULL, NULL, NULL, NULL, help_desc);
212380e3
AC
59
60/*
61 * m_help - HELP message handler
212380e3 62 */
3c7d6fcc 63static void
428ca87b 64m_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3 65{
212380e3 66 dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
212380e3
AC
67}
68
69/*
70 * mo_help - HELP message handler
212380e3 71 */
3c7d6fcc 72static void
428ca87b 73mo_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
74{
75 dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL);
212380e3
AC
76}
77
78/*
79 * mo_uhelp - HELP message handler
80 * This is used so that opers can view the user help file without deopering
212380e3 81 */
3c7d6fcc 82static void
428ca87b 83mo_uhelp(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
84{
85 dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
212380e3
AC
86}
87
88static void
89dohelp(struct Client *source_p, int flags, const char *topic)
90{
91 static const char ntopic[] = "index";
92 struct cachefile *hptr;
93 struct cacheline *lineptr;
5b96d9a6
AC
94 rb_dlink_node *ptr;
95 rb_dlink_node *fptr;
212380e3
AC
96
97 if(EmptyString(topic))
98 topic = ntopic;
99
d8f0b5d7 100 hptr = rb_dictionary_retrieve((flags & HELP_OPER) ? help_dict_oper : help_dict_user, topic);
212380e3 101
9802490c 102 if(hptr == NULL || !(hptr->flags & flags))
212380e3
AC
103 {
104 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
105 me.name, source_p->name, topic);
106 return;
107 }
108
109 fptr = hptr->contents.head;
110 lineptr = fptr->data;
111
112 /* first line cant be empty */
113 sendto_one(source_p, form_str(RPL_HELPSTART),
114 me.name, source_p->name, topic, lineptr->data);
115
5b96d9a6 116 RB_DLINK_FOREACH(ptr, fptr->next)
212380e3
AC
117 {
118 lineptr = ptr->data;
119
120 sendto_one(source_p, form_str(RPL_HELPTXT),
121 me.name, source_p->name, topic, lineptr->data);
122 }
123
124 sendto_one(source_p, form_str(RPL_ENDOFHELP),
125 me.name, source_p->name, topic);
212380e3 126}