0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-03 04:18:55 +01:00
construct/modules/m_help.cc

122 lines
3.7 KiB
C++
Raw Normal View History

/*
* 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
*/
#include <ircd/stdinc.h>
#include <ircd/client.h>
#include <ircd/ircd.h>
#include <ircd/msg.h>
#include <ircd/numeric.h>
#include <ircd/send.h>
#include <ircd/s_conf.h>
#include <ircd/logger.h>
#include <ircd/parse.h>
#include <ircd/modules.h>
#include <ircd/hash.h>
#include <ircd/cache.h>
static const char help_desc[] =
"Provides the help facility for commands, modes, and server concepts";
static void m_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void mo_help(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void mo_uhelp(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
static void dohelp(struct Client *, int, const char *);
struct Message help_msgtab = {
"HELP", 0, 0, 0, 0,
{mg_unreg, {m_help, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_help, 0}}
};
struct Message uhelp_msgtab = {
"UHELP", 0, 0, 0, 0,
{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);
/*
* m_help - HELP message handler
*/
static void
2016-02-11 03:54:17 +01:00
m_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
}
/*
* mo_help - HELP message handler
*/
static void
2016-02-11 03:54:17 +01:00
mo_help(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
dohelp(source_p, HELP_OPER, parc > 1 ? parv[1] : NULL);
}
/*
* mo_uhelp - HELP message handler
* This is used so that opers can view the user help file without deopering
*/
static void
2016-02-11 03:54:17 +01:00
mo_uhelp(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
dohelp(source_p, HELP_USER, parc > 1 ? parv[1] : NULL);
}
static void
dohelp(struct Client *source_p, int flags, const char *topic)
{
static const char ntopic[] = "index";
2016-07-31 08:03:05 +02:00
std::shared_ptr<cachefile> hptr;
int linecnt = 0;
if(EmptyString(topic))
topic = ntopic;
hptr = flags & HELP_OPER ? help_dict_oper[topic] : help_dict_user[topic];
2007-12-04 02:35:55 +01:00
if(hptr == NULL || !(hptr->flags & flags))
{
sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
me.name, source_p->name, topic);
return;
}
2016-07-31 08:03:05 +02:00
for (auto it = hptr->contents.begin(); it != hptr->contents.end(); it++, linecnt++)
{
2016-07-31 08:03:05 +02:00
if (!linecnt)
{
sendto_one(source_p, form_str(RPL_HELPSTART),
me.name, source_p->name, topic, it->c_str());
continue;
}
sendto_one(source_p, form_str(RPL_HELPTXT),
2016-07-31 08:03:05 +02:00
me.name, source_p->name, topic, it->c_str());
}
sendto_one(source_p, form_str(RPL_ENDOFHELP),
me.name, source_p->name, topic);
}