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
40 #include "s_newconf.h"
42 static const char invite_desc
[] = "Provides /invite";
44 static void m_invite(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
46 struct Message invite_msgtab
= {
48 {mg_unreg
, {m_invite
, 3}, {m_invite
, 3}, mg_ignore
, mg_ignore
, {m_invite
, 3}}
51 static int can_invite_hook
;
52 static int invite_hook
;
54 mapi_clist_av1 invite_clist
[] = { &invite_msgtab
, NULL
};
55 mapi_hlist_av1 invite_hlist
[] = {
56 { "can_invite", &can_invite_hook
},
57 { "invite", &invite_hook
},
61 DECLARE_MODULE_AV2(invite
, NULL
, NULL
, invite_clist
, invite_hlist
, NULL
, NULL
, NULL
, invite_desc
);
63 static bool add_invite(struct Channel
*, struct Client
*);
66 * parv[1] - user to invite
67 * parv[2] - channel name
70 m_invite(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
72 struct Client
*target_p
;
73 struct Channel
*chptr
;
74 struct membership
*msptr
;
76 hook_data_channel_approval hdata
= { 0 };
78 if(MyClient(source_p
) && !IsFloodDone(source_p
))
79 flood_endgrace(source_p
);
81 if(MyClient(source_p
))
82 target_p
= find_named_person(parv
[1]);
84 target_p
= find_person(parv
[1]);
87 if(!MyClient(source_p
) && IsDigit(parv
[1][0]))
88 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
89 "* :Target left IRC. Failed to invite to %s",
92 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
93 form_str(ERR_NOSUCHNICK
),
98 if(check_channel_name(parv
[2]) == 0)
100 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
101 form_str(ERR_BADCHANNAME
),
106 /* Do not send local channel invites to users if they are not on the
107 * same server as the person sending the INVITE message.
109 if(parv
[2][0] == '&' && !MyConnect(target_p
))
111 sendto_one(source_p
, form_str(ERR_USERNOTONSERV
),
112 me
.name
, source_p
->name
, target_p
->name
);
116 if(((MyConnect(source_p
) && !IsExemptResv(source_p
)) ||
117 (MyConnect(target_p
) && !IsExemptResv(target_p
))) &&
118 hash_find_resv(parv
[2]))
120 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
121 form_str(ERR_BADCHANNAME
),
126 if((chptr
= find_channel(parv
[2])) == NULL
)
128 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
129 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
133 msptr
= find_channel_membership(chptr
, source_p
);
134 if(MyClient(source_p
) && (msptr
== NULL
))
136 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
137 form_str(ERR_NOTONCHANNEL
), parv
[2]);
141 if(IsMember(target_p
, chptr
))
143 sendto_one_numeric(source_p
, ERR_USERONCHANNEL
,
144 form_str(ERR_USERONCHANNEL
),
145 target_p
->name
, parv
[2]);
149 if (MyClient(source_p
))
153 hdata
.client
= source_p
;
154 hdata
.target
= target_p
;
155 hdata
.approved
= !(is_chanop(msptr
) || (chptr
->mode
.mode
& MODE_FREEINVITE
));
157 call_hook(can_invite_hook
, &hdata
);
161 sendto_one_numeric(source_p
, hdata
.approved
, "%s", hdata
.error
);
163 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
164 me
.name
, source_p
->name
, parv
[2]);
170 /* store invites when they could affect the ability to join
171 * for +l/+j just check if the mode is set, this varies over time
173 if(chptr
->mode
.mode
& MODE_INVITEONLY
||
174 (chptr
->mode
.mode
& MODE_REGONLY
&& EmptyString(target_p
->user
->suser
)) ||
175 chptr
->mode
.limit
|| chptr
->mode
.join_num
)
178 if(MyConnect(source_p
))
180 if (ConfigFileEntry
.target_change
&& !IsOperGeneral(source_p
) &&
181 !find_allowing_channel(source_p
, target_p
) &&
182 !add_target(source_p
, target_p
))
184 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
185 me
.name
, source_p
->name
, target_p
->name
);
188 sendto_one(source_p
, form_str(RPL_INVITING
),
189 me
.name
, source_p
->name
,
190 target_p
->name
, parv
[2]);
191 if(target_p
->user
->away
)
192 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
193 target_p
->name
, target_p
->user
->away
);
195 /* invite timestamp */
196 else if(parc
> 3 && !EmptyString(parv
[3]))
198 /* this should never be less than */
199 if(atol(parv
[3]) > chptr
->channelts
)
203 if(MyConnect(target_p
))
207 hdata
.client
= source_p
;
208 hdata
.target
= target_p
;
211 call_hook(invite_hook
, &hdata
);
216 sendto_one_numeric(source_p
, hdata
.approved
, "%s", hdata
.error
);
220 add_reply_target(target_p
, source_p
);
221 sendto_one(target_p
, ":%s!%s@%s INVITE %s :%s",
222 source_p
->name
, source_p
->username
, source_p
->host
,
223 target_p
->name
, chptr
->chname
);
226 add_invite(chptr
, target_p
);
228 else if (target_p
->from
!= client_p
)
230 sendto_one_prefix(target_p
, source_p
, "INVITE", "%s %lu",
231 chptr
->chname
, (unsigned long) chptr
->channelts
);
237 * input - channel to add invite to, client to add
238 * output - true if it is a new invite, else false
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
);