]> jfr.im git - solanum.git/blob - modules/m_invite.c
Merge pull request #279 from edk0/operhide
[solanum.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 #include "stdinc.h"
26 #include "channel.h"
27 #include "client.h"
28 #include "hash.h"
29 #include "match.h"
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"
39 #include "tgchange.h"
40
41 static const char invite_desc[] = "Provides facilities for invite and related notifications";
42
43 static void m_invite(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
44 static unsigned int CAP_INVITE_NOTIFY = 0;
45
46 struct Message invite_msgtab = {
47 "INVITE", 0, 0, 0, 0,
48 {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}}
49 };
50
51 mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL };
52
53 mapi_cap_list_av2 invite_cap_list[] = {
54 { MAPI_CAP_CLIENT, "invite-notify", NULL, &CAP_INVITE_NOTIFY },
55 { 0, NULL, NULL, NULL }
56 };
57
58 DECLARE_MODULE_AV2(invite, NULL, NULL, invite_clist, NULL, NULL, invite_cap_list, NULL, invite_desc);
59
60 static bool add_invite(struct Channel *, struct Client *);
61
62 /* m_invite()
63 * parv[1] - user to invite
64 * parv[2] - channel name
65 */
66 static void
67 m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
68 {
69 struct Client *target_p;
70 struct Channel *chptr;
71 struct membership *msptr;
72 int store_invite = 0;
73
74 if(MyClient(source_p) && !IsFloodDone(source_p))
75 flood_endgrace(source_p);
76
77 if(MyClient(source_p))
78 target_p = find_named_person(parv[1]);
79 else
80 target_p = find_person(parv[1]);
81 if(target_p == NULL)
82 {
83 if(!MyClient(source_p) && IsDigit(parv[1][0]))
84 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
85 "* :Target left IRC. Failed to invite to %s",
86 parv[2]);
87 else
88 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
89 form_str(ERR_NOSUCHNICK),
90 parv[1]);
91 return;
92 }
93
94 if(check_channel_name(parv[2]) == 0)
95 {
96 sendto_one_numeric(source_p, ERR_BADCHANNAME,
97 form_str(ERR_BADCHANNAME),
98 parv[2]);
99 return;
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;
110 }
111
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;
120 }
121
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;
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;
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;
143 }
144
145 /* unconditionally require ops, unless the channel is +g */
146 /* treat remote clients as chanops */
147 if(MyClient(source_p) && !is_chanop(msptr) &&
148 !(chptr->mode.mode & MODE_FREEINVITE))
149 {
150 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
151 me.name, source_p->name, parv[2]);
152 return;
153 }
154
155 /* store invites when they could affect the ability to join
156 * for +l/+j just check if the mode is set, this varies over time
157 */
158 if(chptr->mode.mode & MODE_INVITEONLY ||
159 (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) ||
160 chptr->mode.limit || chptr->mode.join_num)
161 store_invite = 1;
162
163 if(MyConnect(source_p))
164 {
165 if (ConfigFileEntry.target_change && !IsOper(source_p) &&
166 !find_allowing_channel(source_p, target_p) &&
167 !add_target(source_p, target_p))
168 {
169 sendto_one(source_p, form_str(ERR_TARGCHANGE),
170 me.name, source_p->name, target_p->name);
171 return;
172 }
173 sendto_one(source_p, form_str(RPL_INVITING),
174 me.name, source_p->name,
175 target_p->name, parv[2]);
176 if(target_p->user->away)
177 sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
178 target_p->name, target_p->user->away);
179 }
180 /* invite timestamp */
181 else if(parc > 3 && !EmptyString(parv[3]))
182 {
183 /* this should never be less than */
184 if(atol(parv[3]) > chptr->channelts)
185 return;
186 }
187
188 if(MyConnect(target_p))
189 {
190 if(!IsOper(source_p) && (IsSetCallerId(target_p) ||
191 (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) &&
192 !accept_message(source_p, target_p))
193 {
194 if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])
195 {
196 sendto_one_numeric(source_p, ERR_NONONREG,
197 form_str(ERR_NONONREG),
198 target_p->name);
199 return;
200 }
201 else
202 {
203 /* instead of sending RPL_UMODEGMSG,
204 * just let the invite through
205 */
206 if((target_p->localClient->last_caller_id_time +
207 ConfigFileEntry.caller_id_wait) >= rb_current_time())
208 {
209 sendto_one_numeric(source_p, ERR_TARGUMODEG,
210 form_str(ERR_TARGUMODEG),
211 target_p->name);
212 return;
213 }
214 target_p->localClient->last_caller_id_time = rb_current_time();
215 }
216 }
217 add_reply_target(target_p, source_p);
218 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
219 source_p->name, source_p->username, source_p->host,
220 target_p->name, chptr->chname);
221
222 if(store_invite)
223 {
224 if (!add_invite(chptr, target_p))
225 return;
226
227 sendto_channel_local_with_capability(source_p, CHFL_CHANOP, 0, CAP_INVITE_NOTIFY, chptr,
228 ":%s NOTICE %s :%s is inviting %s to %s.",
229 me.name, chptr->chname, source_p->name, target_p->name, chptr->chname);
230 sendto_channel_local_with_capability(source_p, CHFL_CHANOP, CAP_INVITE_NOTIFY, 0, chptr,
231 ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
232 source_p->host, target_p->name, chptr->chname);
233 }
234 }
235
236 sendto_server(source_p, chptr, CAP_TS6, 0, ":%s INVITE %s %s %lu",
237 use_id(source_p), use_id(target_p),
238 chptr->chname, (unsigned long) chptr->channelts);
239 }
240
241 /* add_invite()
242 *
243 * input - channel to add invite to, client to add
244 * output - true if it is a new invite, else false
245 * side effects - client is added to invite list.
246 */
247 static bool
248 add_invite(struct Channel *chptr, struct Client *who)
249 {
250 rb_dlink_node *ptr;
251
252 /* already invited? */
253 RB_DLINK_FOREACH(ptr, who->user->invited.head)
254 {
255 if(ptr->data == chptr)
256 return false;
257 }
258
259 /* ok, if their invite list is too long, remove the tail */
260 if((int)rb_dlink_list_length(&who->user->invited) >=
261 ConfigChannel.max_chans_per_user)
262 {
263 ptr = who->user->invited.tail;
264 del_invite(ptr->data, who);
265 }
266
267 /* add user to channel invite list */
268 rb_dlinkAddAlloc(who, &chptr->invites);
269
270 /* add channel to user invite list */
271 rb_dlinkAddAlloc(chptr, &who->user->invited);
272
273 return true;
274 }