2 * IRC - Internet Relay Chat, ircd/m_mode.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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 1, or (at your option)
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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
87 #include "ircd_reply.h"
88 #include "ircd_string.h"
101 #ifdef CONFIG_NEW_MODE
103 m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
105 struct Channel *chptr = 0;
107 struct Membership *member;
110 return need_more_params(sptr, "MODE");
112 clean_channelname(parv[1]);
114 if (('#' != *parv[1] && '&' != *parv[1]) || !(chptr = FindChannel(parv[1])))
115 return set_user_mode(cptr, sptr, parc, parv);
117 sptr->flags &= ~FLAGS_TS8;
120 char modebuf[MODEBUFLEN];
121 char parabuf[MODEBUFLEN];
123 *modebuf = *parabuf = '\0';
125 channel_modes(sptr, modebuf, parabuf, chptr);
126 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
127 chptr->chname, modebuf, parabuf);
128 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
129 chptr->chname, chptr->creationtime);
133 if (!(member = find_member_link(chptr, sptr)) || !IsChanOp(member)) {
134 #ifdef OPER_MODE_LCHAN
135 if (IsOperOnLocalChannel(sptr, chptr->chname)) {
136 modebuf_init(&mbuf, sptr, cptr, chptr,
137 (MODEBUF_DEST_CHANNEL | /* Send mode to channel */
138 MODEBUF_DEST_HACK4)); /* Send HACK(4) notice */
139 mode_parse(&mbuf, cptr, sptr, chptr, parc - 2, parv + 2,
140 (MODE_PARSE_SET | /* Set the mode */
141 MODE_PARSE_FORCE)); /* Force it to take */
142 return modebuf_flush(&mbuf);
145 mode_parse(0, cptr, sptr, chptr, parc - 2, parv + 2,
146 (member ? MODE_PARSE_NOTOPER : MODE_PARSE_NOTMEMBER));
150 modebuf_init(&mbuf, sptr, cptr, chptr,
151 (MODEBUF_DEST_CHANNEL | /* Send mode to channel */
152 MODEBUF_DEST_SERVER)); /* Send mode to servers */
153 mode_parse(&mbuf, cptr, sptr, chptr, parc - 2, parv + 2, MODE_PARSE_SET);
154 return modebuf_flush(&mbuf);
158 ms_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
160 struct Channel *chptr = 0;
162 struct Membership *member;
165 return need_more_params(sptr, "MODE");
167 if (IsLocalChannel(parv[1]))
170 if ('#' != *parv[1] || !(chptr = FindChannel(parv[1])))
171 return set_user_mode(cptr, sptr, parc, parv);
173 sptr->flags &= ~FLAGS_TS8;
175 if (IsServer(sptr)) {
176 if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
177 modebuf_init(&mbuf, sptr, cptr, chptr,
178 (MODEBUF_DEST_CHANNEL | /* Send mode to clients */
179 MODEBUF_DEST_SERVER | /* Send mode to servers */
180 MODEBUF_DEST_HACK4)); /* Send a HACK(4) message */
182 modebuf_init(&mbuf, sptr, cptr, chptr,
183 (MODEBUF_DEST_CHANNEL | /* Send mode to clients */
184 MODEBUF_DEST_SERVER | /* Send mode to servers */
185 MODEBUF_DEST_HACK3)); /* Send a HACK(3) message */
187 mode_parse(&mbuf, cptr, sptr, chptr, parc - 2, parv + 2,
188 (MODE_PARSE_SET | /* Set the mode */
189 MODE_PARSE_STRICT | /* Interpret it strictly */
190 MODE_PARSE_FORCE)); /* And force it to be accepted */
192 if (!(member = find_member_link(chptr, sptr)) || !IsChanOp(member)) {
193 modebuf_init(&mbuf, sptr, cptr, chptr,
194 (MODEBUF_DEST_SERVER | /* Send mode to server */
195 MODEBUF_DEST_HACK2 | /* Send a HACK(2) message */
196 MODEBUF_DEST_DEOP | /* Deop the source */
197 MODEBUF_DEST_BOUNCE)); /* And bounce the MODE */
198 mode_parse(&mbuf, cptr, sptr, chptr, parc - 2, parv + 2,
199 (MODE_PARSE_STRICT | /* Interpret it strictly */
200 MODE_PARSE_BOUNCE)); /* And bounce the MODE */
202 modebuf_init(&mbuf, sptr, cptr, chptr,
203 (MODEBUF_DEST_CHANNEL | /* Send mode to clients */
204 MODEBUF_DEST_SERVER)); /* Send mode to servers */
205 mode_parse(&mbuf, cptr, sptr, chptr, parc - 2, parv + 2,
206 (MODE_PARSE_SET | /* Set the mode */
207 MODE_PARSE_STRICT | /* Interpret it strictly */
208 MODE_PARSE_FORCE)); /* And force it to be accepted */
212 return modebuf_flush(&mbuf);
214 #else /* CONFIG_NEW_MODE */
216 * m_mode - generic message handler
218 int m_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
222 struct Channel* chptr = 0;
223 char modebuf[MODEBUFLEN];
224 char parabuf[MODEBUFLEN];
225 char nparabuf[MODEBUFLEN];
229 return need_more_params(sptr, "MODE");
232 * if local user, cleanup channel name, don't allow local channel operations
236 clean_channelname(parv[1]);
237 else if (IsLocalChannel(parv[1]))
241 * try to find the channel
243 if ('#' == *parv[1] || '&' == *parv[1])
244 chptr = FindChannel(parv[1]);
246 return set_user_mode(cptr, sptr, parc, parv);
248 sptr->flags &= ~FLAGS_TS8;
250 * sending an error wasnt good, lets just send an empty mode reply.. poptix
252 if (IsModelessChannel(chptr->chname)) {
254 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
255 chptr->chname, "+nt", "");
261 * no parameters, send channel modes
263 *modebuf = *parabuf = '\0';
265 channel_modes(sptr, modebuf, parabuf, chptr);
266 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
267 chptr->chname, modebuf, parabuf);
268 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
269 chptr->chname, chptr->creationtime);
273 LocalChanOperMode = 0;
275 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
276 modebuf, parabuf, nparabuf, &badop))) {
277 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
278 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
283 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
285 if (strlen(modebuf) > 1 || sendts > 0) {
286 if (badop != 2 && strlen(modebuf) > 1) {
287 #ifdef OPER_MODE_LCHAN
288 if (LocalChanOperMode) {
289 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
290 me.name, chptr->chname, modebuf, parabuf);
291 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
292 sptr->name, chptr->chname, modebuf, parabuf);
296 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
297 parv[0], chptr->chname, modebuf, parabuf);
299 if (IsLocalChannel(chptr->chname))
301 /* We send a creationtime of 0, to mark it as a hack --Run */
302 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
303 if (*modebuf == '\0')
304 strcpy(modebuf, "+");
306 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
307 NumServ(sptr), chptr->chname, modebuf, nparabuf,
308 (badop == 4) ? (time_t) 0 : chptr->creationtime);
313 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
314 NumServ(sptr), chptr->chname, modebuf, nparabuf);
316 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
317 NumNick(sptr), chptr->chname, modebuf, nparabuf);
324 * ms_mode - server message handler
326 int ms_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
330 struct Channel* chptr = 0;
331 char modebuf[MODEBUFLEN];
332 char parabuf[MODEBUFLEN];
333 char nparabuf[MODEBUFLEN];
336 return need_more_params(sptr, "MODE");
339 * if local user, cleanup channel name, don't allow local channel operations
343 clean_channelname(parv[1]);
344 else if (IsLocalChannel(parv[1]))
348 * try to find the channel
350 if ('#' == *parv[1] || '&' == *parv[1])
351 chptr = FindChannel(parv[1]);
353 return set_user_mode(cptr, sptr, parc, parv);
355 sptr->flags &= ~FLAGS_TS8;
357 * sending an error wasnt good, lets just send an empty mode reply.. poptix
359 if (IsModelessChannel(chptr->chname)) {
361 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
362 chptr->chname, "+nt", "");
368 * no parameters, send channel modes
370 *modebuf = *parabuf = '\0';
372 channel_modes(sptr, modebuf, parabuf, chptr);
373 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
374 chptr->chname, modebuf, parabuf);
375 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
376 chptr->chname, chptr->creationtime);
380 LocalChanOperMode = 0;
382 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
383 modebuf, parabuf, nparabuf, &badop))) {
384 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
385 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
390 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
392 if (strlen(modebuf) > 1 || sendts > 0) {
393 if (badop != 2 && strlen(modebuf) > 1) {
394 #ifdef OPER_MODE_LCHAN
395 if (LocalChanOperMode) {
396 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
397 me.name, chptr->chname, modebuf, parabuf);
398 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
399 me.name, chptr->chname, modebuf, parabuf);
403 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
404 parv[0], chptr->chname, modebuf, parabuf);
406 if (IsLocalChannel(chptr->chname))
408 /* We send a creationtime of 0, to mark it as a hack --Run */
409 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
410 if (*modebuf == '\0')
411 strcpy(modebuf, "+");
413 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
414 NumServ(sptr), chptr->chname, modebuf, nparabuf,
415 (badop == 4) ? (time_t) 0 : chptr->creationtime);
420 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
421 NumServ(sptr), chptr->chname, modebuf, nparabuf);
423 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
424 NumNick(sptr), chptr->chname, modebuf, nparabuf);
429 #endif /* CONFIG_NEW_MODE */
437 int m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
441 struct Channel* chptr = 0;
444 return need_more_params(sptr, "MODE");
447 * if local user, cleanup channel name, don't allow local channel operations
451 clean_channelname(parv[1]);
452 else if (IsLocalChannel(parv[1]))
456 * try to find the channel
458 if ('#' == *parv[1] || '&' == *parv[1])
459 chptr = FindChannel(parv[1]);
461 return set_user_mode(cptr, sptr, parc, parv);
463 sptr->flags &= ~FLAGS_TS8;
465 * sending an error wasnt good, lets just send an empty mode reply.. poptix
467 if (IsModelessChannel(chptr->chname)) {
469 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
470 chptr->chname, "+nt", "");
476 * no parameters, send channel modes
478 *modebuf = *parabuf = '\0';
480 channel_modes(sptr, modebuf, parabuf, chptr);
481 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
482 chptr->chname, modebuf, parabuf);
483 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
484 chptr->chname, chptr->creationtime);
488 LocalChanOperMode = 0;
490 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
491 modebuf, parabuf, nparabuf, &badop))) {
492 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
493 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
498 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
500 if (strlen(modebuf) > 1 || sendts > 0) {
501 if (badop != 2 && strlen(modebuf) > 1) {
502 #ifdef OPER_MODE_LCHAN
503 if (LocalChanOperMode) {
504 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
505 me.name, chptr->chname, modebuf, parabuf);
506 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
507 me.name, chptr->chname, modebuf, parabuf);
511 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
512 parv[0], chptr->chname, modebuf, parabuf);
514 if (IsLocalChannel(chptr->chname))
516 /* We send a creationtime of 0, to mark it as a hack --Run */
517 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
518 if (*modebuf == '\0')
519 strcpy(modebuf, "+");
521 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
522 NumServ(sptr), chptr->chname, modebuf, nparabuf,
523 (badop == 4) ? (time_t) 0 : chptr->creationtime);
528 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
529 NumServ(sptr), chptr->chname, modebuf, nparabuf);
531 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
532 NumNick(sptr), chptr->chname, modebuf, nparabuf);