]>
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 }; | |
105a4985 | 54 | DECLARE_MODULE_AV2(help, NULL, NULL, help_clist, NULL, NULL, NULL, NULL, NULL); |
212380e3 AC |
55 | |
56 | /* | |
57 | * m_help - HELP message handler | |
212380e3 AC |
58 | */ |
59 | static int | |
428ca87b | 60 | m_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 61 | { |
212380e3 AC |
62 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); |
63 | ||
64 | return 0; | |
65 | } | |
66 | ||
67 | /* | |
68 | * mo_help - HELP message handler | |
212380e3 AC |
69 | */ |
70 | static int | |
428ca87b | 71 | mo_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
72 | { |
73 | dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL); | |
74 | return 0; | |
75 | } | |
76 | ||
77 | /* | |
78 | * mo_uhelp - HELP message handler | |
79 | * This is used so that opers can view the user help file without deopering | |
212380e3 AC |
80 | */ |
81 | static int | |
428ca87b | 82 | mo_uhelp(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
83 | { |
84 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | static void | |
89 | dohelp(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 | ||
a4bf26dd | 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); | |
126 | return; | |
127 | } |