]>
Commit | Line | Data |
---|---|---|
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 | |
428ca87b AC |
39 | static int m_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
40 | static int mo_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
41 | static int mo_uhelp(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
42 | static void dohelp(struct Client *, int, const char *); |
43 | ||
44 | struct Message help_msgtab = { | |
7baa37a9 | 45 | "HELP", 0, 0, 0, 0, |
212380e3 AC |
46 | {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}} |
47 | }; | |
48 | struct Message uhelp_msgtab = { | |
7baa37a9 | 49 | "UHELP", 0, 0, 0, 0, |
212380e3 AC |
50 | {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}} |
51 | }; | |
52 | ||
53 | mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL }; | |
9fd8e7cb EM |
54 | |
55 | static const char help_desc[] = | |
56 | "Provides the help facility for commands, modes, and server concepts"; | |
57 | ||
58 | DECLARE_MODULE_AV2(help, NULL, NULL, help_clist, NULL, NULL, NULL, NULL, help_desc); | |
212380e3 AC |
59 | |
60 | /* | |
61 | * m_help - HELP message handler | |
212380e3 AC |
62 | */ |
63 | static int | |
428ca87b | 64 | m_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 65 | { |
212380e3 AC |
66 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); |
67 | ||
68 | return 0; | |
69 | } | |
70 | ||
71 | /* | |
72 | * mo_help - HELP message handler | |
212380e3 AC |
73 | */ |
74 | static int | |
428ca87b | 75 | mo_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
76 | { |
77 | dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | /* | |
82 | * mo_uhelp - HELP message handler | |
83 | * This is used so that opers can view the user help file without deopering | |
212380e3 AC |
84 | */ |
85 | static int | |
428ca87b | 86 | mo_uhelp(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
87 | { |
88 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | static void | |
93 | dohelp(struct Client *source_p, int flags, const char *topic) | |
94 | { | |
95 | static const char ntopic[] = "index"; | |
96 | struct cachefile *hptr; | |
97 | struct cacheline *lineptr; | |
5b96d9a6 AC |
98 | rb_dlink_node *ptr; |
99 | rb_dlink_node *fptr; | |
212380e3 AC |
100 | |
101 | if(EmptyString(topic)) | |
102 | topic = ntopic; | |
103 | ||
a4bf26dd | 104 | hptr = rb_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic); |
212380e3 | 105 | |
9802490c | 106 | if(hptr == NULL || !(hptr->flags & flags)) |
212380e3 AC |
107 | { |
108 | sendto_one(source_p, form_str(ERR_HELPNOTFOUND), | |
109 | me.name, source_p->name, topic); | |
110 | return; | |
111 | } | |
112 | ||
113 | fptr = hptr->contents.head; | |
114 | lineptr = fptr->data; | |
115 | ||
116 | /* first line cant be empty */ | |
117 | sendto_one(source_p, form_str(RPL_HELPSTART), | |
118 | me.name, source_p->name, topic, lineptr->data); | |
119 | ||
5b96d9a6 | 120 | RB_DLINK_FOREACH(ptr, fptr->next) |
212380e3 AC |
121 | { |
122 | lineptr = ptr->data; | |
123 | ||
124 | sendto_one(source_p, form_str(RPL_HELPTXT), | |
125 | me.name, source_p->name, topic, lineptr->data); | |
126 | } | |
127 | ||
128 | sendto_one(source_p, form_str(RPL_ENDOFHELP), | |
129 | me.name, source_p->name, topic); | |
130 | return; | |
131 | } |