]> jfr.im git - irc/rqf/shadowircd.git/blob - unsupported/m_force.c
unsupported builds again \o/
[irc/rqf/shadowircd.git] / unsupported / m_force.c
1 /* contrib/m_force.c
2 * Copyright (C) 1996-2002 Hybrid Development Team
3 * Copyright (C) 2004 ircd-ratbox Development Team
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * 1.Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2.Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3.The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id: m_force.c 3297 2007-03-28 14:49:48Z jilles $
30 */
31
32 #include "stdinc.h"
33 #include "channel.h"
34 #include "class.h"
35 #include "client.h"
36 #include "common.h"
37 #include "irc_string.h"
38 #include "sprintf_irc.h"
39 #include "ircd.h"
40 #include "hostmask.h"
41 #include "numeric.h"
42 #include "s_conf.h"
43 #include "s_newconf.h"
44 #include "s_log.h"
45 #include "send.h"
46 #include "hash.h"
47 #include "s_serv.h"
48 #include "msg.h"
49 #include "parse.h"
50 #include "modules.h"
51
52 static int mo_forcejoin(struct Client *client_p, struct Client *source_p,
53 int parc, const char *parv[]);
54 static int mo_forcepart(struct Client *client_p, struct Client *source_p,
55 int parc, const char *parv[]);
56
57 struct Message forcejoin_msgtab = {
58 "FORCEJOIN", 0, 0, 0, MFLG_SLOW,
59 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcejoin, 3}}
60 };
61
62 struct Message forcepart_msgtab = {
63 "FORCEPART", 0, 0, 0, MFLG_SLOW,
64 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcepart, 3}}
65 };
66
67 mapi_clist_av1 force_clist[] = { &forcejoin_msgtab, &forcepart_msgtab, NULL };
68
69 DECLARE_MODULE_AV1(force, NULL, NULL, force_clist, NULL, NULL, "$Revision: 3297 $");
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 int
78 mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
79 {
80 struct Client *target_p;
81 struct Channel *chptr;
82 int type;
83 char mode;
84 char sjmode;
85 char *newch;
86
87 if(!IsOperAdmin(source_p))
88 {
89 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
90 return 0;
91 }
92
93 if((hunt_server(client_p, source_p, ":%s FORCEJOIN %s %s", 1, parc, parv)) != HUNTED_ISME)
94 return 0;
95
96 /* if target_p is not existant, print message
97 * to source_p and bail - scuzzy
98 */
99 if((target_p = find_client(parv[1])) == NULL)
100 {
101 sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]);
102 return 0;
103 }
104
105 if(!IsPerson(target_p))
106 return 0;
107
108 sendto_wallops_flags(UMODE_WALLOP, &me,
109 "FORCEJOIN called for %s %s by %s!%s@%s",
110 parv[1], parv[2], source_p->name, source_p->username, source_p->host);
111 ilog(L_MAIN, "FORCEJOIN called for %s %s by %s!%s@%s",
112 parv[1], parv[2], source_p->name, source_p->username, source_p->host);
113 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
114 ":%s WALLOPS :FORCEJOIN called for %s %s by %s!%s@%s",
115 me.name, parv[1], parv[2],
116 source_p->name, source_p->username, source_p->host);
117
118 /* select our modes from parv[2] if they exist... (chanop) */
119 if(*parv[2] == '@')
120 {
121 type = CHFL_CHANOP;
122 mode = 'o';
123 sjmode = '@';
124 }
125 else if(*parv[2] == '+')
126 {
127 type = CHFL_VOICE;
128 mode = 'v';
129 sjmode = '+';
130 }
131 else
132 {
133 type = CHFL_PEON;
134 mode = sjmode = '\0';
135 }
136
137 if(mode != '\0')
138 parv[2]++;
139
140 if((chptr = find_channel(parv[2])) != NULL)
141 {
142 if(IsMember(target_p, chptr))
143 {
144 /* debugging is fun... */
145 sendto_one_notice(source_p, ":*** Notice -- %s is already in %s",
146 target_p->name, chptr->chname);
147 return 0;
148 }
149
150 add_user_to_channel(chptr, target_p, type);
151
152 sendto_server(target_p, chptr, NOCAPS, NOCAPS,
153 ":%s SJOIN %ld %s + :%c%s",
154 me.name, (long) chptr->channelts,
155 chptr->chname, type ? sjmode : ' ', target_p->name);
156
157 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
158 target_p->name, target_p->username,
159 target_p->host, chptr->chname);
160
161 if(type)
162 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s",
163 me.name, chptr->chname, mode, target_p->name);
164
165 if(chptr->topic != NULL)
166 {
167 sendto_one(target_p, form_str(RPL_TOPIC), me.name,
168 target_p->name, chptr->chname, chptr->topic);
169 sendto_one(target_p, form_str(RPL_TOPICWHOTIME),
170 me.name, source_p->name, chptr->chname,
171 chptr->topic_info, chptr->topic_time);
172 }
173
174 channel_member_names(chptr, target_p, 1);
175 }
176 else
177 {
178 newch = LOCAL_COPY(parv[2]);
179 if(!check_channel_name(newch))
180 {
181 sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name,
182 source_p->name, (unsigned char *) newch);
183 return 0;
184 }
185
186 /* channel name must begin with & or # */
187 if(!IsChannelName(newch))
188 {
189 sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name,
190 source_p->name, (unsigned char *) newch);
191 return 0;
192 }
193
194 /* newch can't be longer than CHANNELLEN */
195 if(strlen(newch) > CHANNELLEN)
196 {
197 sendto_one_notice(source_p, ":Channel name is too long");
198 return 0;
199 }
200
201 chptr = get_or_create_channel(target_p, newch, NULL);
202 add_user_to_channel(chptr, target_p, CHFL_CHANOP);
203
204 /* send out a join, make target_p join chptr */
205 sendto_server(target_p, chptr, NOCAPS, NOCAPS,
206 ":%s SJOIN %ld %s +nt :@%s", me.name,
207 (long) chptr->channelts, chptr->chname, target_p->name);
208
209 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
210 target_p->name, target_p->username,
211 target_p->host, chptr->chname);
212
213 chptr->mode.mode |= MODE_TOPICLIMIT;
214 chptr->mode.mode |= MODE_NOPRIVMSGS;
215
216 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +nt", me.name, chptr->chname);
217
218 target_p->localClient->last_join_time = rb_current_time();
219 channel_member_names(chptr, target_p, 1);
220
221 /* we do this to let the oper know that a channel was created, this will be
222 * seen from the server handling the command instead of the server that
223 * the oper is on.
224 */
225 sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname);
226 }
227 return 0;
228 }
229
230
231 static int
232 mo_forcepart(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
233 {
234 struct Client *target_p;
235 struct Channel *chptr;
236 struct membership *msptr;
237
238 if(!IsOperAdmin(source_p))
239 {
240 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
241 return 0;
242 }
243
244 if((hunt_server(client_p, source_p, ":%s FORCEPART %s %s", 1, parc, parv)) != HUNTED_ISME)
245 return 0;
246
247 /* if target_p == NULL then let the oper know */
248 if((target_p = find_client(parv[1])) == NULL)
249 {
250 sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]);
251 return 0;
252 }
253
254 if(!IsClient(target_p))
255 return 0;
256
257 sendto_wallops_flags(UMODE_WALLOP, &me,
258 "FORCEPART called for %s %s by %s!%s@%s",
259 parv[1], parv[2], source_p->name, source_p->username, source_p->host);
260 ilog(L_MAIN, "FORCEPART called for %s %s by %s!%s@%s",
261 parv[1], parv[2], source_p->name, source_p->username, source_p->host);
262 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
263 ":%s WALLOPS :FORCEPART called for %s %s by %s!%s@%s",
264 me.name, parv[1], parv[2],
265 source_p->name, source_p->username, source_p->host);
266
267 if((chptr = find_channel(parv[2])) == NULL)
268 {
269 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
270 form_str(ERR_NOSUCHCHANNEL), parv[1]);
271 return 0;
272 }
273
274 if((msptr = find_channel_membership(chptr, target_p)) == NULL)
275 {
276 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
277 form_str(ERR_USERNOTINCHANNEL),
278 parv[1], parv[2]);
279 return 0;
280 }
281
282 sendto_server(target_p, chptr, NOCAPS, NOCAPS,
283 ":%s PART %s :%s", target_p->name, chptr->chname, target_p->name);
284
285 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
286 target_p->name, target_p->username,
287 target_p->host, chptr->chname, target_p->name);
288
289
290 remove_user_from_channel(msptr);
291
292 return 0;
293 }