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