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
44 struct module_modes ModuleModes
;
46 static int m_invite(struct Client
*, struct Client
*, int, const char **);
48 struct Message invite_msgtab
= {
49 "INVITE", 0, 0, 0, MFLG_SLOW
,
50 {mg_unreg
, {m_invite
, 3}, {m_invite
, 3}, mg_ignore
, mg_ignore
, {m_invite
, 3}}
52 mapi_clist_av1 invite_clist
[] = { &invite_msgtab
, NULL
};
53 DECLARE_MODULE_AV1(invite
, NULL
, NULL
, invite_clist
, NULL
, NULL
, "$Revision: 3438 $");
55 static void add_invite(struct Channel
*, struct Client
*);
58 * parv[1] - user to invite
59 * parv[2] - channel name
62 m_invite(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
64 struct Client
*target_p
;
65 struct Channel
*chptr
;
66 struct membership
*msptr
;
69 if(MyClient(source_p
) && !IsFloodDone(source_p
))
70 flood_endgrace(source_p
);
72 if(MyClient(source_p
))
73 target_p
= find_named_person(parv
[1]);
75 target_p
= find_person(parv
[1]);
78 if(!MyClient(source_p
) && IsDigit(parv
[1][0]))
79 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
80 "* :Target left IRC. Failed to invite to %s",
83 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
84 form_str(ERR_NOSUCHNICK
),
89 if(check_channel_name(parv
[2]) == 0)
91 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
92 form_str(ERR_BADCHANNAME
),
97 if(!IsChannelName(parv
[2]))
99 if(MyClient(source_p
))
100 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
101 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
105 /* Do not send local channel invites to users if they are not on the
106 * same server as the person sending the INVITE message.
108 if(parv
[2][0] == '&' && !MyConnect(target_p
))
110 sendto_one(source_p
, form_str(ERR_USERNOTONSERV
),
111 me
.name
, source_p
->name
, target_p
->name
);
115 if(((MyConnect(source_p
) && !IsExemptResv(source_p
)) ||
116 (MyConnect(target_p
) && !IsExemptResv(target_p
))) &&
117 hash_find_resv(parv
[2]))
119 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
120 form_str(ERR_BADCHANNAME
),
125 if((chptr
= find_channel(parv
[2])) == NULL
)
127 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
128 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
132 msptr
= find_channel_membership(chptr
, source_p
);
133 if(MyClient(source_p
) && (msptr
== NULL
))
135 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
136 form_str(ERR_NOTONCHANNEL
), parv
[2]);
140 if(IsMember(target_p
, chptr
))
142 sendto_one_numeric(source_p
, ERR_USERONCHANNEL
,
143 form_str(ERR_USERONCHANNEL
),
144 target_p
->name
, parv
[2]);
148 /* unconditionally require ops, unless the channel is +g */
149 /* treat remote clients as chanops */
150 if(MyClient(source_p
) && !is_any_op(msptr
) &&
151 !(chptr
->mode
.mode
& ModuleModes
.MODE_FREEINVITE
))
153 if(IsOverride(source_p
))
155 sendto_wallops_flags(UMODE_WALLOP
, &me
,
156 "%s is overriding INVITE [%s] on [%s]",
157 get_oper_name(source_p
), target_p
->name
, chptr
->chname
);
158 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
159 ":%s WALLOPS :%s is overriding INVITE [%s] on [%s]",
160 me
.name
, get_oper_name(source_p
), target_p
->name
, chptr
->chname
);
164 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
165 me
.name
, source_p
->name
, parv
[2]);
170 if (IsSetNoInvite(target_p
))
172 sendto_one_numeric(source_p
, ERR_NOINVITE
,
173 form_str(ERR_NOINVITE
),
178 /* store invites when they could affect the ability to join
179 * for +l/+j just check if the mode is set, this varies over time
181 if(chptr
->mode
.mode
& MODE_INVITEONLY
||
182 (chptr
->mode
.mode
& ModuleModes
.MODE_REGONLY
&& EmptyString(target_p
->user
->suser
)) ||
183 chptr
->mode
.limit
|| chptr
->mode
.join_num
)
186 if(MyConnect(source_p
))
188 if (ConfigFileEntry
.target_change
&& !IsOper(source_p
) &&
189 !find_allowing_channel(source_p
, target_p
) &&
190 !add_target(source_p
, target_p
))
192 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
193 me
.name
, source_p
->name
, target_p
->name
);
196 sendto_one(source_p
, form_str(RPL_INVITING
),
197 me
.name
, source_p
->name
,
198 target_p
->name
, parv
[2]);
199 if(target_p
->user
->away
)
200 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
201 target_p
->name
, target_p
->user
->away
);
203 /* invite timestamp */
204 else if(parc
> 3 && !EmptyString(parv
[3]))
206 /* this should never be less than */
207 if(atol(parv
[3]) > chptr
->channelts
)
211 if(MyConnect(target_p
))
213 if(!IsOper(source_p
) && (IsSetCallerId(target_p
) ||
214 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])) &&
215 !accept_message(source_p
, target_p
))
217 if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
219 sendto_one_numeric(source_p
, ERR_NONONREG
,
220 form_str(ERR_NONONREG
),
226 /* instead of sending RPL_UMODEGMSG,
227 * just let the invite through
229 if((target_p
->localClient
->last_caller_id_time
+
230 ConfigFileEntry
.caller_id_wait
) >= rb_current_time())
232 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
233 form_str(ERR_TARGUMODEG
),
237 target_p
->localClient
->last_caller_id_time
= rb_current_time();
240 add_reply_target(target_p
, source_p
);
241 sendto_one(target_p
, ":%s!%s@%s INVITE %s :%s",
242 source_p
->name
, source_p
->username
, source_p
->host
,
243 target_p
->name
, chptr
->chname
);
246 add_invite(chptr
, target_p
);
248 else if(target_p
->from
!= client_p
)
250 sendto_one_prefix(target_p
, source_p
, "INVITE", "%s %lu",
251 chptr
->chname
, (unsigned long) chptr
->channelts
);
259 * input - channel to add invite to, client to add
261 * side effects - client is added to invite list.
264 add_invite(struct Channel
*chptr
, struct Client
*who
)
268 /* already invited? */
269 RB_DLINK_FOREACH(ptr
, who
->user
->invited
.head
)
271 if(ptr
->data
== chptr
)
275 /* ok, if their invite list is too long, remove the tail */
276 if((int)rb_dlink_list_length(&who
->user
->invited
) >=
277 ConfigChannel
.max_chans_per_user
)
279 ptr
= who
->user
->invited
.tail
;
280 del_invite(ptr
->data
, who
);
283 /* add user to channel invite list */
284 rb_dlinkAddAlloc(who
, &chptr
->invites
);
286 /* add channel to user invite list */
287 rb_dlinkAddAlloc(chptr
, &who
->user
->invited
);