]> jfr.im git - solanum.git/blame - modules/m_invite.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_invite.c
CommitLineData
212380e3
AC
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
AC
25 */
26
27#include "stdinc.h"
212380e3
AC
28#include "common.h"
29#include "channel.h"
30#include "client.h"
31#include "hash.h"
4562c604 32#include "match.h"
212380e3
AC
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"
890af0e7 42#include "tgchange.h"
212380e3 43
428ca87b 44static int m_invite(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
45
46struct Message invite_msgtab = {
7baa37a9 47 "INVITE", 0, 0, 0, 0,
212380e3
AC
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
AC
52
53static void add_invite(struct Channel *, struct Client *);
54
55/* m_invite()
212380e3
AC
56 * parv[1] - user to invite
57 * parv[2] - channel name
58 */
59static int
428ca87b 60m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
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
8c39f0bf
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]))
55abcbb2
KB
77 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
78 "* :Target left IRC. Failed to invite to %s",
0482ebf7
JT
79 parv[2]);
80 else
55abcbb2
KB
81 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
82 form_str(ERR_NOSUCHNICK),
0482ebf7 83 parv[1]);
212380e3
AC
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
212380e3 95 /* Do not send local channel invites to users if they are not on the
55abcbb2 96 * same server as the person sending the INVITE message.
212380e3
AC
97 */
98 if(parv[2][0] == '&' && !MyConnect(target_p))
99 {
100 sendto_one(source_p, form_str(ERR_USERNOTONSERV),
101 me.name, source_p->name, target_p->name);
102 return 0;
103 }
104
18fc47e6
JT
105 if(((MyConnect(source_p) && !IsExemptResv(source_p)) ||
106 (MyConnect(target_p) && !IsExemptResv(target_p))) &&
107 hash_find_resv(parv[2]))
108 {
109 sendto_one_numeric(source_p, ERR_BADCHANNAME,
110 form_str(ERR_BADCHANNAME),
111 parv[2]);
112 return 0;
113 }
114
212380e3
AC
115 if((chptr = find_channel(parv[2])) == NULL)
116 {
117 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
118 form_str(ERR_NOSUCHCHANNEL), parv[2]);
119 return 0;
120 }
121
122 msptr = find_channel_membership(chptr, source_p);
123 if(MyClient(source_p) && (msptr == NULL))
124 {
125 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
126 form_str(ERR_NOTONCHANNEL), parv[2]);
127 return 0;
128 }
129
130 if(IsMember(target_p, chptr))
131 {
132 sendto_one_numeric(source_p, ERR_USERONCHANNEL,
133 form_str(ERR_USERONCHANNEL),
134 target_p->name, parv[2]);
135 return 0;
136 }
137
307328bb
JT
138 /* unconditionally require ops, unless the channel is +g */
139 /* treat remote clients as chanops */
140 if(MyClient(source_p) && !is_chanop(msptr) &&
141 !(chptr->mode.mode & MODE_FREEINVITE))
212380e3 142 {
307328bb
JT
143 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
144 me.name, source_p->name, parv[2]);
145 return 0;
212380e3
AC
146 }
147
1ebf4db4
JT
148 /* store invites when they could affect the ability to join
149 * for +l/+j just check if the mode is set, this varies over time
150 */
151 if(chptr->mode.mode & MODE_INVITEONLY ||
152 (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) ||
153 chptr->mode.limit || chptr->mode.join_num)
307328bb
JT
154 store_invite = 1;
155
212380e3
AC
156 if(MyConnect(source_p))
157 {
890af0e7
JT
158 if (ConfigFileEntry.target_change && !IsOper(source_p) &&
159 !find_allowing_channel(source_p, target_p) &&
160 !add_target(source_p, target_p))
161 {
162 sendto_one(source_p, form_str(ERR_TARGCHANGE),
163 me.name, source_p->name, target_p->name);
40b79a39 164 return 0;
890af0e7 165 }
55abcbb2 166 sendto_one(source_p, form_str(RPL_INVITING),
212380e3
AC
167 me.name, source_p->name,
168 target_p->name, parv[2]);
c127b45b 169 if(target_p->user->away)
212380e3 170 sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
c127b45b 171 target_p->name, target_p->user->away);
212380e3
AC
172 }
173 /* invite timestamp */
174 else if(parc > 3 && !EmptyString(parv[3]))
175 {
176 /* this should never be less than */
177 if(atol(parv[3]) > chptr->channelts)
178 return 0;
179 }
180
181 if(MyConnect(target_p))
182 {
0cce7774
JT
183 if(!IsOper(source_p) && (IsSetCallerId(target_p) ||
184 (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) &&
185 !accept_message(source_p, target_p))
186 {
187 if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])
188 {
189 sendto_one_numeric(source_p, ERR_NONONREG,
190 form_str(ERR_NONONREG),
191 target_p->name);
192 return 0;
193 }
194 else
195 {
196 /* instead of sending RPL_UMODEGMSG,
197 * just let the invite through
198 */
199 if((target_p->localClient->last_caller_id_time +
200 ConfigFileEntry.caller_id_wait) >= rb_current_time())
201 {
202 sendto_one_numeric(source_p, ERR_TARGUMODEG,
203 form_str(ERR_TARGUMODEG),
204 target_p->name);
205 return 0;
206 }
207 target_p->localClient->last_caller_id_time = rb_current_time();
208 }
209 }
890af0e7 210 add_reply_target(target_p, source_p);
55abcbb2
KB
211 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
212 source_p->name, source_p->username, source_p->host,
212380e3
AC
213 target_p->name, chptr->chname);
214
215 if(store_invite)
216 add_invite(chptr, target_p);
217 }
218 else if(target_p->from != client_p)
219 {
220 sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu",
221 chptr->chname, (unsigned long) chptr->channelts);
222 }
223
224 return 0;
225}
226
227/* add_invite()
228 *
229 * input - channel to add invite to, client to add
230 * output -
231 * side effects - client is added to invite list.
232 */
233static void
234add_invite(struct Channel *chptr, struct Client *who)
235{
5b96d9a6 236 rb_dlink_node *ptr;
212380e3
AC
237
238 /* already invited? */
5b96d9a6 239 RB_DLINK_FOREACH(ptr, who->user->invited.head)
212380e3
AC
240 {
241 if(ptr->data == chptr)
242 return;
243 }
244
245 /* ok, if their invite list is too long, remove the tail */
55abcbb2 246 if((int)rb_dlink_list_length(&who->user->invited) >=
212380e3
AC
247 ConfigChannel.max_chans_per_user)
248 {
249 ptr = who->user->invited.tail;
250 del_invite(ptr->data, who);
251 }
252
253 /* add user to channel invite list */
7018b86a 254 rb_dlinkAddAlloc(who, &chptr->invites);
212380e3
AC
255
256 /* add channel to user invite list */
7018b86a 257 rb_dlinkAddAlloc(chptr, &who->user->invited);
212380e3
AC
258}
259
260