]> jfr.im git - solanum.git/blame - modules/m_invite.c
add separate priv (oper:message) for walking over CALLERID (umode +g) (#152)
[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
212380e3
AC
23 */
24
25#include "stdinc.h"
212380e3
AC
26#include "channel.h"
27#include "client.h"
28#include "hash.h"
4562c604 29#include "match.h"
212380e3
AC
30#include "ircd.h"
31#include "numeric.h"
32#include "send.h"
33#include "s_conf.h"
34#include "s_serv.h"
35#include "msg.h"
36#include "parse.h"
37#include "modules.h"
38#include "packet.h"
890af0e7 39#include "tgchange.h"
d4f7eb4c 40#include "s_newconf.h"
212380e3 41
91ccda4f 42static const char invite_desc[] = "Provides /invite";
eeabf33a 43
3c7d6fcc 44static void 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};
4c83e476 50
e0622d75
EK
51static int can_invite_hook;
52static int invite_hook;
53
df1f1212 54mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL };
e0622d75
EK
55mapi_hlist_av1 invite_hlist[] = {
56 { "can_invite", &can_invite_hook },
57 { "invite", &invite_hook },
58 { NULL, NULL }
59};
4c83e476 60
91ccda4f 61DECLARE_MODULE_AV2(invite, NULL, NULL, invite_clist, invite_hlist, NULL, NULL, NULL, invite_desc);
212380e3 62
f88fd40f 63static bool add_invite(struct Channel *, struct Client *);
212380e3
AC
64
65/* m_invite()
212380e3
AC
66 * parv[1] - user to invite
67 * parv[2] - channel name
68 */
3c7d6fcc 69static void
428ca87b 70m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
71{
72 struct Client *target_p;
73 struct Channel *chptr;
74 struct membership *msptr;
75 int store_invite = 0;
e0622d75 76 hook_data_channel_approval hdata = { 0 };
212380e3
AC
77
78 if(MyClient(source_p) && !IsFloodDone(source_p))
79 flood_endgrace(source_p);
80
8c39f0bf
JT
81 if(MyClient(source_p))
82 target_p = find_named_person(parv[1]);
83 else
84 target_p = find_person(parv[1]);
85 if(target_p == NULL)
212380e3 86 {
0482ebf7 87 if(!MyClient(source_p) && IsDigit(parv[1][0]))
55abcbb2
KB
88 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
89 "* :Target left IRC. Failed to invite to %s",
0482ebf7
JT
90 parv[2]);
91 else
55abcbb2
KB
92 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
93 form_str(ERR_NOSUCHNICK),
0482ebf7 94 parv[1]);
3c7d6fcc 95 return;
212380e3
AC
96 }
97
98 if(check_channel_name(parv[2]) == 0)
99 {
100 sendto_one_numeric(source_p, ERR_BADCHANNAME,
101 form_str(ERR_BADCHANNAME),
102 parv[2]);
3c7d6fcc 103 return;
212380e3
AC
104 }
105
212380e3 106 /* Do not send local channel invites to users if they are not on the
55abcbb2 107 * same server as the person sending the INVITE message.
212380e3
AC
108 */
109 if(parv[2][0] == '&' && !MyConnect(target_p))
110 {
111 sendto_one(source_p, form_str(ERR_USERNOTONSERV),
112 me.name, source_p->name, target_p->name);
3c7d6fcc 113 return;
212380e3
AC
114 }
115
18fc47e6
JT
116 if(((MyConnect(source_p) && !IsExemptResv(source_p)) ||
117 (MyConnect(target_p) && !IsExemptResv(target_p))) &&
118 hash_find_resv(parv[2]))
119 {
120 sendto_one_numeric(source_p, ERR_BADCHANNAME,
121 form_str(ERR_BADCHANNAME),
122 parv[2]);
3c7d6fcc 123 return;
18fc47e6
JT
124 }
125
212380e3
AC
126 if((chptr = find_channel(parv[2])) == NULL)
127 {
128 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
129 form_str(ERR_NOSUCHCHANNEL), parv[2]);
3c7d6fcc 130 return;
212380e3
AC
131 }
132
133 msptr = find_channel_membership(chptr, source_p);
134 if(MyClient(source_p) && (msptr == NULL))
135 {
136 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
137 form_str(ERR_NOTONCHANNEL), parv[2]);
3c7d6fcc 138 return;
212380e3
AC
139 }
140
141 if(IsMember(target_p, chptr))
142 {
143 sendto_one_numeric(source_p, ERR_USERONCHANNEL,
144 form_str(ERR_USERONCHANNEL),
145 target_p->name, parv[2]);
3c7d6fcc 146 return;
212380e3
AC
147 }
148
e3c27d7d 149 if (MyClient(source_p))
212380e3 150 {
e3c27d7d
AC
151 hdata.chptr = chptr;
152 hdata.msptr = msptr;
153 hdata.client = source_p;
154 hdata.target = target_p;
155 hdata.approved = !(is_chanop(msptr) || (chptr->mode.mode & MODE_FREEINVITE));
156
157 call_hook(can_invite_hook, &hdata);
158 if (hdata.approved)
e0622d75
EK
159 {
160 if (hdata.error)
161 sendto_one_numeric(source_p, hdata.approved, "%s", hdata.error);
27590ae0 162 else
e0622d75 163 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
e3c27d7d 164 me.name, source_p->name, parv[2]);
4371dcbd 165
e3c27d7d
AC
166 return;
167 }
212380e3
AC
168 }
169
1ebf4db4
JT
170 /* store invites when they could affect the ability to join
171 * for +l/+j just check if the mode is set, this varies over time
172 */
173 if(chptr->mode.mode & MODE_INVITEONLY ||
174 (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) ||
175 chptr->mode.limit || chptr->mode.join_num)
307328bb
JT
176 store_invite = 1;
177
212380e3
AC
178 if(MyConnect(source_p))
179 {
d4f7eb4c 180 if (ConfigFileEntry.target_change && !IsOperGeneral(source_p) &&
890af0e7
JT
181 !find_allowing_channel(source_p, target_p) &&
182 !add_target(source_p, target_p))
183 {
184 sendto_one(source_p, form_str(ERR_TARGCHANGE),
185 me.name, source_p->name, target_p->name);
3c7d6fcc 186 return;
890af0e7 187 }
55abcbb2 188 sendto_one(source_p, form_str(RPL_INVITING),
212380e3
AC
189 me.name, source_p->name,
190 target_p->name, parv[2]);
c127b45b 191 if(target_p->user->away)
212380e3 192 sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
c127b45b 193 target_p->name, target_p->user->away);
212380e3
AC
194 }
195 /* invite timestamp */
196 else if(parc > 3 && !EmptyString(parv[3]))
197 {
198 /* this should never be less than */
199 if(atol(parv[3]) > chptr->channelts)
3c7d6fcc 200 return;
212380e3
AC
201 }
202
203 if(MyConnect(target_p))
204 {
e0622d75
EK
205 hdata.chptr = chptr;
206 hdata.msptr = msptr;
207 hdata.client = source_p;
208 hdata.target = target_p;
209 hdata.approved = 0;
210
211 call_hook(invite_hook, &hdata);
212
213 if (hdata.approved)
214 {
215 if (hdata.error)
216 sendto_one_numeric(source_p, hdata.approved, "%s", hdata.error);
217 return;
218 }
219
890af0e7 220 add_reply_target(target_p, source_p);
55abcbb2
KB
221 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
222 source_p->name, source_p->username, source_p->host,
212380e3
AC
223 target_p->name, chptr->chname);
224
225 if(store_invite)
91ccda4f
EK
226 add_invite(chptr, target_p);
227 }
228 else if (target_p->from != client_p)
229 {
230 sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu",
231 chptr->chname, (unsigned long) chptr->channelts);
212380e3 232 }
212380e3
AC
233}
234
235/* add_invite()
236 *
237 * input - channel to add invite to, client to add
f88fd40f 238 * output - true if it is a new invite, else false
212380e3
AC
239 * side effects - client is added to invite list.
240 */
f88fd40f 241static bool
212380e3
AC
242add_invite(struct Channel *chptr, struct Client *who)
243{
5b96d9a6 244 rb_dlink_node *ptr;
212380e3
AC
245
246 /* already invited? */
5b96d9a6 247 RB_DLINK_FOREACH(ptr, who->user->invited.head)
212380e3
AC
248 {
249 if(ptr->data == chptr)
f88fd40f 250 return false;
212380e3
AC
251 }
252
253 /* ok, if their invite list is too long, remove the tail */
55abcbb2 254 if((int)rb_dlink_list_length(&who->user->invited) >=
212380e3
AC
255 ConfigChannel.max_chans_per_user)
256 {
257 ptr = who->user->invited.tail;
258 del_invite(ptr->data, who);
259 }
260
261 /* add user to channel invite list */
7018b86a 262 rb_dlinkAddAlloc(who, &chptr->invites);
212380e3
AC
263
264 /* add channel to user invite list */
7018b86a 265 rb_dlinkAddAlloc(chptr, &who->user->invited);
f88fd40f
AC
266
267 return true;
212380e3 268}