]>
Commit | Line | Data |
---|---|---|
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 "common.h" |
27 | #include "channel.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" | |
4562c604 | 30 | #include "match.h" |
212380e3 AC |
31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "send.h" | |
34 | #include "s_conf.h" | |
35 | #include "s_serv.h" | |
36 | #include "msg.h" | |
37 | #include "parse.h" | |
38 | #include "modules.h" | |
39 | #include "packet.h" | |
890af0e7 | 40 | #include "tgchange.h" |
212380e3 | 41 | |
eeabf33a EM |
42 | static const char invite_desc[] = "Provides facilities for invite and related notifications"; |
43 | ||
3c7d6fcc | 44 | static void m_invite(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
4c83e476 | 45 | static unsigned int CAP_INVITE_NOTIFY = 0; |
212380e3 AC |
46 | |
47 | struct Message invite_msgtab = { | |
7baa37a9 | 48 | "INVITE", 0, 0, 0, 0, |
212380e3 AC |
49 | {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}} |
50 | }; | |
4c83e476 | 51 | |
df1f1212 | 52 | mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL }; |
4c83e476 | 53 | |
df1f1212 EM |
54 | mapi_cap_list_av2 invite_cap_list[] = { |
55 | { MAPI_CAP_CLIENT, "invite-notify", NULL, &CAP_INVITE_NOTIFY }, | |
56 | { 0, NULL, NULL, NULL } | |
57 | }; | |
4c83e476 | 58 | |
df1f1212 | 59 | DECLARE_MODULE_AV2(invite, NULL, NULL, invite_clist, NULL, NULL, invite_cap_list, NULL, invite_desc); |
212380e3 AC |
60 | |
61 | static void add_invite(struct Channel *, struct Client *); | |
62 | ||
63 | /* m_invite() | |
212380e3 AC |
64 | * parv[1] - user to invite |
65 | * parv[2] - channel name | |
66 | */ | |
3c7d6fcc | 67 | static void |
428ca87b | 68 | m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
69 | { |
70 | struct Client *target_p; | |
71 | struct Channel *chptr; | |
72 | struct membership *msptr; | |
73 | int store_invite = 0; | |
74 | ||
75 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
76 | flood_endgrace(source_p); | |
77 | ||
8c39f0bf JT |
78 | if(MyClient(source_p)) |
79 | target_p = find_named_person(parv[1]); | |
80 | else | |
81 | target_p = find_person(parv[1]); | |
82 | if(target_p == NULL) | |
212380e3 | 83 | { |
0482ebf7 | 84 | if(!MyClient(source_p) && IsDigit(parv[1][0])) |
55abcbb2 KB |
85 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, |
86 | "* :Target left IRC. Failed to invite to %s", | |
0482ebf7 JT |
87 | parv[2]); |
88 | else | |
55abcbb2 KB |
89 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, |
90 | form_str(ERR_NOSUCHNICK), | |
0482ebf7 | 91 | parv[1]); |
3c7d6fcc | 92 | return; |
212380e3 AC |
93 | } |
94 | ||
95 | if(check_channel_name(parv[2]) == 0) | |
96 | { | |
97 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
98 | form_str(ERR_BADCHANNAME), | |
99 | parv[2]); | |
3c7d6fcc | 100 | return; |
212380e3 AC |
101 | } |
102 | ||
212380e3 | 103 | /* Do not send local channel invites to users if they are not on the |
55abcbb2 | 104 | * same server as the person sending the INVITE message. |
212380e3 AC |
105 | */ |
106 | if(parv[2][0] == '&' && !MyConnect(target_p)) | |
107 | { | |
108 | sendto_one(source_p, form_str(ERR_USERNOTONSERV), | |
109 | me.name, source_p->name, target_p->name); | |
3c7d6fcc | 110 | return; |
212380e3 AC |
111 | } |
112 | ||
18fc47e6 JT |
113 | if(((MyConnect(source_p) && !IsExemptResv(source_p)) || |
114 | (MyConnect(target_p) && !IsExemptResv(target_p))) && | |
115 | hash_find_resv(parv[2])) | |
116 | { | |
117 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
118 | form_str(ERR_BADCHANNAME), | |
119 | parv[2]); | |
3c7d6fcc | 120 | return; |
18fc47e6 JT |
121 | } |
122 | ||
212380e3 AC |
123 | if((chptr = find_channel(parv[2])) == NULL) |
124 | { | |
125 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
126 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 127 | return; |
212380e3 AC |
128 | } |
129 | ||
130 | msptr = find_channel_membership(chptr, source_p); | |
131 | if(MyClient(source_p) && (msptr == NULL)) | |
132 | { | |
133 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
134 | form_str(ERR_NOTONCHANNEL), parv[2]); | |
3c7d6fcc | 135 | return; |
212380e3 AC |
136 | } |
137 | ||
138 | if(IsMember(target_p, chptr)) | |
139 | { | |
140 | sendto_one_numeric(source_p, ERR_USERONCHANNEL, | |
141 | form_str(ERR_USERONCHANNEL), | |
142 | target_p->name, parv[2]); | |
3c7d6fcc | 143 | return; |
212380e3 AC |
144 | } |
145 | ||
307328bb JT |
146 | /* unconditionally require ops, unless the channel is +g */ |
147 | /* treat remote clients as chanops */ | |
148 | if(MyClient(source_p) && !is_chanop(msptr) && | |
149 | !(chptr->mode.mode & MODE_FREEINVITE)) | |
212380e3 | 150 | { |
307328bb JT |
151 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
152 | me.name, source_p->name, parv[2]); | |
3c7d6fcc | 153 | return; |
212380e3 AC |
154 | } |
155 | ||
1ebf4db4 JT |
156 | /* store invites when they could affect the ability to join |
157 | * for +l/+j just check if the mode is set, this varies over time | |
158 | */ | |
159 | if(chptr->mode.mode & MODE_INVITEONLY || | |
160 | (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) || | |
161 | chptr->mode.limit || chptr->mode.join_num) | |
307328bb JT |
162 | store_invite = 1; |
163 | ||
212380e3 AC |
164 | if(MyConnect(source_p)) |
165 | { | |
890af0e7 JT |
166 | if (ConfigFileEntry.target_change && !IsOper(source_p) && |
167 | !find_allowing_channel(source_p, target_p) && | |
168 | !add_target(source_p, target_p)) | |
169 | { | |
170 | sendto_one(source_p, form_str(ERR_TARGCHANGE), | |
171 | me.name, source_p->name, target_p->name); | |
3c7d6fcc | 172 | return; |
890af0e7 | 173 | } |
55abcbb2 | 174 | sendto_one(source_p, form_str(RPL_INVITING), |
212380e3 AC |
175 | me.name, source_p->name, |
176 | target_p->name, parv[2]); | |
c127b45b | 177 | if(target_p->user->away) |
212380e3 | 178 | sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), |
c127b45b | 179 | target_p->name, target_p->user->away); |
212380e3 AC |
180 | } |
181 | /* invite timestamp */ | |
182 | else if(parc > 3 && !EmptyString(parv[3])) | |
183 | { | |
184 | /* this should never be less than */ | |
185 | if(atol(parv[3]) > chptr->channelts) | |
3c7d6fcc | 186 | return; |
212380e3 AC |
187 | } |
188 | ||
189 | if(MyConnect(target_p)) | |
190 | { | |
0cce7774 JT |
191 | if(!IsOper(source_p) && (IsSetCallerId(target_p) || |
192 | (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && | |
193 | !accept_message(source_p, target_p)) | |
194 | { | |
195 | if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) | |
196 | { | |
197 | sendto_one_numeric(source_p, ERR_NONONREG, | |
198 | form_str(ERR_NONONREG), | |
199 | target_p->name); | |
3c7d6fcc | 200 | return; |
0cce7774 JT |
201 | } |
202 | else | |
203 | { | |
204 | /* instead of sending RPL_UMODEGMSG, | |
205 | * just let the invite through | |
206 | */ | |
207 | if((target_p->localClient->last_caller_id_time + | |
208 | ConfigFileEntry.caller_id_wait) >= rb_current_time()) | |
209 | { | |
210 | sendto_one_numeric(source_p, ERR_TARGUMODEG, | |
211 | form_str(ERR_TARGUMODEG), | |
212 | target_p->name); | |
3c7d6fcc | 213 | return; |
0cce7774 JT |
214 | } |
215 | target_p->localClient->last_caller_id_time = rb_current_time(); | |
216 | } | |
217 | } | |
890af0e7 | 218 | add_reply_target(target_p, source_p); |
55abcbb2 KB |
219 | sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", |
220 | source_p->name, source_p->username, source_p->host, | |
212380e3 AC |
221 | target_p->name, chptr->chname); |
222 | ||
223 | if(store_invite) | |
4c83e476 | 224 | { |
212380e3 | 225 | add_invite(chptr, target_p); |
4c83e476 AC |
226 | |
227 | sendto_channel_local_with_capability(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(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 | } | |
212380e3 | 234 | } |
d058096a AC |
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); | |
212380e3 AC |
239 | } |
240 | ||
241 | /* add_invite() | |
242 | * | |
243 | * input - channel to add invite to, client to add | |
244 | * output - | |
245 | * side effects - client is added to invite list. | |
246 | */ | |
247 | static void | |
248 | add_invite(struct Channel *chptr, struct Client *who) | |
249 | { | |
5b96d9a6 | 250 | rb_dlink_node *ptr; |
212380e3 AC |
251 | |
252 | /* already invited? */ | |
5b96d9a6 | 253 | RB_DLINK_FOREACH(ptr, who->user->invited.head) |
212380e3 AC |
254 | { |
255 | if(ptr->data == chptr) | |
256 | return; | |
257 | } | |
258 | ||
259 | /* ok, if their invite list is too long, remove the tail */ | |
55abcbb2 | 260 | if((int)rb_dlink_list_length(&who->user->invited) >= |
212380e3 AC |
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 */ | |
7018b86a | 268 | rb_dlinkAddAlloc(who, &chptr->invites); |
212380e3 AC |
269 | |
270 | /* add channel to user invite list */ | |
7018b86a | 271 | rb_dlinkAddAlloc(chptr, &who->user->invited); |
212380e3 | 272 | } |