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