ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_capture.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: 7350 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_capture.c: Makes a designated client captive
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 "common.h"
27     #include "handlers.h"
28     #include "client.h"
29     #include "hash.h"
30     #include "channel.h"
31     #include "channel_mode.h"
32     #include "hash.h"
33     #include "ircd.h"
34     #include "numeric.h"
35     #include "s_conf.h"
36     #include "s_serv.h"
37     #include "send.h"
38     #include "msg.h"
39     #include "parse.h"
40     #include "modules.h"
41    
42     static void mo_capture(struct Client *, struct Client *, int, char *[]);
43     static void mo_uncapture(struct Client *, struct Client *, int, char *[]);
44    
45     struct Message capture_msgtab = {
46     "CAPTURE", 0, 0, 0, 0, MFLG_SLOW, 0,
47     {m_unregistered, m_ignore, mo_capture, mo_capture, mo_capture, m_ignore}
48     };
49    
50     struct Message uncapture_msgtab = {
51     "UNCAPTURE", 0, 0, 0, 0, MFLG_SLOW, 0,
52     {m_unregistered, m_ignore, mo_uncapture, mo_uncapture, mo_uncapture, m_ignore}
53     };
54    
55     #ifndef STATIC_MODULES
56     void
57     _modinit(void)
58     {
59     mod_add_cmd(&capture_msgtab);
60     mod_add_cmd(&uncapture_msgtab);
61     }
62    
63     void
64     _moddeinit(void)
65     {
66     mod_del_cmd(&capture_msgtab);
67     mod_del_cmd(&uncapture_msgtab);
68     }
69    
70 knight 31 const char *_version = "$Revision$";
71 adx 30 #endif
72    
73     /* mo_capture
74     * parv[0] = sender prefix
75     * parv[1] = nickname masklist
76     */
77     static void
78     mo_capture(struct Client *client_p, struct Client *source_p,
79     int parc, char *parv[])
80     {
81     struct Client *target_p = NULL;
82     char *nick = NULL, *user = NULL, *host = NULL;
83     char *p = NULL;
84     dlink_node *ptr = NULL;
85    
86     if (parc < 2 || EmptyString(parv[1]))
87     {
88     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
89     me.name, source_p->name);
90     return;
91     }
92    
93     /* XXX Add oper flag in future ? */
94    
95     if (MyClient(source_p) && !IsAdmin(source_p))
96     {
97     sendto_one(source_p, form_str(ERR_NOPRIVS),
98     me.name, source_p->name, "CAPTURE");
99     return;
100     }
101    
102     if ((p = strchr(parv[1], '@')) == NULL)
103     {
104     if ((target_p = find_client(parv[1])) != NULL && IsClient(target_p))
105     {
106     if (MyConnect(target_p) && source_p != target_p)
107     {
108     if (IsOper(target_p))
109     {
110     sendto_one(source_p, form_str(ERR_NOPRIVS),
111     me.name, source_p->name, "CAPTURE");
112     return;
113     }
114    
115     if (!IsCaptured(target_p))
116     {
117     sendto_realops_flags(UMODE_ALL, L_ALL, "Captured %s (%s@%s)",
118     target_p->name, target_p->username,
119     target_p->host);
120     SetCaptured(target_p);
121     }
122    
123     sendto_one(source_p, form_str(RPL_ISCAPTURED),
124     me.name, source_p->name, target_p->name);
125     }
126     else if (IsCapable(target_p->from, CAP_ENCAP))
127     sendto_one(target_p, ":%s ENCAP %s CAPTURE %s",
128     source_p->name, target_p->from->name, target_p->name);
129     }
130     else
131     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
132     me.name, source_p->name, parv[1]);
133     }
134     else
135     {
136     unsigned int matches = 0;
137    
138     /* p != NULL so user @ host given */
139     nick = parv[1];
140     *p++ = '\0';
141     host = p;
142    
143     if ((p = strchr(nick, '!')) != NULL)
144     {
145     *p++ = '\0';
146     user = p;
147     }
148     else
149     {
150     user = nick;
151     nick = "*";
152     }
153    
154     if (!valid_wild_card(source_p, YES, 3, nick, user, host))
155     return;
156    
157     if (IsClient(client_p))
158     sendto_server(client_p, NULL, NULL, CAP_ENCAP, 0, 0,
159     ":%s ENCAP * CAPTURE %s!%s@%s",
160     source_p->name, nick, user, host);
161    
162     DLINK_FOREACH(ptr, local_client_list.head)
163     {
164     target_p = ptr->data;
165    
166     if ((source_p == target_p) || IsOper(target_p) || IsCaptured(target_p))
167     continue;
168    
169     if (match(nick, target_p->name) &&
170     match(host, target_p->host) && match(user, target_p->username))
171     {
172     SetCaptured(target_p);
173     ++matches;
174     }
175     }
176    
177     sendto_realops_flags(UMODE_ALL, L_ALL,
178     "Bulk captured %s!%s@%s, %u local match(es)",
179     nick, user, host, matches);
180     }
181     }
182    
183     /* mo_uncapture
184     * parv[0] = sender prefix
185     * parv[1] = nickname masklist
186     */
187     static void
188     mo_uncapture(struct Client *client_p, struct Client *source_p,
189     int parc, char *parv[])
190     {
191     struct Client *target_p = NULL;
192     char *nick = NULL, *user = NULL, *host = NULL, *p = NULL;
193     dlink_node *ptr = NULL;
194    
195     if (MyClient(source_p) && !IsAdmin(source_p))
196     {
197     sendto_one(source_p, form_str(ERR_NOPRIVS),
198     me.name, source_p->name, "CAPTURE");
199     return;
200     }
201    
202     if (parc < 2 || EmptyString(parv[1]))
203     {
204     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
205     me.name, source_p->name);
206     return;
207     }
208    
209     if ((p = strchr(parv[1], '@')) == NULL)
210     {
211     if ((target_p = find_client(parv[1])) != NULL && IsClient(target_p))
212     {
213     if (MyConnect(target_p))
214     {
215     if (IsCaptured(target_p))
216     {
217     ClearCaptured(target_p);
218    
219     sendto_realops_flags(UMODE_ALL, L_ALL, "Uncaptured %s (%s@%s)",
220     target_p->name, target_p->username,
221     target_p->host);
222     }
223    
224     sendto_one(source_p, form_str(RPL_ISUNCAPTURED),
225     me.name, source_p->name, target_p->name);
226     }
227     else if (IsCapable(target_p->from, CAP_ENCAP))
228     sendto_one(target_p, ":%s ENCAP %s UNCAPTURE %s",
229     source_p->name, target_p->from->name, target_p->name);
230     }
231     else
232     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
233     me.name, source_p->name, parv[1]);
234     }
235     else
236     {
237     unsigned int matches = 0;
238    
239     /* p != NULL so user @ host given */
240     nick = parv[1];
241     *p++ = '\0';
242     host = p;
243    
244     if ((p = strchr(nick, '!')) != NULL)
245     {
246     *p++ = '\0';
247     user = p;
248     }
249     else
250     {
251     user = nick;
252     nick = "*";
253     }
254    
255     if (IsClient(client_p))
256     sendto_server(client_p, NULL, NULL, CAP_ENCAP, 0, 0,
257     ":%s ENCAP * UNCAPTURE %s!%s@%s",
258     source_p->name, nick, user, host);
259    
260     DLINK_FOREACH(ptr, local_client_list.head)
261     {
262     target_p = ptr->data;
263    
264     if (!IsCaptured(target_p))
265     continue;
266    
267     if (match(nick, target_p->name) &&
268     match(host, target_p->host) && match(user, target_p->username))
269     {
270     ClearCaptured(target_p);
271     ++matches;
272     }
273     }
274    
275     sendto_realops_flags(UMODE_ALL, L_ALL,
276     "Bulk uncaptured %s!%s@%s, %u local match(es)",
277     nick, user, host, matches);
278     }
279     }

Properties

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