]>
Commit | Line | Data |
---|---|---|
8ffa8275 BG |
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 | * | |
55abcbb2 | 9 | * also adds oper commands FSAY and FACTION, which are like NPC and NPCA |
8ffa8275 | 10 | * except without the underline. |
55abcbb2 | 11 | * |
8ffa8275 BG |
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" | |
23485ebe | 29 | #include "packet.h" |
bd0d352f | 30 | #include "messages.h" |
8ffa8275 | 31 | |
02369fa7 EM |
32 | static const char roleplay_desc[] = |
33 | "Adds a roleplaying system that allows faked nicknames to talk in a channel set +N"; | |
34 | ||
760bafda AC |
35 | static int m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); |
36 | static int m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
37 | static int m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
38 | static int m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
39 | static int m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
40 | static int m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text); | |
41 | static int me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
8ffa8275 BG |
42 | static unsigned int mymode; |
43 | ||
44 | static 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 | ||
55 | static void | |
56 | _moddeinit(void) | |
57 | { | |
58 | /* orphan the +N cmode on modunload */ | |
59 | cflag_orphan('N'); | |
60 | } | |
61 | ||
62 | ||
63 | struct Message scene_msgtab = { | |
7baa37a9 | 64 | "SCENE", 0, 0, 0, 0, |
8ffa8275 BG |
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 */ | |
69 | struct Message ambiance_msgtab = { | |
7baa37a9 | 70 | "AMBIANCE", 0, 0, 0, 0, |
8ffa8275 | 71 | {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}} |
55abcbb2 | 72 | }; |
8ffa8275 BG |
73 | |
74 | struct Message fsay_msgtab = { | |
7baa37a9 | 75 | "FSAY", 0, 0, 0, 0, |
8ffa8275 | 76 | {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}} |
55abcbb2 | 77 | }; |
8ffa8275 BG |
78 | |
79 | struct Message faction_msgtab = { | |
7baa37a9 | 80 | "FACTION", 0, 0, 0, 0, |
8ffa8275 | 81 | {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}} |
55abcbb2 | 82 | }; |
8ffa8275 BG |
83 | |
84 | struct Message npc_msgtab = { | |
7baa37a9 | 85 | "NPC", 0, 0, 0, 0, |
8ffa8275 | 86 | {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}} |
55abcbb2 | 87 | }; |
8ffa8275 BG |
88 | |
89 | struct Message npca_msgtab = { | |
7baa37a9 | 90 | "NPCA", 0, 0, 0, 0, |
8ffa8275 | 91 | {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}} |
55abcbb2 | 92 | }; |
8ffa8275 BG |
93 | |
94 | struct Message roleplay_msgtab = { | |
7baa37a9 | 95 | "ROLEPLAY", 0, 0, 0, 0, |
6816e338 | 96 | {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 4}, mg_ignore} |
55abcbb2 | 97 | }; |
8ffa8275 BG |
98 | |
99 | mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL }; | |
100 | ||
02369fa7 | 101 | DECLARE_MODULE_AV2(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, NULL, NULL, roleplay_desc); |
8ffa8275 BG |
102 | |
103 | static int | |
760bafda | 104 | m_scene(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 | 105 | { |
760bafda | 106 | m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, "=Scene=", parv[2]); |
8ffa8275 BG |
107 | return 0; |
108 | } | |
109 | ||
110 | static int | |
760bafda | 111 | m_fsay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 | 112 | { |
760bafda | 113 | m_displaymsg(msgbuf_p, source_p, parv[1], 0, 0, parv[2], parv[3]); |
8ffa8275 BG |
114 | return 0; |
115 | } | |
116 | ||
117 | static int | |
760bafda | 118 | m_faction(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 | 119 | { |
760bafda | 120 | m_displaymsg(msgbuf_p, source_p, parv[1], 0, 1, parv[2], parv[3]); |
8ffa8275 BG |
121 | return 0; |
122 | } | |
123 | ||
124 | static int | |
760bafda | 125 | m_npc(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 | 126 | { |
760bafda | 127 | m_displaymsg(msgbuf_p, source_p, parv[1], 1, 0, parv[2], parv[3]); |
8ffa8275 BG |
128 | return 0; |
129 | } | |
130 | ||
131 | static int | |
760bafda | 132 | m_npca(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 | 133 | { |
760bafda | 134 | m_displaymsg(msgbuf_p, source_p, parv[1], 1, 1, parv[2], parv[3]); |
8ffa8275 BG |
135 | return 0; |
136 | } | |
137 | ||
138 | static int | |
760bafda | 139 | m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text) |
8ffa8275 BG |
140 | { |
141 | struct Channel *chptr; | |
142 | struct membership *msptr; | |
143 | char nick2[NICKLEN+1]; | |
a6b29d3e | 144 | char nick3[NICKLEN+1]; |
e03fc000 | 145 | char text3[BUFSIZE]; |
8ffa8275 BG |
146 | char text2[BUFSIZE]; |
147 | ||
a6b29d3e JT |
148 | rb_strlcpy(nick3, nick, sizeof nick3); |
149 | ||
23485ebe JT |
150 | if(!IsFloodDone(source_p)) |
151 | flood_endgrace(source_p); | |
152 | ||
8ffa8275 BG |
153 | if((chptr = find_channel(channel)) == NULL) |
154 | { | |
b97e1bf6 JT |
155 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, |
156 | form_str(ERR_NOSUCHCHANNEL), channel); | |
8ffa8275 BG |
157 | return 0; |
158 | } | |
159 | ||
160 | if(!(msptr = find_channel_membership(chptr, source_p))) | |
161 | { | |
162 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
163 | form_str(ERR_NOTONCHANNEL), chptr->chname); | |
164 | return 0; | |
165 | } | |
166 | ||
167 | if(!(chptr->mode.mode & chmode_flags['N'])) | |
168 | { | |
169 | sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname); | |
170 | return 0; | |
171 | } | |
172 | ||
173 | if(!can_send(chptr, source_p, msptr)) | |
174 | { | |
175 | sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname); | |
176 | return 0; | |
177 | } | |
178 | ||
179 | /* enforce flood stuff on roleplay commands */ | |
180 | if(flood_attack_channel(0, source_p, chptr, chptr->chname)) | |
181 | return 0; | |
182 | ||
183 | /* enforce target change on roleplay commands */ | |
184 | if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr)) | |
185 | { | |
186 | sendto_one(source_p, form_str(ERR_TARGCHANGE), | |
187 | me.name, source_p->name, chptr->chname); | |
188 | return 0; | |
189 | } | |
190 | ||
191 | if(underline) | |
5203cba5 | 192 | snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3)); |
8ffa8275 | 193 | else |
5203cba5 | 194 | snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3)); |
8ffa8275 BG |
195 | |
196 | /* don't allow nicks to be empty after stripping | |
197 | * this prevents nastiness like fake factions, etc. */ | |
198 | if(EmptyString(nick3)) | |
199 | { | |
200 | sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname); | |
201 | return 0; | |
202 | } | |
203 | ||
5203cba5 | 204 | snprintf(text3, sizeof(text3), "%s (%s)", text, source_p->name); |
e03fc000 | 205 | |
8ffa8275 | 206 | if(action) |
5203cba5 | 207 | snprintf(text2, sizeof(text2), "\1ACTION %s\1", text3); |
8ffa8275 | 208 | else |
5203cba5 | 209 | snprintf(text2, sizeof(text2), "%s", text3); |
8ffa8275 | 210 | |
e03fc000 | 211 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", nick2, source_p->name, channel, text2); |
6816e338 BG |
212 | sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s :%s", |
213 | channel, nick2, text2); | |
8ffa8275 BG |
214 | return 0; |
215 | } | |
216 | ||
217 | static int | |
760bafda | 218 | me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8ffa8275 BG |
219 | { |
220 | struct Channel *chptr; | |
221 | ||
222 | /* Don't segfault if we get ROLEPLAY with an invalid channel. | |
6816e338 BG |
223 | * This shouldn't happen but it's best to be on the safe side. */ |
224 | if((chptr = find_channel(parv[1])) == NULL) | |
8ffa8275 BG |
225 | return 0; |
226 | ||
55abcbb2 | 227 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[2], source_p->name, parv[1], parv[3]); |
8ffa8275 BG |
228 | return 0; |
229 | } |