ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/contrib/m_clearchan.c
Revision: 1028
Committed: Sun Nov 8 13:03:38 2009 UTC (16 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/contrib/m_clearchan.c
File size: 7491 byte(s)
Log Message:
- move ircd-hybrid-7.2 to trunk

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #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 knight 31 const char *_version = "$Revision$";
69 adx 30 #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 michael 885 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
107 adx 30 ":%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 michael 885 /*
114     * Kill all the modes we have about the channel..
115 adx 30 * making everyone a peon
116     */
117     remove_our_modes(chptr);
118    
119     /* SJOIN the user to give them ops, and lock the channel */
120 michael 885 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
121 adx 30 ":%s JOIN %lu %s +ntsi",
122     source_p->id, (unsigned long)(chptr->channelts - 1),
123     chptr->chname);
124 michael 885 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
125     ":%s SJOIN %lu %s +ntsi :@%s",
126 adx 30 me.name, (unsigned long)(chptr->channelts - 1),
127     chptr->chname, source_p->name);
128 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN %s",
129 adx 30 source_p->name, source_p->username,
130     source_p->host, chptr->chname);
131 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +o %s",
132 adx 30 me.name, chptr->chname, source_p->name);
133    
134    
135 michael 885 /*
136     * Take the TS down by 1, so we don't see the channel taken over
137     * again.
138     */
139 adx 30 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 michael 616 dlink_node *ptr = NULL, *ptr_next = NULL;
155     struct Membership *ms = NULL;
156 adx 30
157 michael 616 DLINK_FOREACH(ptr, chptr->members.head)
158 adx 30 {
159 michael 616 ms = ptr->data;
160 adx 30
161 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr,
162 michael 616 ":%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 michael 885 sendto_server(NULL, chptr, NOCAPS, NOCAPS,
166 adx 30 ":%s KICK %s %s :CLEARCHAN", source_p->name,
167     chptr->chname, ms->client_p->name);
168     }
169    
170 michael 1011 add_user_to_channel(chptr, source_p, CHFL_CHANOP, 0);
171 michael 616
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 adx 30 /*
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 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s",
247 adx 30 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 michael 1011 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s %s %s %s %s %s",
261 adx 30 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