]> jfr.im git - irc/rqf/shadowircd.git/blob - extensions/m_roleplay.c
Add extensions/m_roleplay, a module that provides various roleplaying commands.
[irc/rqf/shadowircd.git] / extensions / m_roleplay.c
1 #include "stdinc.h"
2 #include "ircd.h"
3 #include "client.h"
4 #include "modules.h"
5 #include "send.h"
6 #include "numeric.h"
7 #include "hash.h"
8 #include "s_serv.h"
9 #include "inline/stringops.h"
10 #include "chmode.h"
11
12 static int m_scene(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
13 static int m_fsay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
14 static int m_faction(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
15 static int m_npc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
16 static int m_npca(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
17 static int m_displaymsg(struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text);
18 static int me_roleplay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
19 static unsigned int mymode;
20
21 static int
22 _modinit(void)
23 {
24 /* initalize the +x and +d cmodes */
25 mymode = cflag_add('x', chm_simple);
26 if (mymode == 0)
27 return -1;
28
29 mymode = cflag_add('d', chm_simple);
30 if (mymode == 0)
31 return -1;
32
33 return 0;
34 }
35
36 static void
37 _moddeinit(void)
38 {
39 /* orphan the +x and +d cmodes on modunload */
40 cflag_orphan('x');
41
42 cflag_orphan('d');
43 }
44
45
46 struct Message scene_msgtab = {
47 "SCENE", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
49 };
50
51 struct Message ambiance_msgtab = {
52 "AMBIANCE", 0, 0, 0, MFLG_SLOW,
53 {mg_unreg, {m_scene, 3}, mg_ignore, mg_ignore, mg_ignore, {m_scene, 3}}
54 };
55
56 struct Message fsay_msgtab = {
57 "FSAY", 0, 0, 0, MFLG_SLOW,
58 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_fsay, 4}}
59 };
60
61 struct Message faction_msgtab = {
62 "FACTION", 0, 0, 0, MFLG_SLOW,
63 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_faction, 4}}
64 };
65
66 struct Message npc_msgtab = {
67 "NPC", 0, 0, 0, MFLG_SLOW,
68 {mg_unreg, {m_npc, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npc, 4}}
69 };
70
71 struct Message npca_msgtab = {
72 "NPCA", 0, 0, 0, MFLG_SLOW,
73 {mg_unreg, {m_npca, 4}, mg_ignore, mg_ignore, mg_ignore, {m_npca, 4}}
74 };
75
76 struct Message roleplay_msgtab = {
77 "ROLEPLAY", 0, 0, 0, MFLG_SLOW,
78 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_roleplay, 5}, mg_ignore}
79 };
80
81 mapi_clist_av1 roleplay_clist[] = { &scene_msgtab, &ambiance_msgtab, &fsay_msgtab, &faction_msgtab, &npc_msgtab, &npca_msgtab, &roleplay_msgtab, NULL };
82
83 DECLARE_MODULE_AV1(roleplay, _modinit, _moddeinit, roleplay_clist, NULL, NULL, "$m_roleplay 1.0 - Taros $");
84
85 static int
86 m_scene(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
87 {
88 m_displaymsg(source_p, parv[1], 0, 0, "=Scene=", parv[2]);
89 return 0;
90 }
91
92 static int
93 m_fsay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
94 {
95 m_displaymsg(source_p, parv[1], 0, 0, parv[2], parv[3]);
96 return 0;
97 }
98
99 static int
100 m_faction(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
101 {
102 m_displaymsg(source_p, parv[1], 0, 1, parv[2], parv[3]);
103 return 0;
104 }
105
106 static int
107 m_npc(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
108 {
109 m_displaymsg(source_p, parv[1], 1, 0, parv[2], parv[3]);
110 return 0;
111 }
112
113 static int
114 m_npca(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
115 {
116 m_displaymsg(source_p, parv[1], 1, 1, parv[2], parv[3]);
117 return 0;
118 }
119
120 static int
121 m_displaymsg(struct Client *source_p, const char *channel, int underline, int action, const char *nick, const char *text)
122 {
123 struct Channel *chptr;
124 struct membership *msptr;
125 char nick2[109];
126 char *nick3 = rb_strdup(nick);
127 char text2[BUFSIZE];
128
129 if((chptr = find_channel(channel)) == NULL)
130 {
131 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel);
132 return 0;
133 }
134
135 if(!(msptr = find_channel_membership(chptr, source_p)))
136 {
137 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
138 form_str(ERR_NOTONCHANNEL), chptr->chname);
139 return 0;
140 }
141
142 if(chptr->mode.mode & chmode_flags['d'])
143 {
144 sendto_one_numeric(source_p, 573, "%s :Roleplay commands are disabled on this channel (+d)", chptr->chname);
145 return 0;
146 }
147
148 if(!IsOper(source_p) || chptr->mode.mode & chmode_flags['x'])
149 {
150 if(chptr->mode.mode & chmode_flags['x'])
151 {
152 if(!is_chanop_voiced(msptr))
153 {
154 sendto_one(source_p, ":%s 482 %s %s :You are not a channel operator or voice, and thus cannot use roleplay commands on this channel.",
155 me.name, source_p->name, chptr->chname);
156 return 0;
157 }
158 }
159 else if(!is_any_op(msptr))
160 {
161 sendto_one(source_p, ":%s 482 %s %s :You are not a channel operator, and thus cannot use roleplay commands on this channel.",
162 me.name, source_p->name, chptr->chname);
163 return 0;
164 }
165 }
166
167 if(underline)
168 rb_snprintf(nick2, sizeof(nick2), "\x1F%s\x1F", strip_unprintable(nick3));
169 else
170 rb_snprintf(nick2, sizeof(nick2), "%s", strip_unprintable(nick3));
171
172 if(EmptyString(nick3))
173 {
174 sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname);
175 return 0;
176 }
177
178 if(action)
179 rb_snprintf(text2, sizeof(text2), "\1ACTION %s", text);
180 else
181 rb_snprintf(text2, sizeof(text2), "%s", text);
182
183 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", nick2, source_p->name, channel, text2);
184 sendto_match_servs(&me, "*", CAP_ENCAP, NOCAPS, "ENCAP * ROLEPLAY %s %s %s :%s",
185 source_p->name, channel, nick2, text2);
186 return 0;
187 }
188
189 static int
190 me_roleplay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
191 {
192 struct Channel *chptr;
193
194 /* Don't segfault if we get ENCAP * ROLEPLAY with an invalid channel.
195 * This shouldn't happen but it's best to be on the safe side. */
196 if((chptr = find_channel(parv[2])) == NULL)
197 return 0;
198
199 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[3], parv[1], parv[2], parv[4]);
200 return 0;
201 }