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