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