2010-12-10 00:44:24 +01:00
|
|
|
/*
|
|
|
|
* roleplay commands for charybdis.
|
|
|
|
*
|
|
|
|
* adds NPC, NPCA, and SCENE which allow users to send messages from 'fake'
|
|
|
|
* nicknames. in the case of NPC and NPCA, the nickname will be underlined
|
|
|
|
* to clearly show that it is fake. SCENE is a special case and not underlined.
|
|
|
|
* these commands only work on channels set +N
|
|
|
|
*
|
2014-03-03 05:25:47 +01:00
|
|
|
* also adds oper commands FSAY and FACTION, which are like NPC and NPCA
|
2010-12-10 00:44:24 +01:00
|
|
|
* except without the underline.
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2010-12-10 00:44:24 +01:00
|
|
|
* all of these messages have the hostmask npc.fakeuser.invalid, and their ident
|
|
|
|
* is the nickname of the user running the commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "ircd.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "inline/stringops.h"
|
|
|
|
#include "chmode.h"
|
|
|
|
#include "tgchange.h"
|
|
|
|
#include "channel.h"
|
2012-04-14 01:07:43 +02:00
|
|
|
#include "packet.h"
|
2013-04-27 11:57:44 +02:00
|
|
|
#include "messages.h"
|
2010-12-10 00:44:24 +01:00
|
|
|
|
2016-03-07 10:40:51 +01:00
|
|
|
static const char roleplay_desc[] =
|
|
|
|
"Adds a roleplaying system that allows faked nicknames to talk in a channel set +N";
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text);
|
|
|
|
static void me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
2010-12-10 00:44:24 +01:00
|
|
|
static unsigned int mymode;
|
|
|
|
|
|
|
|
static int
|
|
|
|
_modinit(void)
|
|
|
|
{
|
|
|
|
/* initalize the +N cmode */
|
|
|
|
mymode = cflag_add('N', chm_simple);
|
|
|
|
if (mymode == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_moddeinit(void)
|
|
|
|
{
|
|
|
|
/* orphan the +N cmode on modunload */
|
|
|
|
cflag_orphan('N');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct Message scene_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"SCENE", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this serves as an alias for people who are used to inspircd/unreal m_roleplay */
|
|
|
|
struct Message ambiance_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"AMBIANCE", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
struct Message fsay_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"FSAY", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
struct Message faction_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"FACTION", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
struct Message npc_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"NPC", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
struct Message npca_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"NPCA", 0, 0, 0, 0,
|
2010-12-10 00:44:24 +01:00
|
|
|
{mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
struct Message roleplay_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"ROLEPLAY", 0, 0, 0, 0,
|
2010-12-11 21:51:11 +01:00
|
|
|
{mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore}
|
2014-03-03 05:25:47 +01:00
|
|
|
};
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL };
|
|
|
|
|
2016-03-07 10:40:51 +01:00
|
|
|
DECLARE_MODULE_AV2(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, NULL, NULL, roleplay_desc);
|
2010-12-10 00:44:24 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, "=Scene=", parv[2]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, parv[2], parv[3]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(msgbuf_p, source_p, parv[1], 0, 1, parv[2], parv[3]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(msgbuf_p, source_p, parv[1], 1, 0, parv[2], parv[3]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(msgbuf_p, source_p, parv[1], 1, 1, parv[2], parv[3]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text)
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
|
|
|
struct Channel *chptr;
|
|
|
|
struct membership *msptr;
|
|
|
|
char nick2[NICKLEN+1];
|
2014-02-23 22:01:04 +01:00
|
|
|
char nick3[NICKLEN+1];
|
2013-08-24 05:11:22 +02:00
|
|
|
char text3[BUFSIZE];
|
2010-12-10 00:44:24 +01:00
|
|
|
char text2[BUFSIZE];
|
|
|
|
|
2014-02-23 22:01:04 +01:00
|
|
|
rb_strlcpy(nick3, nick, sizeof nick3);
|
|
|
|
|
2012-04-14 01:07:43 +02:00
|
|
|
if(!IsFloodDone(source_p))
|
|
|
|
flood_endgrace(source_p);
|
|
|
|
|
2010-12-10 00:44:24 +01:00
|
|
|
if((chptr = find_channel(channel)) == NULL)
|
|
|
|
{
|
2012-04-14 01:11:40 +02:00
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), channel);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(msptr = find_channel_membership(chptr, source_p)))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
|
|
|
|
form_str(ERR_NOTONCHANNEL), chptr->chname);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(chptr->mode.mode & chmode_flags['N']))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!can_send(chptr, source_p, msptr))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enforce flood stuff on roleplay commands */
|
|
|
|
if(flood_attack_channel(0, source_p, chptr, chptr->chname))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
/* enforce target change on roleplay commands */
|
|
|
|
if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_TARGCHANGE),
|
|
|
|
me.name, source_p->name, chptr->chname);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(underline)
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3));
|
2010-12-10 00:44:24 +01:00
|
|
|
else
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3));
|
2010-12-10 00:44:24 +01:00
|
|
|
|
|
|
|
/* don't allow nicks to be empty after stripping
|
|
|
|
* this prevents nastiness like fake factions, etc. */
|
|
|
|
if(EmptyString(nick3))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(text3, sizeof(text3), "%s (%s)", text, source_p->name);
|
2013-08-24 05:11:22 +02:00
|
|
|
|
2010-12-10 00:44:24 +01:00
|
|
|
if(action)
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(text2, sizeof(text2), "\1ACTION %s\1", text3);
|
2010-12-10 00:44:24 +01:00
|
|
|
else
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(text2, sizeof(text2), "%s", text3);
|
2010-12-10 00:44:24 +01:00
|
|
|
|
2013-08-24 05:11:22 +02:00
|
|
|
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", nick2, source_p->name, channel, text2);
|
2010-12-11 21:51:11 +01:00
|
|
|
sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s",
|
|
|
|
channel, nick2, text2);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:14:22 +01:00
|
|
|
me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-12-10 00:44:24 +01:00
|
|
|
{
|
|
|
|
struct Channel *chptr;
|
|
|
|
|
|
|
|
/* Don't segfault if we get ROLEPLAY with an invalid channel.
|
2010-12-11 21:51:11 +01:00
|
|
|
* This shouldn't happen but it's best to be on the safe side. */
|
|
|
|
if((chptr = find_channel(parv[1])) == NULL)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-12-10 00:44:24 +01:00
|
|
|
|
2014-03-03 05:25:47 +01:00
|
|
|
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[2], source_p->name, parv[1], parv[3]);
|
2010-12-10 00:44:24 +01:00
|
|
|
}
|