]>
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 | * $Id: m_invite.c 3438 2007-05-06 14:46:45Z jilles $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "tools.h" | |
29 | #include "common.h" | |
30 | #include "channel.h" | |
31 | #include "client.h" | |
32 | #include "hash.h" | |
33 | #include "irc_string.h" | |
34 | #include "ircd.h" | |
35 | #include "numeric.h" | |
36 | #include "send.h" | |
37 | #include "s_conf.h" | |
38 | #include "s_serv.h" | |
39 | #include "msg.h" | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
42 | #include "packet.h" | |
43 | ||
44 | static int m_invite(struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message invite_msgtab = { | |
47 | "INVITE", 0, 0, 0, MFLG_SLOW, | |
48 | {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}} | |
49 | }; | |
50 | mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL }; | |
51 | DECLARE_MODULE_AV1(invite, NULL, NULL, invite_clist, NULL, NULL, "$Revision: 3438 $"); | |
52 | ||
53 | static void add_invite(struct Channel *, struct Client *); | |
54 | ||
55 | /* m_invite() | |
56 | * parv[0] - sender prefix | |
57 | * parv[1] - user to invite | |
58 | * parv[2] - channel name | |
59 | */ | |
60 | static int | |
61 | m_invite(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
62 | { | |
63 | struct Client *target_p; | |
64 | struct Channel *chptr; | |
65 | struct membership *msptr; | |
66 | int store_invite = 0; | |
67 | ||
68 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
69 | flood_endgrace(source_p); | |
70 | ||
71 | if(MyClient(source_p)) | |
72 | target_p = find_named_person(parv[1]); | |
73 | else | |
74 | target_p = find_person(parv[1]); | |
75 | if(target_p == NULL) | |
76 | { | |
77 | if(!MyClient(source_p) && IsDigit(parv[1][0])) | |
78 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
79 | "* :Target left IRC. Failed to invite to %s", | |
80 | parv[2]); | |
81 | else | |
82 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
83 | form_str(ERR_NOSUCHNICK), | |
84 | parv[1]); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | if(check_channel_name(parv[2]) == 0) | |
89 | { | |
90 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
91 | form_str(ERR_BADCHANNAME), | |
92 | parv[2]); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | if(!IsChannelName(parv[2])) | |
97 | { | |
98 | if(MyClient(source_p)) | |
99 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
100 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | /* Do not send local channel invites to users if they are not on the | |
105 | * same server as the person sending the INVITE message. | |
106 | */ | |
107 | if(parv[2][0] == '&' && !MyConnect(target_p)) | |
108 | { | |
109 | sendto_one(source_p, form_str(ERR_USERNOTONSERV), | |
110 | me.name, source_p->name, target_p->name); | |
111 | return 0; | |
112 | } | |
113 | ||
114 | if((chptr = find_channel(parv[2])) == NULL) | |
115 | { | |
116 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
117 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | msptr = find_channel_membership(chptr, source_p); | |
122 | if(MyClient(source_p) && (msptr == NULL)) | |
123 | { | |
124 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
125 | form_str(ERR_NOTONCHANNEL), parv[2]); | |
126 | return 0; | |
127 | } | |
128 | ||
129 | if(IsMember(target_p, chptr)) | |
130 | { | |
131 | sendto_one_numeric(source_p, ERR_USERONCHANNEL, | |
132 | form_str(ERR_USERONCHANNEL), | |
133 | target_p->name, parv[2]); | |
134 | return 0; | |
135 | } | |
136 | ||
137 | /* unconditionally require ops, unless the channel is +g */ | |
138 | /* treat remote clients as chanops */ | |
139 | if(MyClient(source_p) && !is_chanop(msptr) && | |
140 | !(chptr->mode.mode & MODE_FREEINVITE)) | |
141 | { | |
142 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
143 | me.name, source_p->name, parv[2]); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | /* store invites when they could affect the ability to join | |
148 | * for +l/+j just check if the mode is set, this varies over time | |
149 | */ | |
150 | if(chptr->mode.mode & MODE_INVITEONLY || | |
151 | (chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) || | |
152 | chptr->mode.limit || chptr->mode.join_num) | |
153 | store_invite = 1; | |
154 | ||
155 | if(MyConnect(source_p)) | |
156 | { | |
157 | sendto_one(source_p, form_str(RPL_INVITING), | |
158 | me.name, source_p->name, | |
159 | target_p->name, parv[2]); | |
160 | if(target_p->user->away) | |
161 | sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), | |
162 | target_p->name, target_p->user->away); | |
163 | } | |
164 | /* invite timestamp */ | |
165 | else if(parc > 3 && !EmptyString(parv[3])) | |
166 | { | |
167 | /* this should never be less than */ | |
168 | if(atol(parv[3]) > chptr->channelts) | |
169 | return 0; | |
170 | } | |
171 | ||
172 | if(MyConnect(target_p)) | |
173 | { | |
174 | sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", | |
175 | source_p->name, source_p->username, source_p->host, | |
176 | target_p->name, chptr->chname); | |
177 | ||
178 | if(store_invite) | |
179 | add_invite(chptr, target_p); | |
180 | } | |
181 | else if(target_p->from != client_p) | |
182 | { | |
183 | sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu", | |
184 | chptr->chname, (unsigned long) chptr->channelts); | |
185 | } | |
186 | ||
187 | return 0; | |
188 | } | |
189 | ||
190 | /* add_invite() | |
191 | * | |
192 | * input - channel to add invite to, client to add | |
193 | * output - | |
194 | * side effects - client is added to invite list. | |
195 | */ | |
196 | static void | |
197 | add_invite(struct Channel *chptr, struct Client *who) | |
198 | { | |
199 | rb_dlink_node *ptr; | |
200 | ||
201 | /* already invited? */ | |
202 | RB_DLINK_FOREACH(ptr, who->user->invited.head) | |
203 | { | |
204 | if(ptr->data == chptr) | |
205 | return; | |
206 | } | |
207 | ||
208 | /* ok, if their invite list is too long, remove the tail */ | |
209 | if((int)rb_dlink_list_length(&who->user->invited) >= | |
210 | ConfigChannel.max_chans_per_user) | |
211 | { | |
212 | ptr = who->user->invited.tail; | |
213 | del_invite(ptr->data, who); | |
214 | } | |
215 | ||
216 | /* add user to channel invite list */ | |
217 | dlinkAddAlloc(who, &chptr->invites); | |
218 | ||
219 | /* add channel to user invite list */ | |
220 | dlinkAddAlloc(chptr, &who->user->invited); | |
221 | } | |
222 | ||
223 |