ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/contrib/m_clearchan.c
Revision: 1029
Committed: Sun Nov 8 13:10:50 2009 UTC (14 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 7491 byte(s)
Log Message:
- branch off trunk to create 7.3 branch

File Contents

# Content
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 #ifndef STATIC_MODULES
56 void
57 _modinit(void)
58 {
59 mod_add_cmd(&clearchan_msgtab);
60 }
61
62 void
63 _moddeinit(void)
64 {
65 mod_del_cmd(&clearchan_msgtab);
66 }
67
68 const char *_version = "$Revision$";
69 #endif
70
71 /*
72 ** mo_clearchan
73 ** parv[0] = sender prefix
74 ** parv[1] = channel
75 */
76 static void
77 mo_clearchan(struct Client *client_p, struct Client *source_p,
78 int parc, char *parv[])
79 {
80 struct Channel *chptr = NULL;
81
82 /* admins only */
83 if (!IsAdmin(source_p))
84 {
85 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
86 me.name, source_p->name);
87 return;
88 }
89
90 if ((chptr = hash_find_channel(parv[1])) == NULL)
91 {
92 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
93 me.name, source_p->name, parv[1]);
94 return;
95 }
96
97 if (IsMember(source_p, chptr))
98 {
99 sendto_one(source_p, ":%s NOTICE %s :*** Please part %s before using CLEARCHAN",
100 me.name, source_p->name, chptr->chname);
101 return;
102 }
103
104 sendto_wallops_flags(UMODE_WALLOP, &me, "CLEARCHAN called for [%s] by %s!%s@%s",
105 chptr->chname, source_p->name, source_p->username, source_p->host);
106 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
107 ":%s WALLOPS :CLEARCHAN called for [%s] by %s!%s@%s",
108 me.name, chptr->chname, source_p->name, source_p->username,
109 source_p->host);
110 ilog(L_NOTICE, "CLEARCHAN called for [%s] by %s!%s@%s",
111 chptr->chname, source_p->name, source_p->username, source_p->host);
112
113 /*
114 * Kill all the modes we have about the channel..
115 * making everyone a peon
116 */
117 remove_our_modes(chptr);
118
119 /* SJOIN the user to give them ops, and lock the channel */
120 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
121 ":%s JOIN %lu %s +ntsi",
122 source_p->id, (unsigned long)(chptr->channelts - 1),
123 chptr->chname);
124 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
125 ":%s SJOIN %lu %s +ntsi :@%s",
126 me.name, (unsigned long)(chptr->channelts - 1),
127 chptr->chname, source_p->name);
128 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN %s",
129 source_p->name, source_p->username,
130 source_p->host, chptr->chname);
131 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +o %s",
132 me.name, chptr->chname, source_p->name);
133
134
135 /*
136 * Take the TS down by 1, so we don't see the channel taken over
137 * again.
138 */
139 if (chptr->channelts)
140 --chptr->channelts;
141
142 chptr->mode.mode = MODE_SECRET | MODE_TOPICLIMIT |
143 MODE_INVITEONLY | MODE_NOPRIVMSGS;
144 free_topic(chptr);
145 chptr->mode.key[0] = '\0';
146
147 /* Kick the users out and join the oper */
148 kick_list(source_p, chptr);
149 }
150
151 static void
152 kick_list(struct Client *source_p, struct Channel *chptr)
153 {
154 dlink_node *ptr = NULL, *ptr_next = NULL;
155 struct Membership *ms = NULL;
156
157 DLINK_FOREACH(ptr, chptr->members.head)
158 {
159 ms = ptr->data;
160
161 sendto_channel_local(ALL_MEMBERS, 0, chptr,
162 ":%s!%s@%s KICK %s %s CLEARCHAN",
163 source_p->name, source_p->username,
164 source_p->host, chptr->chname, ms->client_p->name);
165 sendto_server(NULL, chptr, NOCAPS, NOCAPS,
166 ":%s KICK %s %s :CLEARCHAN", source_p->name,
167 chptr->chname, ms->client_p->name);
168 }
169
170 add_user_to_channel(chptr, source_p, CHFL_CHANOP, 0);
171
172 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
173 {
174 ms = ptr->data;
175
176 if (ms->client_p != source_p)
177 remove_user_from_channel(ms);
178 }
179
180 /*
181 * Join the user themselves to the channel down here, so they dont see a nicklist
182 * or people being kicked
183 */
184 sendto_one(source_p, ":%s!%s@%s JOIN %s",
185 source_p->name, source_p->username,
186 source_p->host, chptr->chname);
187 channel_member_names(source_p, chptr, 1);
188 }
189
190 /* remove_our_modes()
191 *
192 * inputs - hide from ops or not int flag
193 * - pointer to channel to remove modes from
194 * - client pointer
195 * output - NONE
196 * side effects - Go through the local members, remove all their
197 * chanop modes etc., this side lost the TS.
198 */
199 static void
200 remove_our_modes(struct Channel *chptr)
201 {
202 remove_a_mode(chptr, CHFL_CHANOP, 'o');
203 #ifdef HALFOPS
204 remove_a_mode(chptr, CHFL_HALFOP, 'h');
205 #endif
206 remove_a_mode(chptr, CHFL_VOICE, 'v');
207
208 /* Clear all +beI modes */
209 free_channel_list(&chptr->banlist);
210 free_channel_list(&chptr->exceptlist);
211 free_channel_list(&chptr->invexlist);
212 }
213
214 /* remove_a_mode()
215 *
216 * inputs -
217 * output - NONE
218 * side effects - remove ONE mode from a channel
219 */
220 static void
221 remove_a_mode(struct Channel *chptr, int mask, char flag)
222 {
223 const dlink_node *ptr = NULL;
224 char lmodebuf[MODEBUFLEN];
225 const char *lpara[4] = { "", "", "", "" };
226 char *mbuf = lmodebuf;
227 int count = 0;
228
229 *mbuf++ = '-';
230
231 DLINK_FOREACH(ptr, chptr->members.head)
232 {
233 struct Membership *ms = ptr->data;
234 if ((ms->flags & mask) == 0)
235 continue;
236
237 ms->flags &= ~mask;
238
239 lpara[count++] = ms->client_p->name;
240
241 *mbuf++ = flag;
242
243 if (count == 4)
244 {
245 *mbuf = '\0';
246 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s",
247 me.name, chptr->chname, lmodebuf, lpara[0],
248 lpara[1], lpara[2], lpara[3]);
249
250 mbuf = lmodebuf;
251 *mbuf++ = '-';
252 count = 0;
253 lpara[0] = lpara[1] = lpara[2] = lpara[3] = "";
254 }
255 }
256
257 if (count != 0)
258 {
259 *mbuf = '\0';
260 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s",
261 me.name, chptr->chname, lmodebuf, lpara[0],
262 lpara[1], lpara[2], lpara[3]);
263 }
264 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision