ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_force.c
Revision: 677
Committed: Tue Jun 13 17:12:38 2006 UTC (20 years, 1 month ago) by adx
Content type: text/x-csrc
File size: 10611 byte(s)
Log Message:
+ fixed contrib

File Contents

# User Rev Content
1 adx 30 /* contrib/m_force.c
2     * Copyright (C) 2002, 2003, 2004, 2005 Hybrid Development Team
3     *
4     * Redistribution and use in source and binary forms, with or without
5     * modification, are permitted provided that the following conditions are
6     * met:
7     *
8     * 1.Redistributions of source code must retain the above copyright notice,
9     * this list of conditions and the following disclaimer.
10     * 2.Redistributions in binary form must reproduce the above copyright
11     * notice, this list of conditions and the following disclaimer in the
12     * documentation and/or other materials provided with the distribution.
13     * 3.The name of the author may not be used to endorse or promote products
14     * derived from this software without specific prior written permission.
15     *
16     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18     * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19     * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20     * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21     * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22     * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24     * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25     * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26     * POSSIBILITY OF SUCH DAMAGE.
27     *
28 knight 31 * $Id$
29 adx 30 */
30    
31     #include "stdinc.h"
32     #include "handlers.h"
33     #include "client.h"
34     #include "common.h" /* FALSE bleah */
35     #include "ircd.h"
36     #include "numeric.h"
37     #include "hash.h"
38     #include "s_conf.h"
39     #include "s_serv.h"
40     #include "send.h"
41     #include "msg.h"
42     #include "parse.h"
43 adx 677 #include "conf/modules.h"
44 adx 30 #include "channel.h"
45     #include "channel_mode.h"
46    
47     static void mo_forcejoin(struct Client *, struct Client *, int parc, char *[]);
48     static void mo_forcepart(struct Client *, struct Client *, int parc, char *[]);
49    
50     struct Message forcejoin_msgtab = {
51     "FORCEJOIN", 0, 0, 3, 0, MFLG_SLOW, 0,
52     { m_ignore, m_not_oper, mo_forcejoin, mo_forcejoin, mo_forcejoin, m_ignore }
53     };
54    
55     struct Message forcepart_msgtab = {
56     "FORCEPART", 0, 0, 3, 0, MFLG_SLOW, 0,
57     { m_ignore, m_not_oper, mo_forcepart, mo_forcepart, mo_forcepart, m_ignore }
58     };
59    
60 adx 443 INIT_MODULE(m_force, "$Revision$")
61 adx 30 {
62     mod_add_cmd(&forcejoin_msgtab);
63     mod_add_cmd(&forcepart_msgtab);
64     }
65    
66 adx 443 CLEANUP_MODULE
67 adx 30 {
68 adx 443 mod_del_cmd(&forcepart_msgtab);
69 adx 30 mod_del_cmd(&forcejoin_msgtab);
70     }
71    
72     /* m_forcejoin()
73     * parv[0] = sender prefix
74     * parv[1] = user to force
75     * parv[2] = channel to force them into
76     */
77     static void
78     mo_forcejoin(struct Client *client_p, struct Client *source_p,
79     int parc, char *parv[])
80     {
81     struct Client *target_p = NULL;
82     struct Channel *chptr = NULL;
83     unsigned int type = 0;
84     char mode = '\0';
85     char sjmode = '\0';
86     char *newch = NULL;
87 michael 491 dlink_node *ptr = NULL;
88 adx 30
89     if (!IsAdmin(source_p))
90     {
91     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
92     me.name, source_p->name);
93     return;
94     }
95    
96 michael 491 if ((target_p = find_client(parv[1])) == NULL || !IsClient(target_p))
97 adx 30 {
98     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
99     me.name, source_p->name, parv[1]);
100     return;
101     }
102    
103     if (!MyConnect(target_p))
104     {
105     if (target_p->from != client_p)
106     {
107     if (IsCapable(target_p->from, CAP_ENCAP))
108     sendto_one(target_p, ":%s ENCAP %s FORCEJOIN %s %s",
109     source_p->name, target_p->from->name,
110     target_p->name, parv[2]);
111     else
112     sendto_one(target_p, ":%s FORCEJOIN %s %s",
113     source_p->name, target_p->name, parv[2]);
114     }
115    
116     return;
117     }
118    
119     /* select our modes from parv[2] if they exist... (chanop)*/
120     switch (*parv[2])
121     {
122     case '@':
123     type = CHFL_CHANOP;
124     mode = 'o';
125     sjmode = '@';
126     parv[2]++;
127     break;
128     #ifdef HALFOPS
129     case '%':
130     type = CHFL_HALFOP;
131     mode = 'h';
132     sjmode = '%';
133     parv[2]++;
134     break;
135     #endif
136     case '+':
137     type = CHFL_VOICE;
138     mode = 'v';
139     sjmode = '+';
140     parv[2]++;
141     break;
142     default:
143     type = 0;
144     mode = sjmode = '\0'; /* make sure sjmode is 0. sjoin depends on it */
145     break;
146     }
147    
148     if ((chptr = hash_find_channel(parv[2])) != NULL)
149     {
150     if (IsMember(target_p, chptr))
151     {
152     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- %s is already in %s",
153     me.name, source_p->name, target_p->name, chptr->chname);
154     return;
155     }
156    
157     add_user_to_channel(chptr, target_p, type, NO);
158    
159     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
160     target_p->name, target_p->username,
161     target_p->host, chptr->chname);
162    
163     if (sjmode)
164     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s +%c %s",
165     me.name, chptr->chname, mode, target_p->name);
166    
167     if (chptr->chname[0] == '#')
168     {
169     if (sjmode)
170 michael 491 {
171 adx 355 DLINK_FOREACH (ptr, serv_list.head)
172     {
173     struct Client *serv_p = ptr->data;
174     if (serv_p == target_p->from || IsDead(serv_p))
175     continue;
176    
177     sendto_one(serv_p, ":%s SJOIN %lu %s + :%c%s",
178     ID_or_name(&me, serv_p), (unsigned long)chptr->channelts,
179     chptr->chname, (sjmode == '%' &&
180     !IsCapable(serv_p, CAP_HOPS)) ? '@' : sjmode,
181     ID_or_name(target_p, serv_p));
182     }
183 michael 491 }
184 adx 30 else
185     {
186 michael 405 sendto_server(target_p, target_p, chptr, CAP_TS6, NOCAPS,
187 adx 30 ":%s SJOIN %lu %s + :%s",
188     me.id, (unsigned long)chptr->channelts,
189     chptr->chname, target_p->id);
190 michael 405 sendto_server(target_p, target_p, chptr, NOCAPS, CAP_TS6,
191 adx 30 ":%s SJOIN %lu %s + :%s",
192     me.name, (unsigned long)chptr->channelts,
193     chptr->chname, target_p->name);
194     }
195     }
196    
197     if (chptr->topic != NULL)
198     {
199     sendto_one(target_p, form_str(RPL_TOPIC),
200     me.name, target_p->name,
201     chptr->chname, chptr->topic);
202     sendto_one(target_p, form_str(RPL_TOPICWHOTIME),
203     me.name, source_p->name, chptr->chname,
204     chptr->topic_info, chptr->topic_time);
205     }
206    
207     target_p->localClient->last_join_time = CurrentTime;
208     channel_member_names(target_p, chptr, 1);
209     }
210     else
211     {
212     newch = parv[2];
213    
214 michael 491 if (!check_channel_name(newch, 1))
215 adx 30 {
216     sendto_one(source_p, form_str(ERR_BADCHANNAME),
217     me.name, source_p->name, newch);
218     return;
219     }
220    
221 michael 491 /*
222     * it would be interesting here to allow an oper
223 adx 30 * to force target_p into a channel that doesn't exist
224     * even more so, into a local channel when we disable
225     * local channels... but...
226     * I don't want to break anything - scuzzy
227     */
228     if (ConfigChannel.disable_local_channels && (*newch == '&'))
229     {
230     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
231     me.name, source_p->name, newch);
232     return;
233     }
234    
235 michael 491 chptr = make_channel(newch);
236 adx 30 add_user_to_channel(chptr, target_p, CHFL_CHANOP, NO);
237    
238     /* send out a join, make target_p join chptr */
239     if (chptr->chname[0] == '#')
240     {
241 michael 405 sendto_server(target_p, target_p, chptr, CAP_TS6, NOCAPS,
242 adx 30 ":%s SJOIN %lu %s +nt :@%s",
243     me.id, (unsigned long)chptr->channelts,
244     chptr->chname, ID(target_p));
245 michael 405 sendto_server(target_p, target_p, chptr, NOCAPS, CAP_TS6,
246 adx 30 ":%s SJOIN %lu %s +nt :@%s",
247     me.name, (unsigned long)chptr->channelts,
248     chptr->chname, target_p->name);
249     }
250    
251     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
252     target_p->name, target_p->username,
253     target_p->host, chptr->chname);
254    
255     chptr->mode.mode |= MODE_TOPICLIMIT | MODE_NOPRIVMSGS;
256    
257     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s +nt",
258     me.name, chptr->chname);
259    
260     target_p->localClient->last_join_time = CurrentTime;
261     channel_member_names(target_p, chptr, 1);
262    
263 michael 491 /*
264     * We do this to let the oper know that a channel was created, this will be
265 adx 30 * seen from the server handling the command instead of the server that
266     * the oper is on.
267     */
268     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Creating channel %s",
269     me.name, source_p->name, chptr->chname);
270     }
271     }
272    
273     static void
274     mo_forcepart(struct Client *client_p, struct Client *source_p,
275     int parc, char *parv[])
276     {
277     struct Client *target_p = NULL;
278     struct Channel *chptr = NULL;
279     struct Membership *member = NULL;
280    
281     if (!IsAdmin(source_p))
282     {
283     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
284     me.name, source_p->name);
285     return;
286     }
287    
288     /* if target_p == NULL then let the oper know */
289     if ((target_p = find_client(parv[1])) == NULL)
290     {
291     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
292     me.name, source_p->name, parv[1]);
293     return;
294     }
295    
296     if (!MyConnect(target_p))
297     {
298     if (target_p->from != client_p)
299     {
300     if (IsCapable(target_p->from, CAP_ENCAP))
301     sendto_one(target_p, ":%s ENCAP %s FORCEPART %s %s",
302     source_p->name, target_p->from->name,
303     target_p->name, parv[2]);
304     else
305     sendto_one(target_p, ":%s FORCEPART %s %s",
306     source_p->name, target_p->name, parv[2]);
307     }
308    
309     return;
310     }
311    
312     if ((chptr = hash_find_channel(parv[2])) == NULL)
313     {
314     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
315     me.name, source_p->name, parv[2]);
316     return;
317     }
318    
319     if ((member = find_channel_link(target_p, chptr)) == NULL)
320     {
321     sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
322     me.name, source_p->name, chptr->chname, target_p->name);
323     return;
324     }
325    
326     if (chptr->chname[0] == '#')
327     {
328 michael 405 sendto_server(target_p, target_p, chptr, CAP_TS6, NOCAPS,
329 adx 30 ":%s PART %s :%s", ID(target_p),
330     chptr->chname, target_p->name);
331 michael 405 sendto_server(target_p, target_p, chptr, NOCAPS, CAP_TS6,
332 adx 30 ":%s PART %s :%s", target_p->name,
333     chptr->chname, target_p->name);
334     }
335    
336     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s PART %s :%s",
337     target_p->name, target_p->username,
338     target_p->host, chptr->chname,
339     target_p->name);
340     remove_user_from_channel(member);
341     }

Properties

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