]>
Commit | Line | Data |
---|---|---|
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 | #include "s_newconf.h" | |
41 | ||
42 | static const char invite_desc[] = "Provides /invite"; | |
43 | ||
44 | static void m_invite(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
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 | static int can_invite_hook; | |
52 | static int invite_hook; | |
53 | ||
54 | mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL }; | |
55 | mapi_hlist_av1 invite_hlist[] = { | |
56 | { "can_invite", &can_invite_hook }, | |
57 | { "invite", &invite_hook }, | |
58 | { NULL, NULL } | |
59 | }; | |
60 | ||
61 | DECLARE_MODULE_AV2(invite, NULL, NULL, invite_clist, invite_hlist, NULL, NULL, NULL, invite_desc); | |
62 | ||
63 | static bool add_invite(struct Channel *, struct Client *); | |
64 | ||
65 | /* m_invite() | |
66 | * parv[1] - user to invite | |
67 | * parv[2] - channel name | |
68 | */ | |
69 | static void | |
70 | m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
71 | { | |
72 | struct Client *target_p; | |
73 | struct Channel *chptr; | |
74 | struct membership *msptr; | |
75 | int store_invite = 0; | |
76 | hook_data_channel_approval hdata = { 0 }; | |
77 | ||
78 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
79 | flood_endgrace(source_p); | |
80 | ||
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) | |
86 | { | |
87 | if(!MyClient(source_p) && IsDigit(parv[1][0])) | |
88 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
89 | "* :Target left IRC. Failed to invite to %s", | |
90 | parv[2]); | |
91 | else | |
92 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
93 | form_str(ERR_NOSUCHNICK), | |
94 | parv[1]); | |
95 | return; | |
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]); | |
103 | return; | |
104 | } | |
105 | ||
106 | /* Do not send local channel invites to users if they are not on the | |
107 | * same server as the person sending the INVITE message. | |
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); | |
113 | return; | |
114 | } | |
115 | ||
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]); | |
123 | return; | |
124 | } | |
125 | ||
126 | if((chptr = find_channel(parv[2])) == NULL) | |
127 | { | |
128 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
129 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
130 | return; | |
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]); | |
138 | return; | |
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]); | |
146 | return; | |
147 | } | |
148 | ||
149 | if (MyClient(source_p)) | |
150 | { | |
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) | |
159 | { | |
160 | if (hdata.error) | |
161 | sendto_one_numeric(source_p, hdata.approved, "%s", hdata.error); | |
162 | else | |
163 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
164 | me.name, source_p->name, parv[2]); | |
165 | ||
166 | return; | |
167 | } | |
168 | } | |
169 | ||
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) | |
176 | store_invite = 1; | |
177 | ||
178 | if(MyConnect(source_p)) | |
179 | { | |
180 | if (ConfigFileEntry.target_change && !IsOperGeneral(source_p) && | |
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); | |
186 | return; | |
187 | } | |
188 | sendto_one(source_p, form_str(RPL_INVITING), | |
189 | me.name, source_p->name, | |
190 | target_p->name, parv[2]); | |
191 | if(target_p->user->away) | |
192 | sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), | |
193 | target_p->name, target_p->user->away); | |
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) | |
200 | return; | |
201 | } | |
202 | ||
203 | if(MyConnect(target_p)) | |
204 | { | |
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 | ||
220 | add_reply_target(target_p, source_p); | |
221 | sendto_anywhere(target_p, source_p, "INVITE", ":%s", chptr->chname); | |
222 | ||
223 | if(store_invite) | |
224 | add_invite(chptr, target_p); | |
225 | } | |
226 | else if (target_p->from != client_p) | |
227 | { | |
228 | sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu", | |
229 | chptr->chname, (unsigned long) chptr->channelts); | |
230 | } | |
231 | } | |
232 | ||
233 | /* add_invite() | |
234 | * | |
235 | * input - channel to add invite to, client to add | |
236 | * output - true if it is a new invite, else false | |
237 | * side effects - client is added to invite list. | |
238 | */ | |
239 | static bool | |
240 | add_invite(struct Channel *chptr, struct Client *who) | |
241 | { | |
242 | rb_dlink_node *ptr; | |
243 | ||
244 | /* already invited? */ | |
245 | RB_DLINK_FOREACH(ptr, who->user->invited.head) | |
246 | { | |
247 | if(ptr->data == chptr) | |
248 | return false; | |
249 | } | |
250 | ||
251 | /* ok, if their invite list is too long, remove the tail */ | |
252 | if((int)rb_dlink_list_length(&who->user->invited) >= | |
253 | ConfigChannel.max_chans_per_user) | |
254 | { | |
255 | ptr = who->user->invited.tail; | |
256 | del_invite(ptr->data, who); | |
257 | } | |
258 | ||
259 | /* add user to channel invite list */ | |
260 | rb_dlinkAddAlloc(who, &chptr->invites); | |
261 | ||
262 | /* add channel to user invite list */ | |
263 | rb_dlinkAddAlloc(chptr, &who->user->invited); | |
264 | ||
265 | return true; | |
266 | } |