]> jfr.im git - solanum.git/blame_incremental - extensions/m_roleplay.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / extensions / m_roleplay.c
... / ...
CommitLineData
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
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"
27#include "tgchange.h"
28#include "channel.h"
29#include "packet.h"
30#include "messages.h"
31
32static int m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
33static int m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
34static int m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
35static int m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
36static int m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
37static int m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text);
38static int me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
39static unsigned int mymode;
40
41static int
42_modinit(void)
43{
44 /* initalize the +N cmode */
45 mymode = cflag_add('N', chm_simple);
46 if (mymode == 0)
47 return -1;
48
49 return 0;
50}
51
52static void
53_moddeinit(void)
54{
55 /* orphan the +N cmode on modunload */
56 cflag_orphan('N');
57}
58
59
60struct Message scene_msgtab = {
61 "SCENE", 0, 0, 0, 0,
62 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
63};
64
65/* this serves as an alias for people who are used to inspircd/unreal m_roleplay */
66struct Message ambiance_msgtab = {
67 "AMBIANCE", 0, 0, 0, 0,
68 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
69};
70
71struct Message fsay_msgtab = {
72 "FSAY", 0, 0, 0, 0,
73 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}}
74};
75
76struct Message faction_msgtab = {
77 "FACTION", 0, 0, 0, 0,
78 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}}
79};
80
81struct Message npc_msgtab = {
82 "NPC", 0, 0, 0, 0,
83 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}}
84};
85
86struct Message npca_msgtab = {
87 "NPCA", 0, 0, 0, 0,
88 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}}
89};
90
91struct Message roleplay_msgtab = {
92 "ROLEPLAY", 0, 0, 0, 0,
93 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore}
94};
95
96mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL };
97
98DECLARE_MODULE_AV1(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, "$m_roleplay$");
99
100static int
101m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
102{
103 m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, "=Scene=", parv[2]);
104 return 0;
105}
106
107static int
108m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
109{
110 m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, parv[2], parv[3]);
111 return 0;
112}
113
114static int
115m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
116{
117 m_displaymsg(msgbuf_p, source_p, parv[1], 0, 1, parv[2], parv[3]);
118 return 0;
119}
120
121static int
122m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
123{
124 m_displaymsg(msgbuf_p, source_p, parv[1], 1, 0, parv[2], parv[3]);
125 return 0;
126}
127
128static int
129m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
130{
131 m_displaymsg(msgbuf_p, source_p, parv[1], 1, 1, parv[2], parv[3]);
132 return 0;
133}
134
135static int
136m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text)
137{
138 struct Channel *chptr;
139 struct membership *msptr;
140 char nick2[NICKLEN+1];
141 char nick3[NICKLEN+1];
142 char text3[BUFSIZE];
143 char text2[BUFSIZE];
144
145 rb_strlcpy(nick3, nick, sizeof nick3);
146
147 if(!IsFloodDone(source_p))
148 flood_endgrace(source_p);
149
150 if((chptr = find_channel(channel)) == NULL)
151 {
152 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
153 form_str(ERR_NOSUCHCHANNEL), channel);
154 return 0;
155 }
156
157 if(!(msptr = find_channel_membership(chptr, source_p)))
158 {
159 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
160 form_str(ERR_NOTONCHANNEL), chptr->chname);
161 return 0;
162 }
163
164 if(!(chptr->mode.mode & chmode_flags['N']))
165 {
166 sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname);
167 return 0;
168 }
169
170 if(!can_send(chptr, source_p, msptr))
171 {
172 sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname);
173 return 0;
174 }
175
176 /* enforce flood stuff on roleplay commands */
177 if(flood_attack_channel(0, source_p, chptr, chptr->chname))
178 return 0;
179
180 /* enforce target change on roleplay commands */
181 if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr))
182 {
183 sendto_one(source_p, form_str(ERR_TARGCHANGE),
184 me.name, source_p->name, chptr->chname);
185 return 0;
186 }
187
188 if(underline)
189 snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3));
190 else
191 snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3));
192
193 /* don't allow nicks to be empty after stripping
194 * this prevents nastiness like fake factions, etc. */
195 if(EmptyString(nick3))
196 {
197 sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname);
198 return 0;
199 }
200
201 snprintf(text3, sizeof(text3), "%s (%s)", text, source_p->name);
202
203 if(action)
204 snprintf(text2, sizeof(text2), "\1ACTION %s\1", text3);
205 else
206 snprintf(text2, sizeof(text2), "%s", text3);
207
208 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", nick2, source_p->name, channel, text2);
209 sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s",
210 channel, nick2, text2);
211 return 0;
212}
213
214static int
215me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
216{
217 struct Channel *chptr;
218
219 /* Don't segfault if we get ROLEPLAY with an invalid channel.
220 * This shouldn't happen but it's best to be on the safe side. */
221 if((chptr = find_channel(parv[1])) == NULL)
222 return 0;
223
224 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[2], source_p->name, parv[1], parv[3]);
225 return 0;
226}