]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
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 | * | |
a5ea0e0d | 29 | * $Id: m_force.c 3297 2007-03-28 14:49:48Z jilles $ |
212380e3 AC |
30 | */ |
31 | ||
32 | #include "stdinc.h" | |
33 | #include "tools.h" | |
34 | #include "channel.h" | |
35 | #include "class.h" | |
36 | #include "client.h" | |
37 | #include "common.h" | |
38 | #include "irc_string.h" | |
39 | #include "sprintf_irc.h" | |
40 | #include "ircd.h" | |
41 | #include "hostmask.h" | |
42 | #include "numeric.h" | |
43 | #include "commio.h" | |
44 | #include "s_conf.h" | |
45 | #include "s_newconf.h" | |
46 | #include "s_log.h" | |
47 | #include "send.h" | |
48 | #include "hash.h" | |
49 | #include "s_serv.h" | |
50 | #include "msg.h" | |
51 | #include "parse.h" | |
52 | #include "modules.h" | |
53 | #include "event.h" | |
54 | ||
55 | ||
56 | static int mo_forcejoin(struct Client *client_p, struct Client *source_p, | |
57 | int parc, const char *parv[]); | |
58 | static int mo_forcepart(struct Client *client_p, struct Client *source_p, | |
59 | int parc, const char *parv[]); | |
60 | ||
61 | struct Message forcejoin_msgtab = { | |
62 | "FORCEJOIN", 0, 0, 0, MFLG_SLOW, | |
63 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcejoin, 3}} | |
64 | }; | |
65 | ||
66 | struct Message forcepart_msgtab = { | |
67 | "FORCEPART", 0, 0, 0, MFLG_SLOW, | |
68 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcepart, 3}} | |
69 | }; | |
70 | ||
71 | mapi_clist_av1 force_clist[] = { &forcejoin_msgtab, &forcepart_msgtab, NULL }; | |
72 | ||
a5ea0e0d | 73 | DECLARE_MODULE_AV1(force, NULL, NULL, force_clist, NULL, NULL, "$Revision: 3297 $"); |
212380e3 AC |
74 | |
75 | /* | |
76 | * m_forcejoin | |
77 | * parv[0] = sender prefix | |
78 | * parv[1] = user to force | |
79 | * parv[2] = channel to force them into | |
80 | */ | |
81 | static int | |
82 | mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
83 | { | |
84 | struct Client *target_p; | |
85 | struct Channel *chptr; | |
86 | int type; | |
87 | char mode; | |
88 | char sjmode; | |
89 | char *newch; | |
90 | ||
91 | if(!IsOperAdmin(source_p)) | |
92 | { | |
a5ea0e0d | 93 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); |
212380e3 AC |
94 | return 0; |
95 | } | |
96 | ||
97 | if((hunt_server(client_p, source_p, ":%s FORCEJOIN %s %s", 1, parc, parv)) != HUNTED_ISME) | |
98 | return 0; | |
99 | ||
100 | /* if target_p is not existant, print message | |
101 | * to source_p and bail - scuzzy | |
102 | */ | |
103 | if((target_p = find_client(parv[1])) == NULL) | |
104 | { | |
105 | sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); | |
106 | return 0; | |
107 | } | |
108 | ||
109 | if(!IsPerson(target_p)) | |
110 | return 0; | |
111 | ||
112 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
113 | "FORCEJOIN called for %s %s by %s!%s@%s", | |
114 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
115 | ilog(L_MAIN, "FORCEJOIN called for %s %s by %s!%s@%s", | |
116 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
117 | sendto_server(NULL, NULL, NOCAPS, NOCAPS, | |
118 | ":%s WALLOPS :FORCEJOIN called for %s %s by %s!%s@%s", | |
119 | me.name, parv[1], parv[2], | |
120 | source_p->name, source_p->username, source_p->host); | |
121 | ||
122 | /* select our modes from parv[2] if they exist... (chanop) */ | |
123 | if(*parv[2] == '@') | |
124 | { | |
125 | type = CHFL_CHANOP; | |
126 | mode = 'o'; | |
127 | sjmode = '@'; | |
128 | } | |
129 | else if(*parv[2] == '+') | |
130 | { | |
131 | type = CHFL_VOICE; | |
132 | mode = 'v'; | |
133 | sjmode = '+'; | |
134 | } | |
135 | else | |
136 | { | |
137 | type = CHFL_PEON; | |
138 | mode = sjmode = '\0'; | |
139 | } | |
140 | ||
141 | if(mode != '\0') | |
142 | parv[2]++; | |
143 | ||
144 | if((chptr = find_channel(parv[2])) != NULL) | |
145 | { | |
146 | if(IsMember(target_p, chptr)) | |
147 | { | |
148 | /* debugging is fun... */ | |
5366977b AC |
149 | sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", |
150 | target_p->name, chptr->chname); | |
212380e3 AC |
151 | return 0; |
152 | } | |
153 | ||
154 | add_user_to_channel(chptr, target_p, type); | |
155 | ||
156 | sendto_server(target_p, chptr, NOCAPS, NOCAPS, | |
157 | ":%s SJOIN %ld %s + :%c%s", | |
158 | me.name, (long) chptr->channelts, | |
159 | chptr->chname, type ? sjmode : ' ', target_p->name); | |
160 | ||
161 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
162 | target_p->name, target_p->username, | |
163 | target_p->host, chptr->chname); | |
164 | ||
165 | if(type) | |
166 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s", | |
167 | me.name, chptr->chname, mode, target_p->name); | |
168 | ||
169 | if(chptr->topic != NULL) | |
170 | { | |
171 | sendto_one(target_p, form_str(RPL_TOPIC), me.name, | |
172 | target_p->name, chptr->chname, chptr->topic); | |
173 | sendto_one(target_p, form_str(RPL_TOPICWHOTIME), | |
174 | me.name, source_p->name, chptr->chname, | |
175 | chptr->topic_info, chptr->topic_time); | |
176 | } | |
177 | ||
178 | channel_member_names(chptr, target_p, 1); | |
179 | } | |
180 | else | |
181 | { | |
182 | newch = LOCAL_COPY(parv[2]); | |
183 | if(!check_channel_name(newch)) | |
184 | { | |
185 | sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, | |
186 | source_p->name, (unsigned char *) newch); | |
187 | return 0; | |
188 | } | |
189 | ||
190 | /* channel name must begin with & or # */ | |
191 | if(!IsChannelName(newch)) | |
192 | { | |
193 | sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, | |
194 | source_p->name, (unsigned char *) newch); | |
195 | return 0; | |
196 | } | |
197 | ||
198 | /* newch can't be longer than CHANNELLEN */ | |
199 | if(strlen(newch) > CHANNELLEN) | |
200 | { | |
5366977b | 201 | sendto_one_notice(source_p, ":Channel name is too long"); |
212380e3 AC |
202 | return 0; |
203 | } | |
204 | ||
205 | chptr = get_or_create_channel(target_p, newch, NULL); | |
206 | add_user_to_channel(chptr, target_p, CHFL_CHANOP); | |
207 | ||
208 | /* send out a join, make target_p join chptr */ | |
209 | sendto_server(target_p, chptr, NOCAPS, NOCAPS, | |
210 | ":%s SJOIN %ld %s +nt :@%s", me.name, | |
211 | (long) chptr->channelts, chptr->chname, target_p->name); | |
212 | ||
213 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
214 | target_p->name, target_p->username, | |
215 | target_p->host, chptr->chname); | |
216 | ||
217 | chptr->mode.mode |= MODE_TOPICLIMIT; | |
218 | chptr->mode.mode |= MODE_NOPRIVMSGS; | |
219 | ||
220 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +nt", me.name, chptr->chname); | |
221 | ||
222 | target_p->localClient->last_join_time = CurrentTime; | |
223 | channel_member_names(chptr, target_p, 1); | |
224 | ||
225 | /* we do this to let the oper know that a channel was created, this will be | |
226 | * seen from the server handling the command instead of the server that | |
227 | * the oper is on. | |
228 | */ | |
5366977b | 229 | sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname); |
212380e3 AC |
230 | } |
231 | return 0; | |
232 | } | |
233 | ||
234 | ||
235 | static int | |
236 | mo_forcepart(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
237 | { | |
238 | struct Client *target_p; | |
239 | struct Channel *chptr; | |
240 | struct membership *msptr; | |
241 | ||
242 | if(!IsOperAdmin(source_p)) | |
243 | { | |
a5ea0e0d | 244 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); |
212380e3 AC |
245 | return 0; |
246 | } | |
247 | ||
248 | if((hunt_server(client_p, source_p, ":%s FORCEPART %s %s", 1, parc, parv)) != HUNTED_ISME) | |
249 | return 0; | |
250 | ||
251 | /* if target_p == NULL then let the oper know */ | |
252 | if((target_p = find_client(parv[1])) == NULL) | |
253 | { | |
254 | sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); | |
255 | return 0; | |
256 | } | |
257 | ||
258 | if(!IsClient(target_p)) | |
259 | return 0; | |
260 | ||
261 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
262 | "FORCEPART called for %s %s by %s!%s@%s", | |
263 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
264 | ilog(L_MAIN, "FORCEPART called for %s %s by %s!%s@%s", | |
265 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
266 | sendto_server(NULL, NULL, NOCAPS, NOCAPS, | |
267 | ":%s WALLOPS :FORCEPART called for %s %s by %s!%s@%s", | |
268 | me.name, parv[1], parv[2], | |
269 | source_p->name, source_p->username, source_p->host); | |
270 | ||
271 | if((chptr = find_channel(parv[2])) == NULL) | |
272 | { | |
273 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
274 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
275 | return 0; | |
276 | } | |
277 | ||
278 | if((msptr = find_channel_membership(chptr, target_p)) == NULL) | |
279 | { | |
280 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
281 | form_str(ERR_USERNOTINCHANNEL), | |
282 | parv[1], parv[2]); | |
283 | return 0; | |
284 | } | |
285 | ||
286 | sendto_server(target_p, chptr, NOCAPS, NOCAPS, | |
287 | ":%s PART %s :%s", target_p->name, chptr->chname, target_p->name); | |
288 | ||
289 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", | |
290 | target_p->name, target_p->username, | |
291 | target_p->host, chptr->chname, target_p->name); | |
292 | ||
293 | ||
294 | remove_user_from_channel(msptr); | |
295 | ||
296 | return 0; | |
297 | } |