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
};
68 DECLARE_MODULE_AV2(mode
, NULL
, NULL
, mode_clist
, NULL
, NULL
, NULL
, NULL
, NULL
);
71 * m_mode - MODE command handler
75 m_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
77 struct Channel
*chptr
= NULL
;
78 struct membership
*msptr
;
85 if(IsOperSpy(source_p
) && *dest
== '!')
92 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
93 me
.name
, source_p
->name
, "MODE");
98 /* Now, try to find the channel in question */
99 if(!IsChanPrefix(*dest
))
101 /* if here, it has to be a non-channel name */
102 user_mode(client_p
, source_p
, parc
, parv
);
106 if(!check_channel_name(dest
))
108 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[1]);
112 chptr
= find_channel(dest
);
116 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
117 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
121 /* Now know the channel exists */
125 report_operspy(source_p
, "MODE", chptr
->chname
);
127 sendto_one(source_p
, form_str(RPL_CHANNELMODEIS
),
128 me
.name
, source_p
->name
, parv
[1],
129 operspy
? channel_modes(chptr
, &me
) : channel_modes(chptr
, source_p
));
131 sendto_one(source_p
, form_str(RPL_CREATIONTIME
),
132 me
.name
, source_p
->name
, parv
[1], chptr
->channelts
);
136 msptr
= find_channel_membership(chptr
, source_p
);
138 /* Finish the flood grace period... */
139 if(MyClient(source_p
) && !IsFloodDone(source_p
))
141 if(!((parc
== 3) && (parv
[2][0] == 'b' || parv
[2][0] == 'q') && (parv
[2][1] == '\0')))
142 flood_endgrace(source_p
);
145 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- n
, parv
+ n
);
152 ms_mode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
154 struct Channel
*chptr
;
156 chptr
= find_channel(parv
[1]);
160 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
161 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
165 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 2, parv
+ 2);
171 ms_tmode(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
173 struct Channel
*chptr
= NULL
;
174 struct membership
*msptr
;
176 /* Now, try to find the channel in question */
177 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
179 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
183 chptr
= find_channel(parv
[2]);
187 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
188 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
192 /* TS is higher, drop it. */
193 if(atol(parv
[1]) > chptr
->channelts
)
196 if(IsServer(source_p
))
198 set_channel_mode(client_p
, source_p
, chptr
, NULL
, parc
- 3, parv
+ 3);
202 msptr
= find_channel_membership(chptr
, source_p
);
204 set_channel_mode(client_p
, source_p
, chptr
, msptr
, parc
- 3, parv
+ 3);
211 ms_mlock(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
213 struct Channel
*chptr
= NULL
;
215 /* Now, try to find the channel in question */
216 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
218 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), parv
[2]);
222 chptr
= find_channel(parv
[2]);
226 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
227 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
231 /* TS is higher, drop it. */
232 if(atol(parv
[1]) > chptr
->channelts
)
235 if(IsServer(source_p
))
236 set_channel_mlock(client_p
, source_p
, chptr
, parv
[3], TRUE
);
242 possibly_remove_lower_forward(struct Client
*fakesource_p
, int mems
,
243 struct Channel
*chptr
, rb_dlink_list
*banlist
, int mchar
,
244 const char *mask
, const char *forward
)
246 struct Ban
*actualBan
;
249 RB_DLINK_FOREACH(ptr
, banlist
->head
)
251 actualBan
= ptr
->data
;
252 if(!irccmp(actualBan
->banstr
, mask
) &&
253 (actualBan
->forward
== NULL
||
254 irccmp(actualBan
->forward
, forward
) < 0))
256 sendto_channel_local(mems
, chptr
, ":%s MODE %s -%c %s%s%s",
261 actualBan
->forward
? "$" : "",
262 actualBan
->forward
? actualBan
->forward
: "");
263 rb_dlinkDelete(&actualBan
->node
, banlist
);
271 ms_bmask(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
273 static char modebuf
[BUFSIZE
];
274 static char parabuf
[BUFSIZE
];
275 struct Channel
*chptr
;
276 rb_dlink_list
*banlist
;
287 int needcap
= NOCAPS
;
289 struct Client
*fakesource_p
;
291 if(!IsChanPrefix(parv
[2][0]) || !check_channel_name(parv
[2]))
294 if((chptr
= find_channel(parv
[2])) == NULL
)
297 /* TS is higher, drop it. */
298 if(atol(parv
[1]) > chptr
->channelts
)
304 banlist
= &chptr
->banlist
;
305 mode_type
= CHFL_BAN
;
310 banlist
= &chptr
->exceptlist
;
311 mode_type
= CHFL_EXCEPTION
;
317 banlist
= &chptr
->invexlist
;
318 mode_type
= CHFL_INVEX
;
324 banlist
= &chptr
->quietlist
;
325 mode_type
= CHFL_QUIET
;
329 /* maybe we should just blindly propagate this? */
335 s
= LOCAL_COPY(parv
[4]);
337 /* Hide connecting server on netburst -- jilles */
338 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
341 fakesource_p
= source_p
;
342 mlen
= sprintf(modebuf
, ":%s MODE %s +", fakesource_p
->name
, chptr
->chname
);
343 mbuf
= modebuf
+ mlen
;
349 /* next char isnt a space, point t to the next one */
350 if((t
= strchr(s
, ' ')) != NULL
)
354 /* double spaces will break the parser */
359 /* couldve skipped spaces and got nothing.. */
360 while(!EmptyString(s
))
362 /* ban with a leading ':' -- this will break the protocol */
368 /* I dont even want to begin parsing this.. */
369 if(tlen
> MODEBUFLEN
)
372 if((forward
= strchr(s
+1, '$')) != NULL
)
376 tlen
--, forward
= NULL
;
378 possibly_remove_lower_forward(fakesource_p
,
379 mems
, chptr
, banlist
,
380 parv
[3][0], s
, forward
);
383 if(add_id(fakesource_p
, chptr
, s
, forward
, banlist
, mode_type
))
385 /* this new one wont fit.. */
386 if(mlen
+ MAXMODEPARAMS
+ plen
+ tlen
> BUFSIZE
- 5 ||
387 modecount
>= MAXMODEPARAMS
)
391 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
393 mbuf
= modebuf
+ mlen
;
395 plen
= modecount
= 0;
401 *mbuf
++ = parv
[3][0];
402 arglen
= sprintf(pbuf
, "%s ", s
);
413 if((t
= strchr(s
, ' ')) != NULL
)
427 sendto_channel_local(mems
, chptr
, "%s %s", modebuf
, parabuf
);
430 sendto_server(client_p
, chptr
, CAP_TS6
| needcap
, NOCAPS
, ":%s BMASK %ld %s %s :%s",
431 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
, parv
[3], parv
[4]);