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