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 "client.h" |
27 |
#include "ircd.h" |
28 |
#include "numeric.h" |
29 |
#include "send.h" |
30 |
#include "conf.h" |
31 |
#include "parse.h" |
32 |
#include "modules.h" |
33 |
#include "irc_string.h" |
34 |
|
35 |
#define HELPLEN 400 |
36 |
|
37 |
static void dohelp(struct Client *, const char *, char *); |
38 |
static void sendhelpfile(struct Client *, const char *, const char *); |
39 |
|
40 |
|
41 |
/* |
42 |
* m_help - HELP message handler |
43 |
* parv[0] = sender prefix |
44 |
*/ |
45 |
static void |
46 |
m_help(struct Client *client_p, struct Client *source_p, |
47 |
int parc, char *parv[]) |
48 |
{ |
49 |
static time_t last_used = 0; |
50 |
|
51 |
/* HELP is always local */ |
52 |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
53 |
{ |
54 |
/* safe enough to give this on a local connect only */ |
55 |
sendto_one(source_p, RPL_LOAD2HI, |
56 |
me.name, source_p->name); |
57 |
return; |
58 |
} |
59 |
|
60 |
last_used = CurrentTime; |
61 |
|
62 |
dohelp(source_p, UHPATH, parv[1]); |
63 |
} |
64 |
|
65 |
/* |
66 |
* mo_help - HELP message handler |
67 |
* parv[0] = sender prefix |
68 |
*/ |
69 |
static void |
70 |
mo_help(struct Client *client_p, struct Client *source_p, |
71 |
int parc, char *parv[]) |
72 |
{ |
73 |
dohelp(source_p, HPATH, parv[1]); |
74 |
} |
75 |
|
76 |
/* |
77 |
* mo_uhelp - HELP message handler |
78 |
* This is used so that opers can view the user help file without deopering |
79 |
* parv[0] = sender prefix |
80 |
*/ |
81 |
static void |
82 |
mo_uhelp(struct Client *client_p, struct Client *source_p, |
83 |
int parc, char *parv[]) |
84 |
{ |
85 |
dohelp(source_p, UHPATH, parv[1]); |
86 |
} |
87 |
|
88 |
static void |
89 |
dohelp(struct Client *source_p, const char *hpath, char *topic) |
90 |
{ |
91 |
char h_index[] = "index"; |
92 |
char path[HYB_PATH_MAX + 1]; |
93 |
struct stat sb; |
94 |
unsigned int i; |
95 |
|
96 |
if (EmptyString(topic)) |
97 |
topic = h_index; |
98 |
else |
99 |
for (i = 0; topic[i] != '\0'; ++i) |
100 |
topic[i] = ToLower(topic[i]); |
101 |
|
102 |
if (strpbrk(topic, "/\\")) |
103 |
{ |
104 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
105 |
me.name, source_p->name, topic); |
106 |
return; |
107 |
} |
108 |
|
109 |
if (strlen(hpath) + strlen(topic) + 1 > HYB_PATH_MAX) |
110 |
{ |
111 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
112 |
me.name, source_p->name, topic); |
113 |
return; |
114 |
} |
115 |
|
116 |
snprintf(path, sizeof(path), "%s/%s", hpath, topic); |
117 |
|
118 |
if (stat(path, &sb) < 0) |
119 |
{ |
120 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
121 |
me.name, source_p->name, topic); |
122 |
return; |
123 |
} |
124 |
|
125 |
if (!S_ISREG(sb.st_mode)) |
126 |
{ |
127 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
128 |
me.name, source_p->name, topic); |
129 |
return; |
130 |
} |
131 |
|
132 |
sendhelpfile(source_p, path, topic); |
133 |
} |
134 |
|
135 |
static void |
136 |
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
137 |
{ |
138 |
FILE *file; |
139 |
char line[HELPLEN]; |
140 |
|
141 |
if ((file = fopen(path, "r")) == NULL) |
142 |
{ |
143 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
144 |
me.name, source_p->name, topic); |
145 |
return; |
146 |
} |
147 |
|
148 |
if (fgets(line, sizeof(line), file) == NULL) |
149 |
{ |
150 |
sendto_one(source_p, ERR_HELPNOTFOUND, |
151 |
me.name, source_p->name, topic); |
152 |
return; |
153 |
} |
154 |
|
155 |
line[strlen(line) - 1] = '\0'; |
156 |
sendto_one(source_p, RPL_HELPSTART, |
157 |
me.name, source_p->name, topic, line); |
158 |
|
159 |
while (fgets(line, sizeof(line), file)) |
160 |
{ |
161 |
line[strlen(line) - 1] = '\0'; |
162 |
|
163 |
sendto_one(source_p, RPL_HELPTXT, |
164 |
me.name, source_p->name, topic, line); |
165 |
} |
166 |
|
167 |
fclose(file); |
168 |
sendto_one(source_p, RPL_ENDOFHELP, |
169 |
me.name, source_p->name, topic); |
170 |
} |
171 |
|
172 |
static struct Message help_msgtab = { |
173 |
"HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
174 |
{m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore} |
175 |
}; |
176 |
|
177 |
static struct Message uhelp_msgtab = { |
178 |
"UHELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
179 |
{m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore} |
180 |
}; |
181 |
|
182 |
static void |
183 |
module_init(void) |
184 |
{ |
185 |
mod_add_cmd(&help_msgtab); |
186 |
mod_add_cmd(&uhelp_msgtab); |
187 |
} |
188 |
|
189 |
static void |
190 |
module_exit(void) |
191 |
{ |
192 |
mod_del_cmd(&help_msgtab); |
193 |
mod_del_cmd(&uhelp_msgtab); |
194 |
} |
195 |
|
196 |
struct module module_entry = { |
197 |
.node = { NULL, NULL, NULL }, |
198 |
.name = NULL, |
199 |
.version = "$Revision$", |
200 |
.handle = NULL, |
201 |
.modinit = module_init, |
202 |
.modexit = module_exit, |
203 |
.flags = 0 |
204 |
}; |