| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_clearchan.c: Performs a channel takeover |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "list.h" |
| 27 |
#include "handlers.h" |
| 28 |
#include "channel.h" |
| 29 |
#include "channel_mode.h" |
| 30 |
#include "client.h" |
| 31 |
#include "ircd.h" |
| 32 |
#include "numeric.h" |
| 33 |
#include "s_log.h" |
| 34 |
#include "s_serv.h" |
| 35 |
#include "send.h" |
| 36 |
#include "irc_string.h" |
| 37 |
#include "sprintf_irc.h" |
| 38 |
#include "hash.h" |
| 39 |
#include "msg.h" |
| 40 |
#include "parse.h" |
| 41 |
#include "modules.h" |
| 42 |
#include "s_conf.h" |
| 43 |
#include "common.h" |
| 44 |
|
| 45 |
static void mo_clearchan(struct Client *, struct Client *, int, char *[]); |
| 46 |
static void kick_list(struct Client *, struct Channel *); |
| 47 |
static void remove_our_modes(struct Channel *); |
| 48 |
static void remove_a_mode(struct Channel *, int, char); |
| 49 |
|
| 50 |
struct Message clearchan_msgtab = { |
| 51 |
"CLEARCHAN", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 52 |
{ m_unregistered, m_not_oper, m_ignore, m_ignore, mo_clearchan, m_ignore } |
| 53 |
}; |
| 54 |
|
| 55 |
void |
| 56 |
_modinit(void) |
| 57 |
{ |
| 58 |
mod_add_cmd(&clearchan_msgtab); |
| 59 |
} |
| 60 |
|
| 61 |
void |
| 62 |
_moddeinit(void) |
| 63 |
{ |
| 64 |
mod_del_cmd(&clearchan_msgtab); |
| 65 |
} |
| 66 |
|
| 67 |
const char *_version = "$Revision$"; |
| 68 |
|
| 69 |
/* |
| 70 |
** mo_clearchan |
| 71 |
** parv[0] = sender prefix |
| 72 |
** parv[1] = channel |
| 73 |
*/ |
| 74 |
static void |
| 75 |
mo_clearchan(struct Client *client_p, struct Client *source_p, |
| 76 |
int parc, char *parv[]) |
| 77 |
{ |
| 78 |
struct Channel *chptr = NULL; |
| 79 |
|
| 80 |
/* admins only */ |
| 81 |
if (!IsAdmin(source_p)) |
| 82 |
{ |
| 83 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
| 84 |
me.name, source_p->name); |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 89 |
{ |
| 90 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
| 91 |
me.name, source_p->name, parv[1]); |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
if (IsMember(source_p, chptr)) |
| 96 |
{ |
| 97 |
sendto_one(source_p, ":%s NOTICE %s :*** Please part %s before using CLEARCHAN", |
| 98 |
me.name, source_p->name, chptr->chname); |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
sendto_wallops_flags(UMODE_WALLOP, &me, "CLEARCHAN called for [%s] by %s!%s@%s", |
| 103 |
chptr->chname, source_p->name, source_p->username, source_p->host); |
| 104 |
sendto_server(NULL, NULL, NOCAPS, NOCAPS, |
| 105 |
":%s WALLOPS :CLEARCHAN called for [%s] by %s!%s@%s", |
| 106 |
me.name, chptr->chname, source_p->name, source_p->username, |
| 107 |
source_p->host); |
| 108 |
ilog(L_NOTICE, "CLEARCHAN called for [%s] by %s!%s@%s", |
| 109 |
chptr->chname, source_p->name, source_p->username, source_p->host); |
| 110 |
|
| 111 |
/* |
| 112 |
* Kill all the modes we have about the channel.. |
| 113 |
* making everyone a peon |
| 114 |
*/ |
| 115 |
remove_our_modes(chptr); |
| 116 |
|
| 117 |
/* SJOIN the user to give them ops, and lock the channel */ |
| 118 |
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
| 119 |
":%s JOIN %lu %s +ntsi", |
| 120 |
source_p->id, (unsigned long)(chptr->channelts - 1), |
| 121 |
chptr->chname); |
| 122 |
sendto_server(client_p, chptr, NOCAPS, CAP_TS6, |
| 123 |
":%s SJOIN %lu %s +ntsi :@%s", |
| 124 |
me.name, (unsigned long)(chptr->channelts - 1), |
| 125 |
chptr->chname, source_p->name); |
| 126 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN %s", |
| 127 |
source_p->name, source_p->username, |
| 128 |
source_p->host, chptr->chname); |
| 129 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +o %s", |
| 130 |
me.name, chptr->chname, source_p->name); |
| 131 |
|
| 132 |
|
| 133 |
/* |
| 134 |
* Take the TS down by 1, so we don't see the channel taken over |
| 135 |
* again. |
| 136 |
*/ |
| 137 |
if (chptr->channelts) |
| 138 |
--chptr->channelts; |
| 139 |
|
| 140 |
chptr->mode.mode = MODE_SECRET | MODE_TOPICLIMIT | |
| 141 |
MODE_INVITEONLY | MODE_NOPRIVMSGS; |
| 142 |
free_topic(chptr); |
| 143 |
chptr->mode.key[0] = '\0'; |
| 144 |
|
| 145 |
/* Kick the users out and join the oper */ |
| 146 |
kick_list(source_p, chptr); |
| 147 |
} |
| 148 |
|
| 149 |
static void |
| 150 |
kick_list(struct Client *source_p, struct Channel *chptr) |
| 151 |
{ |
| 152 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 153 |
struct Membership *ms = NULL; |
| 154 |
|
| 155 |
DLINK_FOREACH(ptr, chptr->members.head) |
| 156 |
{ |
| 157 |
ms = ptr->data; |
| 158 |
|
| 159 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, |
| 160 |
":%s!%s@%s KICK %s %s CLEARCHAN", |
| 161 |
source_p->name, source_p->username, |
| 162 |
source_p->host, chptr->chname, ms->client_p->name); |
| 163 |
sendto_server(NULL, chptr, NOCAPS, NOCAPS, |
| 164 |
":%s KICK %s %s :CLEARCHAN", source_p->name, |
| 165 |
chptr->chname, ms->client_p->name); |
| 166 |
} |
| 167 |
|
| 168 |
add_user_to_channel(chptr, source_p, CHFL_CHANOP, 0); |
| 169 |
|
| 170 |
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 171 |
{ |
| 172 |
ms = ptr->data; |
| 173 |
|
| 174 |
if (ms->client_p != source_p) |
| 175 |
remove_user_from_channel(ms); |
| 176 |
} |
| 177 |
|
| 178 |
/* |
| 179 |
* Join the user themselves to the channel down here, so they dont see a nicklist |
| 180 |
* or people being kicked |
| 181 |
*/ |
| 182 |
sendto_one(source_p, ":%s!%s@%s JOIN %s", |
| 183 |
source_p->name, source_p->username, |
| 184 |
source_p->host, chptr->chname); |
| 185 |
channel_member_names(source_p, chptr, 1); |
| 186 |
} |
| 187 |
|
| 188 |
/* remove_our_modes() |
| 189 |
* |
| 190 |
* inputs - hide from ops or not int flag |
| 191 |
* - pointer to channel to remove modes from |
| 192 |
* - client pointer |
| 193 |
* output - NONE |
| 194 |
* side effects - Go through the local members, remove all their |
| 195 |
* chanop modes etc., this side lost the TS. |
| 196 |
*/ |
| 197 |
static void |
| 198 |
remove_our_modes(struct Channel *chptr) |
| 199 |
{ |
| 200 |
remove_a_mode(chptr, CHFL_CHANOP, 'o'); |
| 201 |
#ifdef HALFOPS |
| 202 |
remove_a_mode(chptr, CHFL_HALFOP, 'h'); |
| 203 |
#endif |
| 204 |
remove_a_mode(chptr, CHFL_VOICE, 'v'); |
| 205 |
|
| 206 |
/* Clear all +beI modes */ |
| 207 |
free_channel_list(&chptr->banlist); |
| 208 |
free_channel_list(&chptr->exceptlist); |
| 209 |
free_channel_list(&chptr->invexlist); |
| 210 |
} |
| 211 |
|
| 212 |
/* remove_a_mode() |
| 213 |
* |
| 214 |
* inputs - |
| 215 |
* output - NONE |
| 216 |
* side effects - remove ONE mode from a channel |
| 217 |
*/ |
| 218 |
static void |
| 219 |
remove_a_mode(struct Channel *chptr, int mask, char flag) |
| 220 |
{ |
| 221 |
const dlink_node *ptr = NULL; |
| 222 |
char lmodebuf[MODEBUFLEN]; |
| 223 |
const char *lpara[4] = { "", "", "", "" }; |
| 224 |
char *mbuf = lmodebuf; |
| 225 |
int count = 0; |
| 226 |
|
| 227 |
*mbuf++ = '-'; |
| 228 |
|
| 229 |
DLINK_FOREACH(ptr, chptr->members.head) |
| 230 |
{ |
| 231 |
struct Membership *ms = ptr->data; |
| 232 |
if ((ms->flags & mask) == 0) |
| 233 |
continue; |
| 234 |
|
| 235 |
ms->flags &= ~mask; |
| 236 |
|
| 237 |
lpara[count++] = ms->client_p->name; |
| 238 |
|
| 239 |
*mbuf++ = flag; |
| 240 |
|
| 241 |
if (count == 4) |
| 242 |
{ |
| 243 |
*mbuf = '\0'; |
| 244 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s", |
| 245 |
me.name, chptr->chname, lmodebuf, lpara[0], |
| 246 |
lpara[1], lpara[2], lpara[3]); |
| 247 |
|
| 248 |
mbuf = lmodebuf; |
| 249 |
*mbuf++ = '-'; |
| 250 |
count = 0; |
| 251 |
lpara[0] = lpara[1] = lpara[2] = lpara[3] = ""; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
if (count != 0) |
| 256 |
{ |
| 257 |
*mbuf = '\0'; |
| 258 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s", |
| 259 |
me.name, chptr->chname, lmodebuf, lpara[0], |
| 260 |
lpara[1], lpara[2], lpara[3]); |
| 261 |
} |
| 262 |
} |