2 * ircd-ratbox: A slightly useful ircd.
3 * m_invite.c: Invites the user to join a channel.
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
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.
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.
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
24 * $Id: m_invite.c 3438 2007-05-06 14:46:45Z jilles $
44 static int m_invite(struct Client
*, struct Client
*, int, const char **);
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}}
50 mapi_clist_av1 invite_clist
[] = { &invite_msgtab
, NULL
};
51 DECLARE_MODULE_AV1(invite
, NULL
, NULL
, invite_clist
, NULL
, NULL
, "$Revision: 3438 $");
53 static void add_invite(struct Channel
*, struct Client
*);
56 * parv[1] - user to invite
57 * parv[2] - channel name
60 m_invite(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
62 struct Client
*target_p
;
63 struct Channel
*chptr
;
64 struct membership
*msptr
;
67 if(MyClient(source_p
) && !IsFloodDone(source_p
))
68 flood_endgrace(source_p
);
70 if(MyClient(source_p
))
71 target_p
= find_named_person(parv
[1]);
73 target_p
= find_person(parv
[1]);
76 if(!MyClient(source_p
) && IsDigit(parv
[1][0]))
77 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
78 "* :Target left IRC. Failed to invite to %s",
81 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
82 form_str(ERR_NOSUCHNICK
),
87 if(check_channel_name(parv
[2]) == 0)
89 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
90 form_str(ERR_BADCHANNAME
),
95 if(!IsChannelName(parv
[2]))
97 if(MyClient(source_p
))
98 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
99 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
103 /* Do not send local channel invites to users if they are not on the
104 * same server as the person sending the INVITE message.
106 if(parv
[2][0] == '&' && !MyConnect(target_p
))
108 sendto_one(source_p
, form_str(ERR_USERNOTONSERV
),
109 me
.name
, source_p
->name
, target_p
->name
);
113 if(((MyConnect(source_p
) && !IsExemptResv(source_p
)) ||
114 (MyConnect(target_p
) && !IsExemptResv(target_p
))) &&
115 hash_find_resv(parv
[2]))
117 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
118 form_str(ERR_BADCHANNAME
),
123 if((chptr
= find_channel(parv
[2])) == NULL
)
125 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
126 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
130 msptr
= find_channel_membership(chptr
, source_p
);
131 if(MyClient(source_p
) && (msptr
== NULL
))
133 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
134 form_str(ERR_NOTONCHANNEL
), parv
[2]);
138 if(IsMember(target_p
, chptr
))
140 sendto_one_numeric(source_p
, ERR_USERONCHANNEL
,
141 form_str(ERR_USERONCHANNEL
),
142 target_p
->name
, parv
[2]);
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
))
151 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
152 me
.name
, source_p
->name
, parv
[2]);
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
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
)
164 if(MyConnect(source_p
))
166 if (ConfigFileEntry
.target_change
&& !IsOper(source_p
) &&
167 !find_allowing_channel(source_p
, target_p
) &&
168 !add_target(source_p
, target_p
))
170 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
171 me
.name
, source_p
->name
, target_p
->name
);
174 sendto_one(source_p
, form_str(RPL_INVITING
),
175 me
.name
, source_p
->name
,
176 target_p
->name
, parv
[2]);
177 if(target_p
->user
->away
)
178 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
179 target_p
->name
, target_p
->user
->away
);
181 /* invite timestamp */
182 else if(parc
> 3 && !EmptyString(parv
[3]))
184 /* this should never be less than */
185 if(atol(parv
[3]) > chptr
->channelts
)
189 if(MyConnect(target_p
))
191 if(!IsOper(source_p
) && (IsSetCallerId(target_p
) ||
192 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])) &&
193 !accept_message(source_p
, target_p
))
195 if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
197 sendto_one_numeric(source_p
, ERR_NONONREG
,
198 form_str(ERR_NONONREG
),
204 /* instead of sending RPL_UMODEGMSG,
205 * just let the invite through
207 if((target_p
->localClient
->last_caller_id_time
+
208 ConfigFileEntry
.caller_id_wait
) >= rb_current_time())
210 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
211 form_str(ERR_TARGUMODEG
),
215 target_p
->localClient
->last_caller_id_time
= rb_current_time();
218 add_reply_target(target_p
, source_p
);
219 sendto_one(target_p
, ":%s!%s@%s INVITE %s :%s",
220 source_p
->name
, source_p
->username
, source_p
->host
,
221 target_p
->name
, chptr
->chname
);
224 add_invite(chptr
, target_p
);
226 else if(target_p
->from
!= client_p
)
228 sendto_one_prefix(target_p
, source_p
, "INVITE", "%s %lu",
229 chptr
->chname
, (unsigned long) chptr
->channelts
);
237 * input - channel to add invite to, client to add
239 * side effects - client is added to invite list.
242 add_invite(struct Channel
*chptr
, struct Client
*who
)
246 /* already invited? */
247 RB_DLINK_FOREACH(ptr
, who
->user
->invited
.head
)
249 if(ptr
->data
== chptr
)
253 /* ok, if their invite list is too long, remove the tail */
254 if((int)rb_dlink_list_length(&who
->user
->invited
) >=
255 ConfigChannel
.max_chans_per_user
)
257 ptr
= who
->user
->invited
.tail
;
258 del_invite(ptr
->data
, who
);
261 /* add user to channel invite list */
262 rb_dlinkAddAlloc(who
, &chptr
->invites
);
264 /* add channel to user invite list */
265 rb_dlinkAddAlloc(chptr
, &who
->user
->invited
);