]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/m_roleplay.c
Bring up updated roleplay module from charybdis.
[irc/rqf/shadowircd.git] / extensions / m_roleplay.c
CommitLineData
a26bd774
G
1/*
2 * roleplay commands for charybdis.
3 *
4 * adds NPC, NPCA, and SCENE which allow users to send messages from 'fake'
5 * nicknames. in the case of NPC and NPCA, the nickname will be underlined
6 * to clearly show that it is fake. SCENE is a special case and not underlined.
7 * these commands only work on channels set +N
8 *
9 * also adds oper commands FSAY and FACTION, which are like NPC and NPCA
10 * except without the underline.
11 *
12 * all of these messages have the hostmask npc.fakeuser.invalid, and their ident
13 * is the nickname of the user running the commands.
14 */
15
16
a4d2230f
G
17#include "stdinc.h"
18#include "ircd.h"
19#include "client.h"
20#include "modules.h"
21#include "send.h"
22#include "numeric.h"
23#include "hash.h"
24#include "s_serv.h"
25#include "inline/stringops.h"
26#include "chmode.h"
a26bd774
G
27#include "tgchange.h"
28#include "channel.h"
a4d2230f
G
29
30static int m_scene(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
31static int m_fsay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
32static int m_faction(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
33static int m_npc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
34static int m_npca(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
35static int m_displaymsg(struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text);
36static int me_roleplay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
37static unsigned int mymode;
38
39static int
40_modinit(void)
41{
a26bd774
G
42 /* initalize the +N cmode */
43 mymode = cflag_add('N', chm_simple);
a4d2230f
G
44 if (mymode == 0)
45 return -1;
46
47 return 0;
48}
49
50static void
51_moddeinit(void)
52{
a26bd774
G
53 /* orphan the +N cmode on modunload */
54 cflag_orphan('N');
a4d2230f
G
55}
56
57
58struct Message scene_msgtab = {
59 "SCENE", 0, 0, 0, MFLG_SLOW,
60 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
61};
62
a26bd774 63/* this serves as an alias for people who are used to inspircd/unreal m_roleplay */
a4d2230f
G
64struct Message ambiance_msgtab = {
65 "AMBIANCE", 0, 0, 0, MFLG_SLOW,
66 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
67};
68
69struct Message fsay_msgtab = {
70 "FSAY", 0, 0, 0, MFLG_SLOW,
71 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}}
72};
73
74struct Message faction_msgtab = {
75 "FACTION", 0, 0, 0, MFLG_SLOW,
76 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}}
77};
78
79struct Message npc_msgtab = {
80 "NPC", 0, 0, 0, MFLG_SLOW,
81 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}}
82};
83
84struct Message npca_msgtab = {
85 "NPCA", 0, 0, 0, MFLG_SLOW,
86 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}}
87};
88
89struct Message roleplay_msgtab = {
90 "ROLEPLAY", 0, 0, 0, MFLG_SLOW,
a26bd774 91 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore}
a4d2230f
G
92};
93
94mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL };
95
a26bd774 96DECLARE_MODULE_AV1(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, "$m_roleplay$");
a4d2230f
G
97
98static int
99m_scene(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
100{
101 m_displaymsg(source_p, parv[1], 0, 0, "=Scene=", parv[2]);
102 return 0;
103}
104
105static int
106m_fsay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
107{
108 m_displaymsg(source_p, parv[1], 0, 0, parv[2], parv[3]);
109 return 0;
110}
111
112static int
113m_faction(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
114{
115 m_displaymsg(source_p, parv[1], 0, 1, parv[2], parv[3]);
116 return 0;
117}
118
119static int
120m_npc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
121{
122 m_displaymsg(source_p, parv[1], 1, 0, parv[2], parv[3]);
123 return 0;
124}
125
126static int
127m_npca(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
128{
129 m_displaymsg(source_p, parv[1], 1, 1, parv[2], parv[3]);
130 return 0;
131}
132
133static int
134m_displaymsg(struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text)
135{
136 struct Channel *chptr;
137 struct membership *msptr;
a26bd774 138 char nick2[NICKLEN+1];
a4d2230f
G
139 char *nick3 = rb_strdup(nick);
140 char text2[BUFSIZE];
141
142 if((chptr = find_channel(channel)) == NULL)
143 {
144 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel);
145 return 0;
146 }
147
148 if(!(msptr = find_channel_membership(chptr, source_p)))
149 {
150 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
151 form_str(ERR_NOTONCHANNEL), chptr->chname);
152 return 0;
153 }
154
a26bd774 155 if(!(chptr->mode.mode & chmode_flags['E']))
a4d2230f 156 {
a26bd774 157 sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname);
a4d2230f
G
158 return 0;
159 }
160
a26bd774 161 if(!can_send(chptr, source_p, msptr))
a4d2230f 162 {
a26bd774
G
163 sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname);
164 return 0;
165 }
166
167 /* enforce flood stuff on roleplay commands */
168 if(flood_attack_channel(0, source_p, chptr, chptr->chname))
169 return 0;
170
171 /* enforce target change on roleplay commands */
172 if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr))
173 {
174 sendto_one(source_p, form_str(ERR_TARGCHANGE),
175 me.name, source_p->name, chptr->chname);
176 return 0;
a4d2230f
G
177 }
178
179 if(underline)
180 rb_snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3));
181 else
182 rb_snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3));
183
a26bd774
G
184 /* don't allow nicks to be empty after stripping
185 * this prevents nastiness like fake factions, etc. */
a4d2230f
G
186 if(EmptyString(nick3))
187 {
188 sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname);
189 return 0;
190 }
191
192 if(action)
193 rb_snprintf(text2, sizeof(text2), "\1ACTION %s", text);
194 else
195 rb_snprintf(text2, sizeof(text2), "%s", text);
196
197 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", nick2, source_p->name, channel, text2);
a26bd774
G
198 sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s",
199 channel, nick2, text2);
a4d2230f
G
200 return 0;
201}
202
203static int
204me_roleplay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
205{
206 struct Channel *chptr;
207
a26bd774 208 /* Don't segfault if we get ROLEPLAY with an invalid channel.
a4d2230f 209 * This shouldn't happen but it's best to be on the safe side. */
a26bd774 210 if((chptr = find_channel(parv[1])) == NULL)
a4d2230f
G
211 return 0;
212
a26bd774 213 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[2], source_p->name, parv[1], parv[3]);
a4d2230f
G
214 return 0;
215}