]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | * | |
212380e3 | 24 | */ |
25 | ||
26 | #include "stdinc.h" | |
27 | #include "client.h" | |
28 | #include "ircd.h" | |
29 | #include "msg.h" | |
30 | #include "numeric.h" | |
31 | #include "send.h" | |
32 | #include "s_conf.h" | |
d3455e2c | 33 | #include "logger.h" |
212380e3 | 34 | #include "parse.h" |
35 | #include "modules.h" | |
36 | #include "hash.h" | |
37 | #include "cache.h" | |
9802490c | 38 | #include "irc_dictionary.h" |
212380e3 | 39 | |
40 | static int m_help(struct Client *, struct Client *, int, const char **); | |
41 | static int mo_help(struct Client *, struct Client *, int, const char **); | |
42 | static int mo_uhelp(struct Client *, struct Client *, int, const char **); | |
43 | static void dohelp(struct Client *, int, const char *); | |
44 | ||
45 | struct Message help_msgtab = { | |
46 | "HELP", 0, 0, 0, MFLG_SLOW, | |
47 | {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}} | |
48 | }; | |
49 | struct Message uhelp_msgtab = { | |
50 | "UHELP", 0, 0, 0, MFLG_SLOW, | |
51 | {mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}} | |
52 | }; | |
53 | ||
54 | mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL }; | |
55 | DECLARE_MODULE_AV1(help, NULL, NULL, help_clist, NULL, NULL, "$Revision: 254 $"); | |
56 | ||
57 | /* | |
58 | * m_help - HELP message handler | |
212380e3 | 59 | */ |
60 | static int | |
61 | m_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
62 | { | |
212380e3 | 63 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | /* | |
69 | * mo_help - HELP message handler | |
212380e3 | 70 | */ |
71 | static int | |
72 | mo_help(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
73 | { | |
74 | dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL); | |
75 | return 0; | |
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 | */ |
82 | static int | |
83 | mo_uhelp(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
84 | { | |
85 | dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL); | |
86 | return 0; | |
87 | } | |
88 | ||
89 | static void | |
90 | dohelp(struct Client *source_p, int flags, const char *topic) | |
91 | { | |
92 | static const char ntopic[] = "index"; | |
93 | struct cachefile *hptr; | |
94 | struct cacheline *lineptr; | |
08d11e34 WP |
95 | rb_dlink_node *ptr; |
96 | rb_dlink_node *fptr; | |
212380e3 | 97 | |
98 | if(EmptyString(topic)) | |
ef07b59a | 99 | { |
212380e3 | 100 | topic = ntopic; |
ef07b59a JH |
101 | if(!EmptyString(ServerInfo.helpchan)) |
102 | sendto_one(source_p, ":%s 525 %s :Official Help Channel: %s", | |
103 | me.name, source_p->name, ServerInfo.helpchan); | |
104 | if(!EmptyString(ServerInfo.helpurl)) | |
105 | sendto_one(source_p, ":%s 526 %s :Official Help URL: %s", | |
106 | me.name, source_p->name, ServerInfo.helpurl); | |
107 | } | |
212380e3 | 108 | |
5a34b193 | 109 | hptr = irc_dictionary_retrieve(flags & HELP_OPER ? help_dict_oper : help_dict_user, topic); |
212380e3 | 110 | |
9802490c | 111 | if(hptr == NULL || !(hptr->flags & flags)) |
212380e3 | 112 | { |
113 | sendto_one(source_p, form_str(ERR_HELPNOTFOUND), | |
114 | me.name, source_p->name, topic); | |
115 | return; | |
116 | } | |
117 | ||
118 | fptr = hptr->contents.head; | |
119 | lineptr = fptr->data; | |
120 | ||
121 | /* first line cant be empty */ | |
122 | sendto_one(source_p, form_str(RPL_HELPSTART), | |
123 | me.name, source_p->name, topic, lineptr->data); | |
124 | ||
08d11e34 | 125 | RB_DLINK_FOREACH(ptr, fptr->next) |
212380e3 | 126 | { |
127 | lineptr = ptr->data; | |
128 | ||
129 | sendto_one(source_p, form_str(RPL_HELPTXT), | |
130 | me.name, source_p->name, topic, lineptr->data); | |
131 | } | |
132 | ||
133 | sendto_one(source_p, form_str(RPL_ENDOFHELP), | |
134 | me.name, source_p->name, topic); | |
135 | return; | |
136 | } |