2 * IRC - Internet Relay Chat, ircd/m_clearmode.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
7 * See file AUTHORS in IRC package for additional names of
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 1, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * m_functions execute protocol messages on this server:
30 * cptr is always NON-NULL, pointing to a *LOCAL* client
31 * structure (with an open socket connected!). This
32 * identifies the physical socket where the message
33 * originated (or which caused the m_function to be
34 * executed--some m_functions may call others...).
36 * sptr is the source of the message, defined by the
37 * prefix part of the message if present. If not
38 * or prefix not found, then sptr==cptr.
40 * (!IsServer(cptr)) => (cptr == sptr), because
41 * prefixes are taken *only* from servers...
44 * (sptr == cptr) => the message didn't
47 * (sptr != cptr && IsServer(sptr) means
48 * the prefix specified servername. (?)
50 * (sptr != cptr && !IsServer(sptr) means
51 * that message originated from a remote
56 * (!IsServer(sptr)) means that, sptr can safely
57 * taken as defining the target structure of the
58 * message in this server.
60 * *Always* true (if 'parse' and others are working correct):
62 * 1) sptr->from == cptr (note: cptr->from == cptr)
64 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
65 * *cannot* be a local connection, unless it's
66 * actually cptr!). [MyConnect(x) should probably
67 * be defined as (x == x->from) --msa ]
69 * parc number of variable parameter strings (if zero,
70 * parv is allowed to be NULL)
72 * parv a NULL terminated list of parameter pointers,
74 * parv[0], sender (prefix string), if not present
75 * this points to an empty string.
76 * parv[1]...parv[parc-1]
77 * pointers to additional parameters
78 * parv[parc] == NULL, *always*
80 * note: it is guaranteed that parv[0]..parv[parc-1] are all
89 #include "ircd_alloc.h"
90 #include "ircd_features.h"
92 #include "ircd_reply.h"
93 #include "ircd_string.h"
105 * do_clearmode(struct Client *cptr, struct Client *sptr,
106 * struct Channel *chptr, char *control)
108 * This is the function that actually clears the channel modes.
111 do_clearmode(struct Client *cptr, struct Client *sptr, struct Channel *chptr,
114 static int flags[] = {
120 MODE_TOPICLIMIT, 't',
121 MODE_INVITEONLY, 'i',
122 MODE_NOPRIVMSGS, 'n',
131 unsigned int del_mode = 0;
132 char control_buf[20];
133 int control_buf_i = 0;
135 struct SLink *link, *next;
136 struct Membership *member;
138 /* Ok, so what are we supposed to get rid of? */
139 for (; *control; control++) {
140 for (flag_p = flags; flag_p[0]; flag_p += 2)
141 if (*control == flag_p[1]) {
142 del_mode |= flag_p[0];
148 return 0; /* nothing to remove; ho hum. */
150 modebuf_init(&mbuf, sptr, cptr, chptr,
151 (MODEBUF_DEST_CHANNEL | /* Send MODE to channel */
152 MODEBUF_DEST_OPMODE | /* Treat it like an OPMODE */
153 MODEBUF_DEST_HACK4)); /* Generate a HACK(4) notice */
155 modebuf_mode(&mbuf, MODE_DEL | (del_mode & chptr->mode.mode));
156 chptr->mode.mode &= ~del_mode; /* and of course actually delete them */
158 /* If we're removing invite, remove all the invites */
159 if (del_mode & MODE_INVITEONLY)
160 mode_invite_clear(chptr);
163 * If we're removing the key, note that; note that we can't clear
164 * the key until after modebuf_* are done with it
166 if (del_mode & MODE_KEY && *chptr->mode.key)
167 modebuf_mode_string(&mbuf, MODE_DEL | MODE_KEY, chptr->mode.key, 0);
169 /* If we're removing the limit, note that and clear the limit */
170 if (del_mode & MODE_LIMIT && chptr->mode.limit) {
171 modebuf_mode_uint(&mbuf, MODE_DEL | MODE_LIMIT, chptr->mode.limit);
172 chptr->mode.limit = 0; /* not referenced, so safe */
176 * Go through and mark the bans for deletion; note that we can't
177 * free them until after modebuf_* are done with them
179 if (del_mode & MODE_BAN) {
180 for (link = chptr->banlist; link; link = next) {
183 modebuf_mode_string(&mbuf, MODE_DEL | MODE_BAN, /* delete ban */
184 link->value.ban.banstr, 1);
186 MyFree(link->value.ban.who); /* free up who string */
187 free_link(link); /* and of course the link itself */
193 /* Deal with users on the channel */
194 if (del_mode & (MODE_BAN | MODE_CHANOP | MODE_VOICE))
195 for (member = chptr->members; member; member = member->next_member) {
196 if (IsZombie(member)) /* we ignore zombies */
199 if (del_mode & MODE_BAN) /* If we cleared bans, clear the valid flags */
200 ClearBanValid(member);
202 /* Drop channel operator status */
203 if (IsChanOp(member) && del_mode & MODE_CHANOP) {
204 modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, member->user);
205 member->status &= ~CHFL_CHANOP;
209 if (HasVoice(member) && del_mode & MODE_VOICE) {
210 modebuf_mode_client(&mbuf, MODE_DEL | MODE_VOICE, member->user);
211 member->status &= ~CHFL_VOICE;
215 /* And flush the modes to the channel */
216 modebuf_flush(&mbuf);
218 /* Finally, we can clear the key... */
219 if (del_mode & MODE_KEY)
220 chptr->mode.key[0] = '\0';
222 /* Ok, build control string again */
223 for (flag_p = flags; flag_p[0]; flag_p += 2)
224 if (del_mode & flag_p[0])
225 control_buf[control_buf_i++] = flag_p[1];
227 control_buf[control_buf_i] = '\0';
230 log_write(LS_OPERMODE, L_INFO, LOG_NOSNOTICE, "%#C CLEARMODE %H %s", sptr,
234 if (!IsLocalChannel(chptr->chname))
235 sendcmdto_serv_butone(sptr, CMD_CLEARMODE, cptr, "%H %s", chptr,
242 * ms_clearmode - server message handler
244 * parv[0] = Send prefix
245 * parv[1] = Channel name
246 * parv[2] = Control string
249 ms_clearmode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
251 struct Channel *chptr;
254 return need_more_params(sptr, "CLEARMODE");
256 if (!IsPrivileged(sptr)) {
257 protocol_violation(sptr,"No priviledges on source for CLEARMODE, desync?");
258 return send_reply(sptr, ERR_NOPRIVILEGES);
261 if (!IsChannelName(parv[1]) || IsLocalChannel(parv[1]) ||
262 !(chptr = FindChannel(parv[1])))
263 return send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
265 return do_clearmode(cptr, sptr, chptr, parv[2]);
269 * mo_clearmode - oper message handler
271 * parv[0] = Send prefix
272 * parv[1] = Channel name
273 * parv[2] = Control string
276 mo_clearmode(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
278 struct Channel *chptr;
279 char *control = "ovpsmikbl"; /* default control string */
280 const char *chname, *qreason;
283 if (!feature_bool(FEAT_CONFIG_OPERCMDS))
284 return send_reply(sptr, ERR_DISABLED, "CLEARMODE");
287 return need_more_params(sptr, "CLEARMODE");
296 if (!HasPriv(sptr, IsLocalChannel(chname) ?
297 PRIV_FORCE_LOCAL_OPMODE :
299 return send_reply(sptr, ERR_NOPRIVILEGES);
304 IsLocalChannel(chname) ? PRIV_LOCAL_OPMODE : PRIV_OPMODE))
305 return send_reply(sptr, ERR_NOPRIVILEGES);
307 if (('#' != *chname && '&' != *chname) || !(chptr = FindChannel(chname)))
308 return send_reply(sptr, ERR_NOSUCHCHANNEL, chname);
310 if (!force && (qreason = find_quarantine(chptr->chname)))
311 return send_reply(sptr, ERR_QUARANTINED, chptr->chname, qreason);
313 return do_clearmode(cptr, sptr, chptr, control);