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 * m_mode - generic message handler
103 int m_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
107 struct Channel* chptr = 0;
108 char modebuf[MODEBUFLEN];
109 char parabuf[MODEBUFLEN];
110 char nparabuf[MODEBUFLEN];
114 return need_more_params(sptr, "MODE");
117 * if local user, cleanup channel name, don't allow local channel operations
121 clean_channelname(parv[1]);
122 else if (IsLocalChannel(parv[1]))
126 * try to find the channel
128 if ('#' == *parv[1] || '&' == *parv[1])
129 chptr = FindChannel(parv[1]);
131 return set_user_mode(cptr, sptr, parc, parv);
133 sptr->flags &= ~FLAGS_TS8;
135 * sending an error wasnt good, lets just send an empty mode reply.. poptix
137 if (IsModelessChannel(chptr->chname)) {
139 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
140 chptr->chname, "+nt", "");
146 * no parameters, send channel modes
148 *modebuf = *parabuf = '\0';
150 channel_modes(sptr, modebuf, parabuf, chptr);
151 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
152 chptr->chname, modebuf, parabuf);
153 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
154 chptr->chname, chptr->creationtime);
158 LocalChanOperMode = 0;
160 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
161 modebuf, parabuf, nparabuf, &badop))) {
162 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
163 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
168 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
170 if (strlen(modebuf) > 1 || sendts > 0) {
171 if (badop != 2 && strlen(modebuf) > 1) {
172 #ifdef OPER_MODE_LCHAN
173 if (LocalChanOperMode) {
174 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
175 me.name, chptr->chname, modebuf, parabuf);
176 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
177 sptr->name, chptr->chname, modebuf, parabuf);
181 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
182 parv[0], chptr->chname, modebuf, parabuf);
184 if (IsLocalChannel(chptr->chname))
186 /* We send a creationtime of 0, to mark it as a hack --Run */
187 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
188 if (*modebuf == '\0')
189 strcpy(modebuf, "+");
191 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
192 NumServ(sptr), chptr->chname, modebuf, nparabuf,
193 (badop == 4) ? (time_t) 0 : chptr->creationtime);
198 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
199 NumServ(sptr), chptr->chname, modebuf, nparabuf);
201 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
202 NumNick(sptr), chptr->chname, modebuf, nparabuf);
209 * ms_mode - server message handler
211 int ms_mode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
215 struct Channel* chptr = 0;
216 char modebuf[MODEBUFLEN];
217 char parabuf[MODEBUFLEN];
218 char nparabuf[MODEBUFLEN];
221 return need_more_params(sptr, "MODE");
224 * if local user, cleanup channel name, don't allow local channel operations
228 clean_channelname(parv[1]);
229 else if (IsLocalChannel(parv[1]))
233 * try to find the channel
235 if ('#' == *parv[1] || '&' == *parv[1])
236 chptr = FindChannel(parv[1]);
238 return set_user_mode(cptr, sptr, parc, parv);
240 sptr->flags &= ~FLAGS_TS8;
242 * sending an error wasnt good, lets just send an empty mode reply.. poptix
244 if (IsModelessChannel(chptr->chname)) {
246 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
247 chptr->chname, "+nt", "");
253 * no parameters, send channel modes
255 *modebuf = *parabuf = '\0';
257 channel_modes(sptr, modebuf, parabuf, chptr);
258 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
259 chptr->chname, modebuf, parabuf);
260 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
261 chptr->chname, chptr->creationtime);
265 LocalChanOperMode = 0;
267 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
268 modebuf, parabuf, nparabuf, &badop))) {
269 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
270 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
275 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
277 if (strlen(modebuf) > 1 || sendts > 0) {
278 if (badop != 2 && strlen(modebuf) > 1) {
279 #ifdef OPER_MODE_LCHAN
280 if (LocalChanOperMode) {
281 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
282 me.name, chptr->chname, modebuf, parabuf);
283 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
284 me.name, chptr->chname, modebuf, parabuf);
288 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
289 parv[0], chptr->chname, modebuf, parabuf);
291 if (IsLocalChannel(chptr->chname))
293 /* We send a creationtime of 0, to mark it as a hack --Run */
294 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
295 if (*modebuf == '\0')
296 strcpy(modebuf, "+");
298 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
299 NumServ(sptr), chptr->chname, modebuf, nparabuf,
300 (badop == 4) ? (time_t) 0 : chptr->creationtime);
305 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
306 NumServ(sptr), chptr->chname, modebuf, nparabuf);
308 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
309 NumNick(sptr), chptr->chname, modebuf, nparabuf);
321 int m_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
325 struct Channel* chptr = 0;
328 return need_more_params(sptr, "MODE");
331 * if local user, cleanup channel name, don't allow local channel operations
335 clean_channelname(parv[1]);
336 else if (IsLocalChannel(parv[1]))
340 * try to find the channel
342 if ('#' == *parv[1] || '&' == *parv[1])
343 chptr = FindChannel(parv[1]);
345 return set_user_mode(cptr, sptr, parc, parv);
347 sptr->flags &= ~FLAGS_TS8;
349 * sending an error wasnt good, lets just send an empty mode reply.. poptix
351 if (IsModelessChannel(chptr->chname)) {
353 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
354 chptr->chname, "+nt", "");
360 * no parameters, send channel modes
362 *modebuf = *parabuf = '\0';
364 channel_modes(sptr, modebuf, parabuf, chptr);
365 sendto_one(sptr, rpl_str(RPL_CHANNELMODEIS), me.name, parv[0],
366 chptr->chname, modebuf, parabuf);
367 sendto_one(sptr, rpl_str(RPL_CREATIONTIME), me.name, parv[0],
368 chptr->chname, chptr->creationtime);
372 LocalChanOperMode = 0;
374 if (!(sendts = set_mode(cptr, sptr, chptr, parc - 2, parv + 2,
375 modebuf, parabuf, nparabuf, &badop))) {
376 sendto_one(sptr, err_str(find_channel_member(sptr, chptr) ? ERR_CHANOPRIVSNEEDED :
377 ERR_NOTONCHANNEL), me.name, parv[0], chptr->chname);
382 send_hack_notice(cptr, sptr, parc, parv, badop, 1);
384 if (strlen(modebuf) > 1 || sendts > 0) {
385 if (badop != 2 && strlen(modebuf) > 1) {
386 #ifdef OPER_MODE_LCHAN
387 if (LocalChanOperMode) {
388 sendto_channel_butserv(chptr, &me, ":%s MODE %s %s %s",
389 me.name, chptr->chname, modebuf, parabuf);
390 sendto_op_mask(SNO_HACK4,"OPER MODE: %s MODE %s %s %s",
391 me.name, chptr->chname, modebuf, parabuf);
395 sendto_channel_butserv(chptr, sptr, ":%s MODE %s %s %s",
396 parv[0], chptr->chname, modebuf, parabuf);
398 if (IsLocalChannel(chptr->chname))
400 /* We send a creationtime of 0, to mark it as a hack --Run */
401 if (IsServer(sptr) && (badop == 2 || sendts > 0)) {
402 if (*modebuf == '\0')
403 strcpy(modebuf, "+");
405 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s " TIME_T_FMT,
406 NumServ(sptr), chptr->chname, modebuf, nparabuf,
407 (badop == 4) ? (time_t) 0 : chptr->creationtime);
412 sendto_highprot_butone(cptr, 10, "%s " TOK_MODE " %s %s %s",
413 NumServ(sptr), chptr->chname, modebuf, nparabuf);
415 sendto_highprot_butone(cptr, 10, "%s%s " TOK_MODE " %s %s %s",
416 NumNick(sptr), chptr->chname, modebuf, nparabuf);