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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 616 - (show annotations)
Mon May 22 07:10:56 2006 UTC (14 years, 1 month ago) by michael
File MIME type: text/x-chdr
File size: 7676 byte(s)
- Backported m_clearchan:kick_list fixes

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 *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, NO, 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, source_p, chptr, NOCAPS, NOCAPS, LL_ICLIENT,
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, NO);
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, NO, 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, NO, 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

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