]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/core/m_mode.c
5549203f880dbbe55991db740673066cfc412731
[irc/rqf/shadowircd.git] / modules / core / m_mode.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_mode.c: Sets a user or channel mode.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 */
25
26 #include "stdinc.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "hash.h"
30 #include "match.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "s_user.h"
34 #include "s_conf.h"
35 #include "s_serv.h"
36 #include "logger.h"
37 #include "send.h"
38 #include "msg.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "packet.h"
42 #include "s_newconf.h"
43
44 struct module_modes ModuleModes;
45
46 static int m_mode(struct Client *, struct Client *, int, const char **);
47 static int ms_mode(struct Client *, struct Client *, int, const char **);
48 static int ms_tmode(struct Client *, struct Client *, int, const char **);
49 static int ms_mlock(struct Client *, struct Client *, int, const char **);
50 static int ms_bmask(struct Client *, struct Client *, int, const char **);
51
52 struct Message mode_msgtab = {
53 "MODE", 0, 0, 0, MFLG_SLOW,
54 {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}}
55 };
56 struct Message tmode_msgtab = {
57 "TMODE", 0, 0, 0, MFLG_SLOW,
58 {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore}
59 };
60 struct Message mlock_msgtab = {
61 "MLOCK", 0, 0, 0, MFLG_SLOW,
62 {mg_ignore, mg_ignore, {ms_mlock, 4}, {ms_mlock, 4}, mg_ignore, mg_ignore}
63 };
64 struct Message bmask_msgtab = {
65 "BMASK", 0, 0, 0, MFLG_SLOW,
66 {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore}
67 };
68
69 mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL };
70
71 DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $");
72
73 /*
74 * m_mode - MODE command handler
75 * parv[1] - channel
76 */
77 static int
78 m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
79 {
80 struct Channel *chptr = NULL;
81 struct membership *msptr;
82 int n = 2;
83 const char *dest;
84 int operspy = 0;
85
86 dest = parv[1];
87
88 if(IsOperSpy(source_p) && *dest == '!')
89 {
90 dest++;
91 operspy = 1;
92
93 if(EmptyString(dest))
94 {
95 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
96 me.name, source_p->name, "MODE");
97 return 0;
98 }
99 }
100
101 /* Now, try to find the channel in question */
102 if(!IsChanPrefix(*dest))
103 {
104 /* if here, it has to be a non-channel name */
105 user_mode(client_p, source_p, parc, parv);
106 return 0;
107 }
108
109 if(!check_channel_name(dest))
110 {
111 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
112 return 0;
113 }
114
115 chptr = find_channel(dest);
116
117 if(chptr == NULL)
118 {
119 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
120 form_str(ERR_NOSUCHCHANNEL), parv[1]);
121 return 0;
122 }
123
124 /* Now know the channel exists */
125 if(parc < n + 1)
126 {
127 if(operspy)
128 report_operspy(source_p, "MODE", chptr->chname);
129
130 sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
131 me.name, source_p->name, parv[1],
132 operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p));
133
134 sendto_one(source_p, form_str(RPL_CREATIONTIME),
135 me.name, source_p->name, parv[1], chptr->channelts);
136 }
137 else
138 {
139 msptr = find_channel_membership(chptr, source_p);
140
141 /* Finish the flood grace period... */
142 if(MyClient(source_p) && !IsFloodDone(source_p))
143 {
144 if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
145 flood_endgrace(source_p);
146 }
147
148 set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n);
149 }
150
151 return 0;
152 }
153
154 static int
155 ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
156 {
157 struct Channel *chptr;
158
159 chptr = find_channel(parv[1]);
160
161 if(chptr == NULL)
162 {
163 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
164 form_str(ERR_NOSUCHCHANNEL), parv[1]);
165 return 0;
166 }
167
168 set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
169
170 return 0;
171 }
172
173 static int
174 ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
175 {
176 struct Channel *chptr = NULL;
177 struct membership *msptr;
178
179 /* Now, try to find the channel in question */
180 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
181 {
182 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
183 return 0;
184 }
185
186 chptr = find_channel(parv[2]);
187
188 if(chptr == NULL)
189 {
190 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
191 form_str(ERR_NOSUCHCHANNEL), parv[2]);
192 return 0;
193 }
194
195 /* TS is higher, drop it. */
196 if(atol(parv[1]) > chptr->channelts)
197 return 0;
198
199 if(IsServer(source_p))
200 {
201 set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3);
202 }
203 else
204 {
205 msptr = find_channel_membership(chptr, source_p);
206
207 set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
208 }
209
210 return 0;
211 }
212
213 static int
214 ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
215 {
216 struct Channel *chptr = NULL;
217
218 /* Now, try to find the channel in question */
219 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
220 {
221 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
222 return 0;
223 }
224
225 chptr = find_channel(parv[2]);
226
227 if(chptr == NULL)
228 {
229 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
230 form_str(ERR_NOSUCHCHANNEL), parv[2]);
231 return 0;
232 }
233
234 /* TS is higher, drop it. */
235 if(atol(parv[1]) > chptr->channelts)
236 return 0;
237
238 if(IsServer(source_p))
239 set_channel_mlock(client_p, source_p, chptr, parv[3]);
240
241 return 0;
242 }
243
244 static int
245 ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
246 {
247 static char modebuf[BUFSIZE];
248 static char parabuf[BUFSIZE];
249 struct Channel *chptr;
250 rb_dlink_list *banlist;
251 const char *s;
252 char *t;
253 char *mbuf;
254 char *pbuf;
255 long mode_type;
256 int mlen;
257 int plen = 0;
258 int tlen;
259 int arglen;
260 int modecount = 0;
261 int needcap = NOCAPS;
262 int mems;
263 struct Client *fakesource_p;
264
265 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
266 return 0;
267
268 if((chptr = find_channel(parv[2])) == NULL)
269 return 0;
270
271 /* TS is higher, drop it. */
272 if(atol(parv[1]) > chptr->channelts)
273 return 0;
274
275 switch (parv[3][0])
276 {
277 case 'b':
278 banlist = &chptr->banlist;
279 mode_type = CHFL_BAN;
280 mems = ALL_MEMBERS;
281 break;
282
283 case 'e':
284 banlist = &chptr->exceptlist;
285 mode_type = CHFL_EXCEPTION;
286 needcap = CAP_EX;
287 mems = ONLY_CHANOPS;
288 break;
289
290 case 'I':
291 banlist = &chptr->invexlist;
292 mode_type = CHFL_INVEX;
293 needcap = CAP_IE;
294 mems = ONLY_CHANOPS;
295 break;
296
297 case 'q':
298 banlist = &chptr->quietlist;
299 mode_type = ModuleModes.CHFL_QUIET;
300 mems = ALL_MEMBERS;
301 break;
302
303 /* maybe we should just blindly propagate this? */
304 default:
305 return 0;
306 }
307
308 parabuf[0] = '\0';
309 s = LOCAL_COPY(parv[4]);
310
311 /* Hide connecting server on netburst -- jilles */
312 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
313 fakesource_p = &me;
314 else
315 fakesource_p = source_p;
316 mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
317 mbuf = modebuf + mlen;
318 pbuf = parabuf;
319
320 while(*s == ' ')
321 s++;
322
323 /* next char isnt a space, point t to the next one */
324 if((t = strchr(s, ' ')) != NULL)
325 {
326 *t++ = '\0';
327
328 /* double spaces will break the parser */
329 while(*t == ' ')
330 t++;
331 }
332
333 /* couldve skipped spaces and got nothing.. */
334 while(!EmptyString(s))
335 {
336 /* ban with a leading ':' -- this will break the protocol */
337 if(*s == ':')
338 goto nextban;
339
340 tlen = strlen(s);
341
342 /* I dont even want to begin parsing this.. */
343 if(tlen > MODEBUFLEN)
344 break;
345
346 if(add_id(fakesource_p, chptr, s, banlist, mode_type))
347 {
348 /* this new one wont fit.. */
349 if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
350 modecount >= MAXMODEPARAMS)
351 {
352 *mbuf = '\0';
353 *(pbuf - 1) = '\0';
354 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
355 sendto_server(client_p, chptr, needcap, CAP_TS6,
356 "%s %s", modebuf, parabuf);
357
358 mbuf = modebuf + mlen;
359 pbuf = parabuf;
360 plen = modecount = 0;
361 }
362
363 *mbuf++ = parv[3][0];
364 arglen = rb_sprintf(pbuf, "%s ", s);
365 pbuf += arglen;
366 plen += arglen;
367 modecount++;
368 }
369
370 nextban:
371 s = t;
372
373 if(s != NULL)
374 {
375 if((t = strchr(s, ' ')) != NULL)
376 {
377 *t++ = '\0';
378
379 while(*t == ' ')
380 t++;
381 }
382 }
383 }
384
385 if(modecount)
386 {
387 *mbuf = '\0';
388 *(pbuf - 1) = '\0';
389 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
390 sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf);
391 }
392
393 sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
394 source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
395 return 0;
396 }
397