]> jfr.im git - solanum.git/blame - modules/core/m_mode.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / core / m_mode.c
CommitLineData
212380e3
AC
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 * $Id: m_mode.c 1006 2006-03-09 15:32:14Z nenolod $
25 */
26
27#include "stdinc.h"
212380e3
AC
28#include "channel.h"
29#include "client.h"
30#include "hash.h"
4562c604 31#include "match.h"
212380e3
AC
32#include "ircd.h"
33#include "numeric.h"
34#include "s_user.h"
35#include "s_conf.h"
36#include "s_serv.h"
4016731b 37#include "logger.h"
212380e3
AC
38#include "send.h"
39#include "msg.h"
40#include "parse.h"
41#include "modules.h"
42#include "packet.h"
212380e3
AC
43#include "s_newconf.h"
44
428ca87b
AC
45static int m_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
46static int ms_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
47static int ms_tmode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
48static int ms_mlock(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
49static int ms_bmask(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
50
51struct Message mode_msgtab = {
7baa37a9 52 "MODE", 0, 0, 0, 0,
212380e3
AC
53 {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}}
54};
55struct Message tmode_msgtab = {
7baa37a9 56 "TMODE", 0, 0, 0, 0,
212380e3
AC
57 {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore}
58};
8727cbe8 59struct Message mlock_msgtab = {
7baa37a9 60 "MLOCK", 0, 0, 0, 0,
6b8db2da 61 {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore}
8727cbe8 62};
212380e3 63struct Message bmask_msgtab = {
7baa37a9 64 "BMASK", 0, 0, 0, 0,
212380e3
AC
65 {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore}
66};
67
8727cbe8 68mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL };
212380e3
AC
69
70DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $");
71
72/*
73 * m_mode - MODE command handler
212380e3
AC
74 * parv[1] - channel
75 */
76static int
428ca87b 77m_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
78{
79 struct Channel *chptr = NULL;
80 struct membership *msptr;
81 int n = 2;
82 const char *dest;
83 int operspy = 0;
84
85 dest = parv[1];
86
87 if(IsOperSpy(source_p) && *dest == '!')
88 {
89 dest++;
90 operspy = 1;
91
92 if(EmptyString(dest))
93 {
94 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
95 me.name, source_p->name, "MODE");
96 return 0;
97 }
98 }
99
100 /* Now, try to find the channel in question */
101 if(!IsChanPrefix(*dest))
102 {
103 /* if here, it has to be a non-channel name */
104 user_mode(client_p, source_p, parc, parv);
105 return 0;
106 }
107
108 if(!check_channel_name(dest))
109 {
110 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
111 return 0;
112 }
113
114 chptr = find_channel(dest);
115
116 if(chptr == NULL)
117 {
118 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
119 form_str(ERR_NOSUCHCHANNEL), parv[1]);
120 return 0;
121 }
122
123 /* Now know the channel exists */
124 if(parc < n + 1)
125 {
126 if(operspy)
127 report_operspy(source_p, "MODE", chptr->chname);
128
129 sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
130 me.name, source_p->name, parv[1],
131 operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p));
132
133 sendto_one(source_p, form_str(RPL_CREATIONTIME),
134 me.name, source_p->name, parv[1], chptr->channelts);
135 }
136 else
137 {
138 msptr = find_channel_membership(chptr, source_p);
139
212380e3
AC
140 /* Finish the flood grace period... */
141 if(MyClient(source_p) && !IsFloodDone(source_p))
142 {
c7b2fd3d 143 if(!((parc == 3) && (parv[2][0] == 'b' || parv[2][0] == 'q') && (parv[2][1] == '\0')))
212380e3
AC
144 flood_endgrace(source_p);
145 }
146
147 set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n);
148 }
149
150 return 0;
151}
152
153static int
428ca87b 154ms_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
155{
156 struct Channel *chptr;
157
158 chptr = find_channel(parv[1]);
159
160 if(chptr == NULL)
161 {
162 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
163 form_str(ERR_NOSUCHCHANNEL), parv[1]);
164 return 0;
165 }
166
167 set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
168
169 return 0;
170}
171
172static int
428ca87b 173ms_tmode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
174{
175 struct Channel *chptr = NULL;
176 struct membership *msptr;
177
178 /* Now, try to find the channel in question */
179 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
180 {
181 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
182 return 0;
183 }
184
185 chptr = find_channel(parv[2]);
186
187 if(chptr == NULL)
188 {
189 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
190 form_str(ERR_NOSUCHCHANNEL), parv[2]);
191 return 0;
192 }
193
194 /* TS is higher, drop it. */
195 if(atol(parv[1]) > chptr->channelts)
196 return 0;
197
198 if(IsServer(source_p))
199 {
200 set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3);
201 }
202 else
203 {
204 msptr = find_channel_membership(chptr, source_p);
205
212380e3
AC
206 set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
207 }
208
209 return 0;
210}
211
8727cbe8 212static int
428ca87b 213ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
8727cbe8
AC
214{
215 struct Channel *chptr = NULL;
216
217 /* Now, try to find the channel in question */
218 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
219 {
220 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
221 return 0;
222 }
223
224 chptr = find_channel(parv[2]);
225
226 if(chptr == NULL)
227 {
228 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
229 form_str(ERR_NOSUCHCHANNEL), parv[2]);
230 return 0;
231 }
232
233 /* TS is higher, drop it. */
234 if(atol(parv[1]) > chptr->channelts)
235 return 0;
236
237 if(IsServer(source_p))
6fb6bd15 238 set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE);
8727cbe8
AC
239
240 return 0;
241}
242
d1316b19
JT
243static void
244possibly_remove_lower_forward(struct Client *fakesource_p, int mems,
245 struct Channel *chptr, rb_dlink_list *banlist, int mchar,
246 const char *mask, const char *forward)
247{
248 struct Ban *actualBan;
249 rb_dlink_node *ptr;
250
251 RB_DLINK_FOREACH(ptr, banlist->head)
252 {
253 actualBan = ptr->data;
254 if(!irccmp(actualBan->banstr, mask) &&
255 (actualBan->forward == NULL ||
256 irccmp(actualBan->forward, forward) < 0))
257 {
258 sendto_channel_local(mems, chptr, ":%s MODE %s -%c %s%s%s",
259 fakesource_p->name,
260 chptr->chname,
261 mchar,
262 actualBan->banstr,
263 actualBan->forward ? "$" : "",
264 actualBan->forward ? actualBan->forward : "");
265 rb_dlinkDelete(&actualBan->node, banlist);
266 free_ban(actualBan);
267 return;
268 }
269 }
270}
271
212380e3 272static int
428ca87b 273ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
274{
275 static char modebuf[BUFSIZE];
276 static char parabuf[BUFSIZE];
277 struct Channel *chptr;
5b96d9a6 278 rb_dlink_list *banlist;
765d839d 279 char *s, *forward;
212380e3
AC
280 char *t;
281 char *mbuf;
282 char *pbuf;
283 long mode_type;
284 int mlen;
285 int plen = 0;
286 int tlen;
287 int arglen;
288 int modecount = 0;
289 int needcap = NOCAPS;
290 int mems;
291 struct Client *fakesource_p;
292
293 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
294 return 0;
295
296 if((chptr = find_channel(parv[2])) == NULL)
297 return 0;
298
299 /* TS is higher, drop it. */
300 if(atol(parv[1]) > chptr->channelts)
301 return 0;
302
303 switch (parv[3][0])
304 {
305 case 'b':
306 banlist = &chptr->banlist;
307 mode_type = CHFL_BAN;
308 mems = ALL_MEMBERS;
309 break;
310
311 case 'e':
312 banlist = &chptr->exceptlist;
313 mode_type = CHFL_EXCEPTION;
314 needcap = CAP_EX;
315 mems = ONLY_CHANOPS;
316 break;
317
318 case 'I':
319 banlist = &chptr->invexlist;
320 mode_type = CHFL_INVEX;
321 needcap = CAP_IE;
322 mems = ONLY_CHANOPS;
323 break;
324
325 case 'q':
326 banlist = &chptr->quietlist;
327 mode_type = CHFL_QUIET;
328 mems = ALL_MEMBERS;
329 break;
330
331 /* maybe we should just blindly propagate this? */
332 default:
333 return 0;
334 }
335
336 parabuf[0] = '\0';
337 s = LOCAL_COPY(parv[4]);
338
339 /* Hide connecting server on netburst -- jilles */
340 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
341 fakesource_p = &me;
342 else
343 fakesource_p = source_p;
5203cba5 344 mlen = sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
212380e3
AC
345 mbuf = modebuf + mlen;
346 pbuf = parabuf;
347
348 while(*s == ' ')
349 s++;
350
351 /* next char isnt a space, point t to the next one */
352 if((t = strchr(s, ' ')) != NULL)
353 {
354 *t++ = '\0';
355
356 /* double spaces will break the parser */
357 while(*t == ' ')
358 t++;
359 }
360
361 /* couldve skipped spaces and got nothing.. */
362 while(!EmptyString(s))
363 {
364 /* ban with a leading ':' -- this will break the protocol */
365 if(*s == ':')
366 goto nextban;
367
368 tlen = strlen(s);
369
370 /* I dont even want to begin parsing this.. */
371 if(tlen > MODEBUFLEN)
372 break;
373
765d839d
EM
374 if((forward = strchr(s+1, '$')) != NULL)
375 {
376 *forward++ = '\0';
377 if(*forward == '\0')
23f6b63a 378 tlen--, forward = NULL;
fea6157d
JT
379 else
380 possibly_remove_lower_forward(fakesource_p,
381 mems, chptr, banlist,
382 parv[3][0], s, forward);
765d839d
EM
383 }
384
385 if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type))
212380e3
AC
386 {
387 /* this new one wont fit.. */
388 if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
389 modecount >= MAXMODEPARAMS)
390 {
391 *mbuf = '\0';
392 *(pbuf - 1) = '\0';
393 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
212380e3
AC
394
395 mbuf = modebuf + mlen;
396 pbuf = parabuf;
397 plen = modecount = 0;
398 }
399
23f6b63a
JT
400 if (forward != NULL)
401 forward[-1] = '$';
402
212380e3 403 *mbuf++ = parv[3][0];
5203cba5 404 arglen = sprintf(pbuf, "%s ", s);
212380e3
AC
405 pbuf += arglen;
406 plen += arglen;
407 modecount++;
408 }
409
410 nextban:
411 s = t;
412
413 if(s != NULL)
414 {
415 if((t = strchr(s, ' ')) != NULL)
416 {
417 *t++ = '\0';
418
419 while(*t == ' ')
420 t++;
421 }
422 }
423 }
424
425 if(modecount)
426 {
427 *mbuf = '\0';
428 *(pbuf - 1) = '\0';
429 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
212380e3
AC
430 }
431
432 sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
433 source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
434 return 0;
435}