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