]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_invite.c
Allow /ojoin !#channel/%#channel, if admin/halfop are enabled.
[irc/rqf/shadowircd.git] / modules / m_invite.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_invite.c: Invites the user to join a channel.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
0482ebf7 24 * $Id: m_invite.c 3438 2007-05-06 14:46:45Z jilles $
212380e3 25 */
26
27#include "stdinc.h"
212380e3 28#include "common.h"
29#include "channel.h"
30#include "client.h"
31#include "hash.h"
13ae2f4b 32#include "match.h"
212380e3 33#include "ircd.h"
34#include "numeric.h"
35#include "send.h"
36#include "s_conf.h"
37#include "s_serv.h"
38#include "msg.h"
39#include "parse.h"
40#include "modules.h"
41#include "packet.h"
3f76eb8a 42#include "tgchange.h"
212380e3 43
44static int m_invite(struct Client *, struct Client *, int, const char **);
45
46struct Message invite_msgtab = {
47 "INVITE", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}}
49};
50mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL };
0482ebf7 51DECLARE_MODULE_AV1(invite, NULL, NULL, invite_clist, NULL, NULL, "$Revision: 3438 $");
212380e3 52
53static void add_invite(struct Channel *, struct Client *);
54
55/* m_invite()
212380e3 56 * parv[1] - user to invite
57 * parv[2] - channel name
58 */
59static int
60m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
61{
62 struct Client *target_p;
63 struct Channel *chptr;
64 struct membership *msptr;
65 int store_invite = 0;
66
67 if(MyClient(source_p) && !IsFloodDone(source_p))
68 flood_endgrace(source_p);
69
3499aa48
JT
70 if(MyClient(source_p))
71 target_p = find_named_person(parv[1]);
72 else
73 target_p = find_person(parv[1]);
74 if(target_p == NULL)
212380e3 75 {
0482ebf7 76 if(!MyClient(source_p) && IsDigit(parv[1][0]))
77 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
78 "* :Target left IRC. Failed to invite to %s",
79 parv[2]);
80 else
81 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
82 form_str(ERR_NOSUCHNICK),
83 parv[1]);
212380e3 84 return 0;
85 }
86
87 if(check_channel_name(parv[2]) == 0)
88 {
89 sendto_one_numeric(source_p, ERR_BADCHANNAME,
90 form_str(ERR_BADCHANNAME),
91 parv[2]);
92 return 0;
93 }
94
95 if(!IsChannelName(parv[2]))
96 {
97 if(MyClient(source_p))
98 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
99 form_str(ERR_NOSUCHCHANNEL), parv[2]);
100 return 0;
101 }
102
103 /* Do not send local channel invites to users if they are not on the
104 * same server as the person sending the INVITE message.
105 */
106 if(parv[2][0] == '&' && !MyConnect(target_p))
107 {
108 sendto_one(source_p, form_str(ERR_USERNOTONSERV),
109 me.name, source_p->name, target_p->name);
110 return 0;
111 }
112
f47964e4
JT
113 if(((MyConnect(source_p) && !IsExemptResv(source_p)) ||
114 (MyConnect(target_p) && !IsExemptResv(target_p))) &&
115 hash_find_resv(parv[2]))
116 {
117 sendto_one_numeric(source_p, ERR_BADCHANNAME,
118 form_str(ERR_BADCHANNAME),
119 parv[2]);
120 return 0;
121 }
122
212380e3 123 if((chptr = find_channel(parv[2])) == NULL)
124 {
125 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
126 form_str(ERR_NOSUCHCHANNEL), parv[2]);
127 return 0;
128 }
129
130 msptr = find_channel_membership(chptr, source_p);
131 if(MyClient(source_p) && (msptr == NULL))
132 {
133 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
134 form_str(ERR_NOTONCHANNEL), parv[2]);
135 return 0;
136 }
137
138 if(IsMember(target_p, chptr))
139 {
140 sendto_one_numeric(source_p, ERR_USERONCHANNEL,
141 form_str(ERR_USERONCHANNEL),
142 target_p->name, parv[2]);
143 return 0;
144 }
145
307328bb 146 /* unconditionally require ops, unless the channel is +g */
147 /* treat remote clients as chanops */
fbd2e5da 148 if(MyClient(source_p) && !is_any_op(msptr) &&
307328bb 149 !(chptr->mode.mode & MODE_FREEINVITE))
212380e3 150 {
fbd2e5da 151 if(IsOverride(source_p))
34d8ef4d
JH
152 {
153 sendto_wallops_flags(UMODE_WALLOP, &me,
fbd2e5da
JH
154 "%s is overriding INVITE [%s] on [%s]",
155 get_oper_name(source_p), target_p->name, chptr->chname);
34d8ef4d
JH
156 sendto_server(NULL, chptr, NOCAPS, NOCAPS,
157 ":%s WALLOPS :%s is overriding INVITE [%s] on [%s]",
71ea6069 158 me.name, get_oper_name(source_p), target_p->name, chptr->chname);
34d8ef4d 159 }
fbd2e5da
JH
160 else
161 {
162 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
163 me.name, source_p->name, parv[2]);
164 return 0;
165 }
212380e3 166 }
167
854f6bd0
G
168 if (IsSetNoInvite(target_p))
169 {
170 sendto_one_numeric(source_p, ERR_NOINVITE,
171 form_str(ERR_NOINVITE),
172 target_p->name);
173 return 0;
174 }
175
1ebf4db4 176 /* store invites when they could affect the ability to join
177 * for +l/+j just check if the mode is set, this varies over time
178 */
179 if(chptr->mode.mode & MODE_INVITEONLY ||
180 (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) ||
181 chptr->mode.limit || chptr->mode.join_num)
307328bb 182 store_invite = 1;
183
212380e3 184 if(MyConnect(source_p))
185 {
3f76eb8a
JT
186 if (ConfigFileEntry.target_change && !IsOper(source_p) &&
187 !find_allowing_channel(source_p, target_p) &&
188 !add_target(source_p, target_p))
189 {
190 sendto_one(source_p, form_str(ERR_TARGCHANGE),
191 me.name, source_p->name, target_p->name);
0f18c084 192 return 0;
3f76eb8a 193 }
212380e3 194 sendto_one(source_p, form_str(RPL_INVITING),
195 me.name, source_p->name,
196 target_p->name, parv[2]);
c387fc41 197 if(target_p->user->away)
212380e3 198 sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
c387fc41 199 target_p->name, target_p->user->away);
212380e3 200 }
201 /* invite timestamp */
202 else if(parc > 3 && !EmptyString(parv[3]))
203 {
204 /* this should never be less than */
205 if(atol(parv[3]) > chptr->channelts)
206 return 0;
207 }
208
209 if(MyConnect(target_p))
210 {
625a2b1f
JT
211 if(!IsOper(source_p) && (IsSetCallerId(target_p) ||
212 (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) &&
213 !accept_message(source_p, target_p))
214 {
215 if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])
216 {
217 sendto_one_numeric(source_p, ERR_NONONREG,
218 form_str(ERR_NONONREG),
219 target_p->name);
220 return 0;
221 }
222 else
223 {
224 /* instead of sending RPL_UMODEGMSG,
225 * just let the invite through
226 */
227 if((target_p->localClient->last_caller_id_time +
228 ConfigFileEntry.caller_id_wait) >= rb_current_time())
229 {
230 sendto_one_numeric(source_p, ERR_TARGUMODEG,
231 form_str(ERR_TARGUMODEG),
232 target_p->name);
233 return 0;
234 }
235 target_p->localClient->last_caller_id_time = rb_current_time();
236 }
237 }
3f76eb8a 238 add_reply_target(target_p, source_p);
212380e3 239 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
240 source_p->name, source_p->username, source_p->host,
241 target_p->name, chptr->chname);
242
243 if(store_invite)
244 add_invite(chptr, target_p);
245 }
246 else if(target_p->from != client_p)
247 {
248 sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu",
249 chptr->chname, (unsigned long) chptr->channelts);
250 }
251
252 return 0;
253}
254
255/* add_invite()
256 *
257 * input - channel to add invite to, client to add
258 * output -
259 * side effects - client is added to invite list.
260 */
261static void
262add_invite(struct Channel *chptr, struct Client *who)
263{
08d11e34 264 rb_dlink_node *ptr;
212380e3 265
266 /* already invited? */
08d11e34 267 RB_DLINK_FOREACH(ptr, who->user->invited.head)
212380e3 268 {
269 if(ptr->data == chptr)
270 return;
271 }
272
273 /* ok, if their invite list is too long, remove the tail */
08d11e34 274 if((int)rb_dlink_list_length(&who->user->invited) >=
212380e3 275 ConfigChannel.max_chans_per_user)
276 {
277 ptr = who->user->invited.tail;
278 del_invite(ptr->data, who);
279 }
280
281 /* add user to channel invite list */
7f4fa195 282 rb_dlinkAddAlloc(who, &chptr->invites);
212380e3 283
284 /* add channel to user invite list */
7f4fa195 285 rb_dlinkAddAlloc(chptr, &who->user->invited);
212380e3 286}
287
288