2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_help.c: Provides help information to a user/operator.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char help_desc[] =
|
|
|
|
"Provides the help facility for commands, modes, and server concepts";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_help(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void mo_help(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void mo_uhelp(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void dohelp(client::client &, int, const char *);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message help_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"HELP", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}}
|
|
|
|
};
|
|
|
|
struct Message uhelp_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"UHELP", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_uhelp, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 help_clist[] = { &help_msgtab, &uhelp_msgtab, NULL };
|
2016-03-07 08:59:08 +01:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(help, NULL, NULL, help_clist, NULL, NULL, NULL, NULL, help_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* m_help - HELP message handler
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_help(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-15 10:17:35 +02:00
|
|
|
using namespace cache::help;
|
2016-08-14 01:42:12 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
dohelp(source, USER, parc > 1 ? parv[1] : NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mo_help - HELP message handler
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_help(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-15 10:17:35 +02:00
|
|
|
using namespace cache::help;
|
2016-08-14 01:42:12 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
dohelp(source, OPER, parc > 1 ? parv[1] : NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mo_uhelp - HELP message handler
|
|
|
|
* This is used so that opers can view the user help file without deopering
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_uhelp(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-15 10:17:35 +02:00
|
|
|
using namespace cache::help;
|
2016-08-14 01:42:12 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
dohelp(source, USER, parc > 1 ? parv[1] : NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
dohelp(client::client &source,
|
2016-08-14 01:42:12 +02:00
|
|
|
int type,
|
|
|
|
const char *topic)
|
|
|
|
try
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-14 01:42:12 +02:00
|
|
|
namespace help = cache::help;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-14 01:42:12 +02:00
|
|
|
static const char *const ntopic("index");
|
|
|
|
if (EmptyString(topic))
|
2007-01-25 07:40:21 +01:00
|
|
|
topic = ntopic;
|
|
|
|
|
2016-08-14 01:42:12 +02:00
|
|
|
std::shared_ptr<cache::file> file
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-14 01:42:12 +02:00
|
|
|
type & help::OPER? help::oper.at(topic):
|
|
|
|
type & help::USER? help::user.at(topic):
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!file || !(flags(*file) & type))
|
|
|
|
throw std::out_of_range(ntopic);
|
|
|
|
|
|
|
|
auto it(begin(contents(*file)));
|
|
|
|
if (it != end(contents(*file)))
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_HELPSTART),
|
2016-08-14 01:42:12 +02:00
|
|
|
me.name,
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
2016-08-14 01:42:12 +02:00
|
|
|
topic,
|
|
|
|
it->c_str());
|
|
|
|
|
|
|
|
for (++it; it != end(contents(*file)); ++it)
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_HELPTXT),
|
2016-08-14 01:42:12 +02:00
|
|
|
me.name,
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
2016-08-14 01:42:12 +02:00
|
|
|
topic,
|
|
|
|
it->c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_ENDOFHELP),
|
2016-08-14 01:42:12 +02:00
|
|
|
me.name,
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
2016-08-14 01:42:12 +02:00
|
|
|
topic);
|
|
|
|
}
|
|
|
|
catch(const std::out_of_range &e)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_HELPNOTFOUND),
|
2016-08-14 01:42:12 +02:00
|
|
|
me.name,
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
2016-08-14 01:42:12 +02:00
|
|
|
topic?: e.what());
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|