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