/[svn]/ircd-hybrid-7.2/modules/m_help.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_help.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Sun Oct 2 21:05:51 2005 UTC (14 years ago) by lusky
File MIME type: text/x-chdr
File size: 5731 byte(s)
create 7.2 branch, we can move/rename it as needed.


1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_help.c: Provides help information to a user/operator.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "ircd_handler.h"
30 #include "msg.h"
31 #include "numeric.h"
32 #include "send.h"
33 #include "s_conf.h"
34 #include "s_log.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "irc_string.h"
38
39 #define HPATH IRCD_PREFIX "/help/opers"
40 #define UHPATH IRCD_PREFIX "/help/users"
41 #define HELPLEN 400
42
43 static void m_help(struct Client *, struct Client *, int, char *[]);
44 static void mo_help(struct Client *, struct Client *, int, char *[]);
45 static void mo_uhelp(struct Client *, struct Client *, int, char *[]);
46 static void dohelp(struct Client *, const char *, char *);
47 static void sendhelpfile(struct Client *, const char *, const char *);
48
49 struct Message help_msgtab = {
50 "HELP", 0, 0, 0, 0, MFLG_SLOW, 0,
51 {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
52 };
53
54 struct Message uhelp_msgtab = {
55 "UHELP", 0, 0, 0, 0, MFLG_SLOW, 0,
56 {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
57 };
58
59 #ifndef STATIC_MODULES
60 void
61 _modinit(void)
62 {
63 mod_add_cmd(&help_msgtab);
64 mod_add_cmd(&uhelp_msgtab);
65 }
66
67 void
68 _moddeinit(void)
69 {
70 mod_del_cmd(&help_msgtab);
71 mod_del_cmd(&uhelp_msgtab);
72 }
73
74 const char *_version = "$Revision$";
75 #endif
76
77 /*
78 * m_help - HELP message handler
79 * parv[0] = sender prefix
80 */
81 static void
82 m_help(struct Client *client_p, struct Client *source_p,
83 int parc, char *parv[])
84 {
85 static time_t last_used = 0;
86
87 /* HELP is always local */
88 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
89 {
90 /* safe enough to give this on a local connect only */
91 sendto_one(source_p,form_str(RPL_LOAD2HI),
92 me.name, source_p->name);
93 return;
94 }
95
96 last_used = CurrentTime;
97
98 dohelp(source_p, UHPATH, parv[1]);
99 }
100
101 /*
102 * mo_help - HELP message handler
103 * parv[0] = sender prefix
104 */
105 static void
106 mo_help(struct Client *client_p, struct Client *source_p,
107 int parc, char *parv[])
108 {
109 dohelp(source_p, HPATH, parv[1]);
110 }
111
112 /*
113 * mo_uhelp - HELP message handler
114 * This is used so that opers can view the user help file without deopering
115 * parv[0] = sender prefix
116 */
117 static void
118 mo_uhelp(struct Client *client_p, struct Client *source_p,
119 int parc, char *parv[])
120 {
121 dohelp(source_p, UHPATH, parv[1]);
122 }
123
124 static void
125 dohelp(struct Client *source_p, const char *hpath, char *topic)
126 {
127 char path[PATH_MAX + 1];
128 struct stat sb;
129 int i;
130
131 if (topic != NULL)
132 {
133 if (*topic == '\0')
134 topic = "index";
135 else
136 {
137 /* convert to lower case */
138 for (i = 0; topic[i] != '\0'; i++)
139 topic[i] = ToLower(topic[i]);
140 }
141 }
142 else
143 topic = "index"; /* list available help topics */
144
145 if (strpbrk(topic, "/\\"))
146 {
147 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
148 me.name, source_p->name, topic);
149 return;
150 }
151
152 if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
153 {
154 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
155 me.name, source_p->name, topic);
156 return;
157 }
158
159 snprintf(path, sizeof(path), "%s/%s", hpath, topic);
160
161 if (stat(path, &sb) < 0)
162 {
163 ilog(L_NOTICE, "help file %s not found", path);
164 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
165 me.name, source_p->name, topic);
166 return;
167 }
168
169 #ifndef _WIN32
170 if (!S_ISREG(sb.st_mode))
171 {
172 ilog(L_NOTICE, "help file %s not found", path);
173 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
174 me.name, source_p->name, topic);
175 return;
176 }
177 #endif
178
179 sendhelpfile(source_p, path, topic);
180 }
181
182 static void
183 sendhelpfile(struct Client *source_p, const char *path, const char *topic)
184 {
185 FBFILE *file;
186 char line[HELPLEN];
187 char started = 0;
188 int type;
189
190 if ((file = fbopen(path, "r")) == NULL)
191 {
192 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
193 me.name, source_p->name, topic);
194 return;
195 }
196
197 if (fbgets(line, sizeof(line), file) == NULL)
198 {
199 sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
200 me.name, source_p->name, topic);
201 return;
202 }
203
204 else if (line[0] != '#')
205 {
206 line[strlen(line) - 1] = '\0';
207 sendto_one(source_p, form_str(RPL_HELPSTART),
208 me.name, source_p->name, topic, line);
209 started = 1;
210 }
211
212 while (fbgets(line, sizeof(line), file))
213 {
214 line[strlen(line) - 1] = '\0';
215 if(line[0] != '#')
216 {
217 if (!started)
218 {
219 type = RPL_HELPSTART;
220 started = 1;
221 }
222 else
223 type = RPL_HELPTXT;
224
225 sendto_one(source_p, form_str(RPL_HELPTXT),
226 me.name, source_p->name, topic, line);
227 }
228 }
229
230 fbclose(file);
231 sendto_one(source_p, form_str(RPL_HELPTXT),
232 me.name, source_p->name, topic, "");
233 sendto_one(source_p, form_str(RPL_ENDOFHELP),
234 me.name, source_p->name, topic);
235 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26