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 26 2006-09-20 18:02:06Z spb $
33 #include "irc_string.h"
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: 26 $");
53 static void add_invite(struct Channel
*, struct Client
*);
56 * parv[0] - sender prefix
57 * parv[1] - user to invite
58 * parv[2] - channel name
61 m_invite(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
63 struct Client
*target_p
;
64 struct Channel
*chptr
;
65 struct membership
*msptr
;
68 if(MyClient(source_p
) && !IsFloodDone(source_p
))
69 flood_endgrace(source_p
);
71 if((target_p
= find_person(parv
[1])) == NULL
)
73 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
74 form_str(ERR_NOSUCHNICK
),
75 IsDigit(parv
[1][0]) ? "*" : parv
[1]);
79 if(check_channel_name(parv
[2]) == 0)
81 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
82 form_str(ERR_BADCHANNAME
),
87 if(!IsChannelName(parv
[2]))
89 if(MyClient(source_p
))
90 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
91 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
95 /* Do not send local channel invites to users if they are not on the
96 * same server as the person sending the INVITE message.
98 if(parv
[2][0] == '&' && !MyConnect(target_p
))
100 sendto_one(source_p
, form_str(ERR_USERNOTONSERV
),
101 me
.name
, source_p
->name
, target_p
->name
);
105 if((chptr
= find_channel(parv
[2])) == NULL
)
107 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
108 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
112 msptr
= find_channel_membership(chptr
, source_p
);
113 if(MyClient(source_p
) && (msptr
== NULL
))
115 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
116 form_str(ERR_NOTONCHANNEL
), parv
[2]);
120 if(IsMember(target_p
, chptr
))
122 sendto_one_numeric(source_p
, ERR_USERONCHANNEL
,
123 form_str(ERR_USERONCHANNEL
),
124 target_p
->name
, parv
[2]);
128 /* only store invites for +i channels */
129 /* if the invite could allow someone to join who otherwise could not,
130 * unconditionally require ops, unless the channel is +g */
131 if(ConfigChannel
.invite_ops_only
|| (chptr
->mode
.mode
& MODE_INVITEONLY
))
133 /* treat remote clients as chanops */
134 if(MyClient(source_p
) && !is_chanop(msptr
) &&
135 !(chptr
->mode
.mode
& MODE_FREEINVITE
))
137 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
138 me
.name
, source_p
->name
, parv
[2]);
142 if(chptr
->mode
.mode
& MODE_INVITEONLY
)
146 if(MyConnect(source_p
))
148 sendto_one(source_p
, form_str(RPL_INVITING
),
149 me
.name
, source_p
->name
,
150 target_p
->name
, parv
[2]);
151 if(target_p
->user
->away
)
152 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
153 target_p
->name
, target_p
->user
->away
);
155 /* invite timestamp */
156 else if(parc
> 3 && !EmptyString(parv
[3]))
158 /* this should never be less than */
159 if(atol(parv
[3]) > chptr
->channelts
)
163 if(MyConnect(target_p
))
165 sendto_one(target_p
, ":%s!%s@%s INVITE %s :%s",
166 source_p
->name
, source_p
->username
, source_p
->host
,
167 target_p
->name
, chptr
->chname
);
170 add_invite(chptr
, target_p
);
172 else if(target_p
->from
!= client_p
)
174 sendto_one_prefix(target_p
, source_p
, "INVITE", "%s %lu",
175 chptr
->chname
, (unsigned long) chptr
->channelts
);
183 * input - channel to add invite to, client to add
185 * side effects - client is added to invite list.
188 add_invite(struct Channel
*chptr
, struct Client
*who
)
192 /* already invited? */
193 DLINK_FOREACH(ptr
, who
->user
->invited
.head
)
195 if(ptr
->data
== chptr
)
199 /* ok, if their invite list is too long, remove the tail */
200 if((int)dlink_list_length(&who
->user
->invited
) >=
201 ConfigChannel
.max_chans_per_user
)
203 ptr
= who
->user
->invited
.tail
;
204 del_invite(ptr
->data
, who
);
207 /* add user to channel invite list */
208 dlinkAddAlloc(who
, &chptr
->invites
);
210 /* add channel to user invite list */
211 dlinkAddAlloc(chptr
, &who
->user
->invited
);