ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/m_clearchan.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
File size: 7558 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

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

Properties

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