ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_clearchan.c
Revision: 76
Committed: Tue Oct 4 19:38:49 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 7612 byte(s)
Log Message:
- fixed contrib #includes

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

Properties

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