2 * ircd-ratbox: A slightly useful ircd.
3 * m_mode.c: Sets a user or channel mode.
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
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.
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.
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
41 #include "s_newconf.h"
43 static const char mode_desc
[] =
44 "Provides the MODE and MLOCK client and server commands, and TS6 server-to-server TMODE and BMASK commands";
46 static void m_mode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static void ms_mode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static void ms_tmode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
49 static void ms_mlock(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 static void ms_bmask(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
52 struct Message mode_msgtab
= {
54 {mg_unreg
, {m_mode
, 2}, {m_mode
, 3}, {ms_mode
, 3}, mg_ignore
, {m_mode
, 2}}
56 struct Message tmode_msgtab
= {
58 {mg_ignore
, mg_ignore
, {ms_tmode
, 4}, {ms_tmode
, 4}, mg_ignore
, mg_ignore
}
60 struct Message mlock_msgtab
= {
62 {mg_ignore
, mg_ignore
, {ms_mlock
, 3}, {ms_mlock
, 3}, mg_ignore
, mg_ignore
}
64 struct Message bmask_msgtab
= {
66 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_bmask
, 5}, mg_ignore
, mg_ignore
}
69 mapi_clist_av1 mode_clist
[] = { &mode_msgtab
, &tmode_msgtab
, &mlock_msgtab
, &bmask_msgtab
, NULL
};
71 DECLARE_MODULE_AV2(mode
, NULL
, NULL
, mode_clist
, NULL
, NULL
, NULL
, NULL
, mode_desc
);
74 * m_mode - MODE command handler
78 m_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
80 struct Channel
*chptr
= NULL
;
81 struct membership
*msptr
;
88 if(IsOperSpy(source_p
) && *dest
== '!')
95 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
96 me
.name
, source_p
->name
, "MODE");
101 /* Now, try to find the channel in question */
102 if(!IsChanPrefix(*dest
))
104 /* if here, it has to be a non-channel name */
105 user_mode(client_p
, source_p
, parc
, parv
);
109 if(!check_channel_name(dest
))
111 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[1]);
115 chptr
= find_channel(dest
);
119 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
120 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
124 /* Now know the channel exists */
128 report_operspy(source_p
, "MODE", chptr
->chname
);
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
));
134 sendto_one(source_p
, form_str(RPL_CREATIONTIME
),
135 me
.name
, source_p
->name
, parv
[1], chptr
->channelts
);
139 msptr
= find_channel_membership(chptr
, source_p
);
141 /* Finish the flood grace period... */
142 if(MyClient(source_p
) && !IsFloodDone(source_p
))
144 if(!((parc
== 3) && (parv
[2][0] == 'b' || parv
[2][0] == 'q') && (parv
[2][1] == '\0')))
145 flood_endgrace(source_p
);
148 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- n
, parv
+ n
);
153 ms_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
155 struct Channel
*chptr
;
157 chptr
= find_channel(parv
[1]);
161 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
162 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
166 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 2, parv
+ 2);
170 ms_tmode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
172 struct Channel
*chptr
= NULL
;
173 struct membership
*msptr
;
175 /* Now, try to find the channel in question */
176 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
178 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
182 chptr
= find_channel(parv
[2]);
186 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
187 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
191 /* TS is higher, drop it. */
192 if(atol(parv
[1]) > chptr
->channelts
)
195 if(IsServer(source_p
))
197 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 3, parv
+ 3);
201 msptr
= find_channel_membership(chptr
, source_p
);
203 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- 3, parv
+ 3);
208 ms_mlock(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
210 struct Channel
*chptr
= NULL
;
212 /* Now, try to find the channel in question */
213 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
215 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
219 chptr
= find_channel(parv
[2]);
223 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
224 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
228 /* TS is higher, drop it. */
229 if(atol(parv
[1]) > chptr
->channelts
)
232 if(IsServer(source_p
))
233 set_channel_mlock(client_p
, source_p
, chptr
, parv
[3], true);
237 possibly_remove_lower_forward(struct Client
*fakesource_p
, int mems
,
238 struct Channel
*chptr
, rb_dlink_list
*banlist
, int mchar
,
239 const char *mask
, const char *forward
)
241 struct Ban
*actualBan
;
244 RB_DLINK_FOREACH(ptr
, banlist
->head
)
246 actualBan
= ptr
->data
;
247 if(!irccmp(actualBan
->banstr
, mask
) &&
248 (actualBan
->forward
== NULL
||
249 irccmp(actualBan
->forward
, forward
) < 0))
251 sendto_channel_local(mems
, chptr
, ":%s MODE %s -%c %s%s%s",
256 actualBan
->forward
? "$" : "",
257 actualBan
->forward
? actualBan
->forward
: "");
258 rb_dlinkDelete(&actualBan
->node
, banlist
);
266 ms_bmask(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
268 static char modebuf
[BUFSIZE
];
269 static char parabuf
[BUFSIZE
];
270 struct Channel
*chptr
;
271 rb_dlink_list
*banlist
;
282 int needcap
= NOCAPS
;
284 struct Client
*fakesource_p
;
286 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
289 if((chptr
= find_channel(parv
[2])) == NULL
)
292 /* TS is higher, drop it. */
293 if(atol(parv
[1]) > chptr
->channelts
)
299 banlist
= &chptr
->banlist
;
300 mode_type
= CHFL_BAN
;
305 banlist
= &chptr
->exceptlist
;
306 mode_type
= CHFL_EXCEPTION
;
312 banlist
= &chptr
->invexlist
;
313 mode_type
= CHFL_INVEX
;
319 banlist
= &chptr
->quietlist
;
320 mode_type
= CHFL_QUIET
;
324 /* maybe we should just blindly propagate this? */
330 s
= LOCAL_COPY(parv
[4]);
332 /* Hide connecting server on netburst -- jilles */
333 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
336 fakesource_p
= source_p
;
337 mlen
= sprintf(modebuf
, ":%s MODE %s +", fakesource_p
->name
, chptr
->chname
);
338 mbuf
= modebuf
+ mlen
;
344 /* next char isnt a space, point t to the next one */
345 if((t
= strchr(s
, ' ')) != NULL
)
349 /* double spaces will break the parser */
354 /* couldve skipped spaces and got nothing.. */
355 while(!EmptyString(s
))
357 /* ban with a leading ':' -- this will break the protocol */
363 /* I dont even want to begin parsing this.. */
364 if(tlen
> MODEBUFLEN
)
367 if((forward
= strchr(s
+1, '$')) != NULL
)
371 tlen
--, forward
= NULL
;
373 possibly_remove_lower_forward(fakesource_p
,
374 mems
, chptr
, banlist
,
375 parv
[3][0], s
, forward
);
378 if(add_id(fakesource_p
, chptr
, s
, forward
, banlist
, mode_type
))
380 /* this new one wont fit.. */
381 if(mlen
+ MAXMODEPARAMS
+ plen
+ tlen
> BUFSIZE
- 5 ||
382 modecount
>= MAXMODEPARAMS
)
386 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
388 mbuf
= modebuf
+ mlen
;
390 plen
= modecount
= 0;
396 *mbuf
++ = parv
[3][0];
397 arglen
= sprintf(pbuf
, "%s ", s
);
408 if((t
= strchr(s
, ' ')) != NULL
)
422 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
425 sendto_server(client_p
, chptr
, CAP_TS6
| needcap
, NOCAPS
, ":%s BMASK %ld %s %s :%s",
426 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
, parv
[3], parv
[4]);