ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/contrib/m_clearchan.c
Revision: 885
Committed: Wed Oct 31 18:09:24 2007 UTC (16 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 7516 byte(s)
Log Message:
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

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

Properties

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