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 $
43 static int m_invite(struct Client
*, struct Client
*, int, const char **);
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}}
49 mapi_clist_av1 invite_clist
[] = { &invite_msgtab
, NULL
};
50 DECLARE_MODULE_AV1(invite
, NULL
, NULL
, invite_clist
, NULL
, NULL
, "$Revision: 3438 $");
52 static void add_invite(struct Channel
*, struct Client
*);
55 * parv[1] - user to invite
56 * parv[2] - channel name
59 m_invite(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
61 struct Client
*target_p
;
62 struct Channel
*chptr
;
63 struct membership
*msptr
;
66 if(MyClient(source_p
) && !IsFloodDone(source_p
))
67 flood_endgrace(source_p
);
69 if(MyClient(source_p
))
70 target_p
= find_named_person(parv
[1]);
72 target_p
= find_person(parv
[1]);
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",
80 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
81 form_str(ERR_NOSUCHNICK
),
86 if(check_channel_name(parv
[2]) == 0)
88 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
89 form_str(ERR_BADCHANNAME
),
94 if(!IsChannelName(parv
[2]))
96 if(MyClient(source_p
))
97 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
98 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
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.
105 if(parv
[2][0] == '&' && !MyConnect(target_p
))
107 sendto_one(source_p
, form_str(ERR_USERNOTONSERV
),
108 me
.name
, source_p
->name
, target_p
->name
);
112 if(((MyConnect(source_p
) && !IsExemptResv(source_p
)) ||
113 (MyConnect(target_p
) && !IsExemptResv(target_p
))) &&
114 hash_find_resv(parv
[2]))
116 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
117 form_str(ERR_BADCHANNAME
),
122 if((chptr
= find_channel(parv
[2])) == NULL
)
124 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
125 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
129 msptr
= find_channel_membership(chptr
, source_p
);
130 if(MyClient(source_p
) && (msptr
== NULL
))
132 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
133 form_str(ERR_NOTONCHANNEL
), parv
[2]);
137 if(IsMember(target_p
, chptr
))
139 sendto_one_numeric(source_p
, ERR_USERONCHANNEL
,
140 form_str(ERR_USERONCHANNEL
),
141 target_p
->name
, parv
[2]);
145 /* unconditionally require ops, unless the channel is +g */
146 /* treat remote clients as chanops */
147 if(MyClient(source_p
) && !is_chanop(msptr
) &&
148 !(chptr
->mode
.mode
& MODE_FREEINVITE
))
150 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
151 me
.name
, source_p
->name
, parv
[2]);
155 /* store invites when they could affect the ability to join
156 * for +l/+j just check if the mode is set, this varies over time
158 if(chptr
->mode
.mode
& MODE_INVITEONLY
||
159 (chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(target_p
->user
->suser
)) ||
160 chptr
->mode
.limit
|| chptr
->mode
.join_num
)
163 if(MyConnect(source_p
))
165 sendto_one(source_p
, form_str(RPL_INVITING
),
166 me
.name
, source_p
->name
,
167 target_p
->name
, parv
[2]);
168 if(target_p
->user
->away
)
169 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
170 target_p
->name
, target_p
->user
->away
);
172 /* invite timestamp */
173 else if(parc
> 3 && !EmptyString(parv
[3]))
175 /* this should never be less than */
176 if(atol(parv
[3]) > chptr
->channelts
)
180 if(MyConnect(target_p
))
182 sendto_one(target_p
, ":%s!%s@%s INVITE %s :%s",
183 source_p
->name
, source_p
->username
, source_p
->host
,
184 target_p
->name
, chptr
->chname
);
187 add_invite(chptr
, target_p
);
189 else if(target_p
->from
!= client_p
)
191 sendto_one_prefix(target_p
, source_p
, "INVITE", "%s %lu",
192 chptr
->chname
, (unsigned long) chptr
->channelts
);
200 * input - channel to add invite to, client to add
202 * side effects - client is added to invite list.
205 add_invite(struct Channel
*chptr
, struct Client
*who
)
209 /* already invited? */
210 RB_DLINK_FOREACH(ptr
, who
->user
->invited
.head
)
212 if(ptr
->data
== chptr
)
216 /* ok, if their invite list is too long, remove the tail */
217 if((int)rb_dlink_list_length(&who
->user
->invited
) >=
218 ConfigChannel
.max_chans_per_user
)
220 ptr
= who
->user
->invited
.tail
;
221 del_invite(ptr
->data
, who
);
224 /* add user to channel invite list */
225 rb_dlinkAddAlloc(who
, &chptr
->invites
);
227 /* add channel to user invite list */
228 rb_dlinkAddAlloc(chptr
, &who
->user
->invited
);