]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | * | |
212380e3 | 29 | */ |
30 | ||
31 | #include "stdinc.h" | |
212380e3 | 32 | #include "channel.h" |
33 | #include "class.h" | |
34 | #include "client.h" | |
35 | #include "common.h" | |
13ae2f4b | 36 | #include "match.h" |
212380e3 | 37 | #include "ircd.h" |
38 | #include "hostmask.h" | |
39 | #include "numeric.h" | |
212380e3 | 40 | #include "s_conf.h" |
41 | #include "s_newconf.h" | |
d3455e2c | 42 | #include "logger.h" |
212380e3 | 43 | #include "send.h" |
44 | #include "hash.h" | |
45 | #include "s_serv.h" | |
46 | #include "msg.h" | |
47 | #include "parse.h" | |
48 | #include "modules.h" | |
212380e3 | 49 | |
50 | static int mo_forcejoin(struct Client *client_p, struct Client *source_p, | |
51 | int parc, const char *parv[]); | |
212380e3 | 52 | |
53 | struct Message forcejoin_msgtab = { | |
54 | "FORCEJOIN", 0, 0, 0, MFLG_SLOW, | |
55 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_forcejoin, 3}} | |
56 | }; | |
57 | ||
96f20bc6 | 58 | mapi_clist_av1 force_clist[] = { &forcejoin_msgtab, NULL }; |
212380e3 | 59 | |
a5ea0e0d | 60 | DECLARE_MODULE_AV1(force, NULL, NULL, force_clist, NULL, NULL, "$Revision: 3297 $"); |
212380e3 | 61 | |
62 | /* | |
63 | * m_forcejoin | |
212380e3 | 64 | * parv[1] = user to force |
65 | * parv[2] = channel to force them into | |
66 | */ | |
67 | static int | |
68 | mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
69 | { | |
70 | struct Client *target_p; | |
71 | struct Channel *chptr; | |
72 | int type; | |
73 | char mode; | |
74 | char sjmode; | |
75 | char *newch; | |
76 | ||
77 | if(!IsOperAdmin(source_p)) | |
78 | { | |
a5ea0e0d | 79 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); |
212380e3 | 80 | return 0; |
81 | } | |
82 | ||
83 | if((hunt_server(client_p, source_p, ":%s FORCEJOIN %s %s", 1, parc, parv)) != HUNTED_ISME) | |
84 | return 0; | |
85 | ||
86 | /* if target_p is not existant, print message | |
87 | * to source_p and bail - scuzzy | |
88 | */ | |
89 | if((target_p = find_client(parv[1])) == NULL) | |
90 | { | |
91 | sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); | |
92 | return 0; | |
93 | } | |
94 | ||
95 | if(!IsPerson(target_p)) | |
96 | return 0; | |
97 | ||
98 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
99 | "FORCEJOIN called for %s %s by %s!%s@%s", | |
100 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
101 | ilog(L_MAIN, "FORCEJOIN called for %s %s by %s!%s@%s", | |
102 | parv[1], parv[2], source_p->name, source_p->username, source_p->host); | |
103 | sendto_server(NULL, NULL, NOCAPS, NOCAPS, | |
104 | ":%s WALLOPS :FORCEJOIN called for %s %s by %s!%s@%s", | |
105 | me.name, parv[1], parv[2], | |
106 | source_p->name, source_p->username, source_p->host); | |
107 | ||
108 | /* select our modes from parv[2] if they exist... (chanop) */ | |
109 | if(*parv[2] == '@') | |
110 | { | |
111 | type = CHFL_CHANOP; | |
112 | mode = 'o'; | |
113 | sjmode = '@'; | |
114 | } | |
115 | else if(*parv[2] == '+') | |
116 | { | |
117 | type = CHFL_VOICE; | |
118 | mode = 'v'; | |
119 | sjmode = '+'; | |
120 | } | |
121 | else | |
122 | { | |
123 | type = CHFL_PEON; | |
124 | mode = sjmode = '\0'; | |
125 | } | |
126 | ||
127 | if(mode != '\0') | |
128 | parv[2]++; | |
129 | ||
130 | if((chptr = find_channel(parv[2])) != NULL) | |
131 | { | |
132 | if(IsMember(target_p, chptr)) | |
133 | { | |
134 | /* debugging is fun... */ | |
5366977b | 135 | sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", |
136 | target_p->name, chptr->chname); | |
212380e3 | 137 | return 0; |
138 | } | |
139 | ||
140 | add_user_to_channel(chptr, target_p, type); | |
141 | ||
142 | sendto_server(target_p, chptr, NOCAPS, NOCAPS, | |
143 | ":%s SJOIN %ld %s + :%c%s", | |
144 | me.name, (long) chptr->channelts, | |
145 | chptr->chname, type ? sjmode : ' ', target_p->name); | |
146 | ||
147 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
148 | target_p->name, target_p->username, | |
149 | target_p->host, chptr->chname); | |
150 | ||
151 | if(type) | |
152 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s", | |
153 | me.name, chptr->chname, mode, target_p->name); | |
154 | ||
155 | if(chptr->topic != NULL) | |
156 | { | |
157 | sendto_one(target_p, form_str(RPL_TOPIC), me.name, | |
158 | target_p->name, chptr->chname, chptr->topic); | |
159 | sendto_one(target_p, form_str(RPL_TOPICWHOTIME), | |
160 | me.name, source_p->name, chptr->chname, | |
161 | chptr->topic_info, chptr->topic_time); | |
162 | } | |
163 | ||
164 | channel_member_names(chptr, target_p, 1); | |
165 | } | |
166 | else | |
167 | { | |
168 | newch = LOCAL_COPY(parv[2]); | |
169 | if(!check_channel_name(newch)) | |
170 | { | |
171 | sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, | |
172 | source_p->name, (unsigned char *) newch); | |
173 | return 0; | |
174 | } | |
175 | ||
176 | /* channel name must begin with & or # */ | |
177 | if(!IsChannelName(newch)) | |
178 | { | |
179 | sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, | |
180 | source_p->name, (unsigned char *) newch); | |
181 | return 0; | |
182 | } | |
183 | ||
184 | /* newch can't be longer than CHANNELLEN */ | |
185 | if(strlen(newch) > CHANNELLEN) | |
186 | { | |
5366977b | 187 | sendto_one_notice(source_p, ":Channel name is too long"); |
212380e3 | 188 | return 0; |
189 | } | |
190 | ||
191 | chptr = get_or_create_channel(target_p, newch, NULL); | |
192 | add_user_to_channel(chptr, target_p, CHFL_CHANOP); | |
193 | ||
194 | /* send out a join, make target_p join chptr */ | |
195 | sendto_server(target_p, chptr, NOCAPS, NOCAPS, | |
196 | ":%s SJOIN %ld %s +nt :@%s", me.name, | |
197 | (long) chptr->channelts, chptr->chname, target_p->name); | |
198 | ||
199 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", | |
200 | target_p->name, target_p->username, | |
201 | target_p->host, chptr->chname); | |
202 | ||
203 | chptr->mode.mode |= MODE_TOPICLIMIT; | |
204 | chptr->mode.mode |= MODE_NOPRIVMSGS; | |
205 | ||
206 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +nt", me.name, chptr->chname); | |
207 | ||
d9baf66a | 208 | target_p->localClient->last_join_time = rb_current_time(); |
212380e3 | 209 | channel_member_names(chptr, target_p, 1); |
210 | ||
211 | /* we do this to let the oper know that a channel was created, this will be | |
212 | * seen from the server handling the command instead of the server that | |
213 | * the oper is on. | |
214 | */ | |
5366977b | 215 | sendto_one_notice(source_p, ":*** Notice -- Creating channel %s", chptr->chname); |
212380e3 | 216 | } |
217 | return 0; | |
218 | } |