ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/m_force.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (14 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 10646 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 /* 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 * $Id$
29 */
30
31 #include "stdinc.h"
32 #include "client.h"
33 #include "ircd.h"
34 #include "irc_string.h"
35 #include "numeric.h"
36 #include "fdlist.h"
37 #include "hash.h"
38 #include "s_bsd.h"
39 #include "conf.h"
40 #include "s_serv.h"
41 #include "send.h"
42 #include "parse.h"
43 #include "modules.h"
44 #include "channel.h"
45 #include "channel_mode.h"
46
47
48 /* m_forcejoin()
49 * parv[0] = sender prefix
50 * parv[1] = user to force
51 * parv[2] = channel to force them into
52 */
53 static void
54 mo_forcejoin(struct Client *client_p, struct Client *source_p,
55 int parc, char *parv[])
56 {
57 struct Client *target_p = NULL;
58 struct Channel *chptr = NULL;
59 unsigned int type = 0;
60 char mode = '\0';
61 char sjmode = '\0';
62 char *newch = NULL;
63 dlink_node *ptr = NULL;
64
65 if (!HasUMode(source_p, UMODE_ADMIN))
66 {
67 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
68 me.name, source_p->name);
69 return;
70 }
71
72 if ((target_p = hash_find_client(parv[1])) == NULL || !IsClient(target_p))
73 {
74 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
75 me.name, source_p->name, parv[1]);
76 return;
77 }
78
79 if (!MyConnect(target_p))
80 {
81 if (target_p->from != client_p)
82 {
83 if (IsCapable(target_p->from, CAP_ENCAP))
84 sendto_one(target_p, ":%s ENCAP %s FORCEJOIN %s %s",
85 source_p->name, target_p->from->name,
86 target_p->name, parv[2]);
87 else
88 sendto_one(target_p, ":%s FORCEJOIN %s %s",
89 source_p->name, target_p->name, parv[2]);
90 }
91
92 return;
93 }
94
95 /* select our modes from parv[2] if they exist... (chanop)*/
96 switch (*parv[2])
97 {
98 case '@':
99 type = CHFL_CHANOP;
100 mode = 'o';
101 sjmode = '@';
102 parv[2]++;
103 break;
104 #ifdef HALFOPS
105 case '%':
106 type = CHFL_HALFOP;
107 mode = 'h';
108 sjmode = '%';
109 parv[2]++;
110 break;
111 #endif
112 case '+':
113 type = CHFL_VOICE;
114 mode = 'v';
115 sjmode = '+';
116 parv[2]++;
117 break;
118 default:
119 type = 0;
120 mode = sjmode = '\0'; /* make sure sjmode is 0. sjoin depends on it */
121 break;
122 }
123
124 if ((chptr = hash_find_channel(parv[2])) != NULL)
125 {
126 if (IsMember(target_p, chptr))
127 {
128 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- %s is already in %s",
129 me.name, source_p->name, target_p->name, chptr->chname);
130 return;
131 }
132
133 add_user_to_channel(chptr, target_p, type, 0);
134
135 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
136 target_p->name, target_p->username,
137 target_p->host, chptr->chname);
138
139 if (sjmode)
140 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +%c %s",
141 me.name, chptr->chname, mode, target_p->name);
142
143 if (chptr->chname[0] == '#')
144 {
145 if (sjmode)
146 {
147 DLINK_FOREACH (ptr, serv_list.head)
148 {
149 struct Client *serv_p = ptr->data;
150 if (serv_p == target_p->from || IsDead(serv_p))
151 continue;
152
153 sendto_one(serv_p, ":%s SJOIN %lu %s + :%c%s",
154 ID_or_name(&me, serv_p), (unsigned long)chptr->channelts,
155 chptr->chname, (sjmode == '%' &&
156 !IsCapable(serv_p, CAP_HOPS)) ? '@' : sjmode,
157 ID_or_name(target_p, serv_p));
158 }
159 }
160 else
161 {
162 sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
163 ":%s SJOIN %lu %s + :%s",
164 me.id, (unsigned long)chptr->channelts,
165 chptr->chname, target_p->id);
166 sendto_server(target_p, chptr, NOCAPS, CAP_TS6,
167 ":%s SJOIN %lu %s + :%s",
168 me.name, (unsigned long)chptr->channelts,
169 chptr->chname, target_p->name);
170 }
171 }
172
173 if (chptr->topic[0])
174 {
175 sendto_one(target_p, form_str(RPL_TOPIC),
176 me.name, target_p->name,
177 chptr->chname, chptr->topic);
178 sendto_one(target_p, form_str(RPL_TOPICWHOTIME),
179 me.name, target_p->name, chptr->chname,
180 chptr->topic_info, chptr->topic_time);
181 }
182
183 target_p->localClient->last_join_time = CurrentTime;
184 channel_member_names(target_p, chptr, 1);
185 }
186 else
187 {
188 newch = parv[2];
189
190 if (!check_channel_name(newch, 1))
191 {
192 sendto_one(source_p, form_str(ERR_BADCHANNAME),
193 me.name, source_p->name, newch);
194 return;
195 }
196
197 /*
198 * it would be interesting here to allow an oper
199 * to force target_p into a channel that doesn't exist
200 * even more so, into a local channel when we disable
201 * local channels... but...
202 * I don't want to break anything - scuzzy
203 */
204 if (ConfigChannel.disable_local_channels && (*newch == '&'))
205 {
206 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
207 me.name, source_p->name, newch);
208 return;
209 }
210
211 chptr = make_channel(newch);
212 add_user_to_channel(chptr, target_p, CHFL_CHANOP, 0);
213
214 /* send out a join, make target_p join chptr */
215 if (chptr->chname[0] == '#')
216 {
217 sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
218 ":%s SJOIN %lu %s +nt :@%s",
219 me.id, (unsigned long)chptr->channelts,
220 chptr->chname, ID(target_p));
221 sendto_server(target_p, chptr, NOCAPS, CAP_TS6,
222 ":%s SJOIN %lu %s +nt :@%s",
223 me.name, (unsigned long)chptr->channelts,
224 chptr->chname, target_p->name);
225 }
226
227 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
228 target_p->name, target_p->username,
229 target_p->host, chptr->chname);
230
231 chptr->mode.mode |= MODE_TOPICLIMIT | MODE_NOPRIVMSGS;
232
233 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
234 me.name, chptr->chname);
235
236 target_p->localClient->last_join_time = CurrentTime;
237 channel_member_names(target_p, chptr, 1);
238
239 /* we do this to let the oper know that a channel was created, this will be
240 * seen from the server handling the command instead of the server that
241 * the oper is on.
242 */
243 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Creating channel %s",
244 me.name, source_p->name, chptr->chname);
245 }
246 }
247
248 static void
249 mo_forcepart(struct Client *client_p, struct Client *source_p,
250 int parc, char *parv[])
251 {
252 struct Client *target_p = NULL;
253 struct Channel *chptr = NULL;
254 struct Membership *member = NULL;
255
256 if (!HasUMode(source_p, UMODE_ADMIN))
257 {
258 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
259 me.name, source_p->name);
260 return;
261 }
262
263 /* if target_p == NULL then let the oper know */
264 if ((target_p = hash_find_client(parv[1])) == NULL || !IsClient(target_p))
265 {
266 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
267 me.name, source_p->name, parv[1]);
268 return;
269 }
270
271 if (!MyConnect(target_p))
272 {
273 if (target_p->from != client_p)
274 {
275 if (IsCapable(target_p->from, CAP_ENCAP))
276 sendto_one(target_p, ":%s ENCAP %s FORCEPART %s %s",
277 source_p->name, target_p->from->name,
278 target_p->name, parv[2]);
279 else
280 sendto_one(target_p, ":%s FORCEPART %s %s",
281 source_p->name, target_p->name, parv[2]);
282 }
283
284 return;
285 }
286
287 if ((chptr = hash_find_channel(parv[2])) == NULL)
288 {
289 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
290 me.name, source_p->name, parv[2]);
291 return;
292 }
293
294 if ((member = find_channel_link(target_p, chptr)) == NULL)
295 {
296 sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
297 me.name, source_p->name, chptr->chname, target_p->name);
298 return;
299 }
300
301 if (chptr->chname[0] == '#')
302 {
303 sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
304 ":%s PART %s :%s", ID(target_p),
305 chptr->chname, target_p->name);
306 sendto_server(target_p, chptr, NOCAPS, CAP_TS6,
307 ":%s PART %s :%s", target_p->name,
308 chptr->chname, target_p->name);
309 }
310
311 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s",
312 target_p->name, target_p->username,
313 target_p->host, chptr->chname,
314 target_p->name);
315 remove_user_from_channel(member);
316 }
317
318 static struct Message forcejoin_msgtab = {
319 "FORCEJOIN", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
320 { m_ignore, m_not_oper, mo_forcejoin, mo_forcejoin, mo_forcejoin, m_ignore }
321 };
322
323 static struct Message forcepart_msgtab = {
324 "FORCEPART", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
325 { m_ignore, m_not_oper, mo_forcepart, mo_forcepart, mo_forcepart, m_ignore }
326 };
327
328 static void
329 module_init(void)
330 {
331 mod_add_cmd(&forcejoin_msgtab);
332 mod_add_cmd(&forcepart_msgtab);
333 }
334
335 static void
336 module_exit(void)
337 {
338 mod_del_cmd(&forcejoin_msgtab);
339 mod_del_cmd(&forcepart_msgtab);
340 }
341
342 struct module module_entry = {
343 .node = { NULL, NULL, NULL },
344 .name = NULL,
345 .version = "$Revision$",
346 .handle = NULL,
347 .modinit = module_init,
348 .modexit = module_exit,
349 .flags = 0
350 };

Properties

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