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 int m_mode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
44 static int ms_mode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
45 static int ms_tmode(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 static int ms_mlock(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
47 static int ms_bmask(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
49 struct Message mode_msgtab
= {
51 {mg_unreg
, {m_mode
, 2}, {m_mode
, 3}, {ms_mode
, 3}, mg_ignore
, {m_mode
, 2}}
53 struct Message tmode_msgtab
= {
55 {mg_ignore
, mg_ignore
, {ms_tmode
, 4}, {ms_tmode
, 4}, mg_ignore
, mg_ignore
}
57 struct Message mlock_msgtab
= {
59 {mg_ignore
, mg_ignore
, {ms_mlock
, 3}, {ms_mlock
, 3}, mg_ignore
, mg_ignore
}
61 struct Message bmask_msgtab
= {
63 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_bmask
, 5}, mg_ignore
, mg_ignore
}
66 mapi_clist_av1 mode_clist
[] = { &mode_msgtab
, &tmode_msgtab
, &mlock_msgtab
, &bmask_msgtab
, NULL
};
67 static const char mode_desc
[] =
68 "Provides the MODE and MLOCK client and server commands, and TS6 server-to-server TMODE and BMASK commands";
70 DECLARE_MODULE_AV2(mode
, NULL
, NULL
, mode_clist
, NULL
, NULL
, NULL
, NULL
, mode_desc
);
73 * m_mode - MODE command handler
77 m_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
79 struct Channel
*chptr
= NULL
;
80 struct membership
*msptr
;
87 if(IsOperSpy(source_p
) && *dest
== '!')
94 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
95 me
.name
, source_p
->name
, "MODE");
100 /* Now, try to find the channel in question */
101 if(!IsChanPrefix(*dest
))
103 /* if here, it has to be a non-channel name */
104 user_mode(client_p
, source_p
, parc
, parv
);
108 if(!check_channel_name(dest
))
110 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[1]);
114 chptr
= find_channel(dest
);
118 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
119 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
123 /* Now know the channel exists */
127 report_operspy(source_p
, "MODE", chptr
->chname
);
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
));
133 sendto_one(source_p
, form_str(RPL_CREATIONTIME
),
134 me
.name
, source_p
->name
, parv
[1], chptr
->channelts
);
138 msptr
= find_channel_membership(chptr
, source_p
);
140 /* Finish the flood grace period... */
141 if(MyClient(source_p
) && !IsFloodDone(source_p
))
143 if(!((parc
== 3) && (parv
[2][0] == 'b' || parv
[2][0] == 'q') && (parv
[2][1] == '\0')))
144 flood_endgrace(source_p
);
147 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- n
, parv
+ n
);
154 ms_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
156 struct Channel
*chptr
;
158 chptr
= find_channel(parv
[1]);
162 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
163 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
167 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 2, parv
+ 2);
173 ms_tmode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
175 struct Channel
*chptr
= NULL
;
176 struct membership
*msptr
;
178 /* Now, try to find the channel in question */
179 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
181 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
185 chptr
= find_channel(parv
[2]);
189 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
190 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
194 /* TS is higher, drop it. */
195 if(atol(parv
[1]) > chptr
->channelts
)
198 if(IsServer(source_p
))
200 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 3, parv
+ 3);
204 msptr
= find_channel_membership(chptr
, source_p
);
206 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- 3, parv
+ 3);
213 ms_mlock(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
215 struct Channel
*chptr
= NULL
;
217 /* Now, try to find the channel in question */
218 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
220 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
224 chptr
= find_channel(parv
[2]);
228 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
229 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
233 /* TS is higher, drop it. */
234 if(atol(parv
[1]) > chptr
->channelts
)
237 if(IsServer(source_p
))
238 set_channel_mlock(client_p
, source_p
, chptr
, parv
[3], TRUE
);
244 possibly_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
)
248 struct Ban
*actualBan
;
251 RB_DLINK_FOREACH(ptr
, banlist
->head
)
253 actualBan
= ptr
->data
;
254 if(!irccmp(actualBan
->banstr
, mask
) &&
255 (actualBan
->forward
== NULL
||
256 irccmp(actualBan
->forward
, forward
) < 0))
258 sendto_channel_local(mems
, chptr
, ":%s MODE %s -%c %s%s%s",
263 actualBan
->forward
? "$" : "",
264 actualBan
->forward
? actualBan
->forward
: "");
265 rb_dlinkDelete(&actualBan
->node
, banlist
);
273 ms_bmask(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
275 static char modebuf
[BUFSIZE
];
276 static char parabuf
[BUFSIZE
];
277 struct Channel
*chptr
;
278 rb_dlink_list
*banlist
;
289 int needcap
= NOCAPS
;
291 struct Client
*fakesource_p
;
293 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
296 if((chptr
= find_channel(parv
[2])) == NULL
)
299 /* TS is higher, drop it. */
300 if(atol(parv
[1]) > chptr
->channelts
)
306 banlist
= &chptr
->banlist
;
307 mode_type
= CHFL_BAN
;
312 banlist
= &chptr
->exceptlist
;
313 mode_type
= CHFL_EXCEPTION
;
319 banlist
= &chptr
->invexlist
;
320 mode_type
= CHFL_INVEX
;
326 banlist
= &chptr
->quietlist
;
327 mode_type
= CHFL_QUIET
;
331 /* maybe we should just blindly propagate this? */
337 s
= LOCAL_COPY(parv
[4]);
339 /* Hide connecting server on netburst -- jilles */
340 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
343 fakesource_p
= source_p
;
344 mlen
= sprintf(modebuf
, ":%s MODE %s +", fakesource_p
->name
, chptr
->chname
);
345 mbuf
= modebuf
+ mlen
;
351 /* next char isnt a space, point t to the next one */
352 if((t
= strchr(s
, ' ')) != NULL
)
356 /* double spaces will break the parser */
361 /* couldve skipped spaces and got nothing.. */
362 while(!EmptyString(s
))
364 /* ban with a leading ':' -- this will break the protocol */
370 /* I dont even want to begin parsing this.. */
371 if(tlen
> MODEBUFLEN
)
374 if((forward
= strchr(s
+1, '$')) != NULL
)
378 tlen
--, forward
= NULL
;
380 possibly_remove_lower_forward(fakesource_p
,
381 mems
, chptr
, banlist
,
382 parv
[3][0], s
, forward
);
385 if(add_id(fakesource_p
, chptr
, s
, forward
, banlist
, mode_type
))
387 /* this new one wont fit.. */
388 if(mlen
+ MAXMODEPARAMS
+ plen
+ tlen
> BUFSIZE
- 5 ||
389 modecount
>= MAXMODEPARAMS
)
393 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
395 mbuf
= modebuf
+ mlen
;
397 plen
= modecount
= 0;
403 *mbuf
++ = parv
[3][0];
404 arglen
= sprintf(pbuf
, "%s ", s
);
415 if((t
= strchr(s
, ' ')) != NULL
)
429 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
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]);