/[svn]/ircd-hybrid/contrib/m_clearchan.c
ViewVC logotype

Contents of /ircd-hybrid/contrib/m_clearchan.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (show annotations)
Sun Oct 2 20:50:00 2005 UTC (14 years, 9 months ago) by knight
File MIME type: text/x-chdr
File size: 7717 byte(s)
- svn:keywords

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28