Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_invite.c
blob077060670bc170d677a40bbdf12ee2ebdf328a02
1 /*
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
22 * USA
25 #include "stdinc.h"
26 #include "tools.h"
27 #include "common.h"
28 #include "channel.h"
29 #include "client.h"
30 #include "hash.h"
31 #include "irc_string.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "send.h"
35 #include "s_conf.h"
36 #include "s_serv.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "packet.h"
42 static int m_invite(struct Client *, struct Client *, int, const char **);
44 struct Message invite_msgtab = {
45 "INVITE", 0, 0, 0, MFLG_SLOW,
46 {mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}}
48 mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL };
49 DECLARE_MODULE_AV1(invite, NULL, NULL, invite_clist, NULL, NULL, "$Revision: 26 $");
51 static void add_invite(struct Channel *, struct Client *);
53 /* m_invite()
54 * parv[0] - sender prefix
55 * parv[1] - user to invite
56 * parv[2] - channel name
58 static int
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;
64 int store_invite = 0;
66 if(MyClient(source_p) && !IsFloodDone(source_p))
67 flood_endgrace(source_p);
69 if((target_p = find_person(parv[1])) == NULL)
71 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
72 form_str(ERR_NOSUCHNICK),
73 IsDigit(parv[1][0]) ? "*" : parv[1]);
74 return 0;
77 if(check_channel_name(parv[2]) == 0)
79 sendto_one_numeric(source_p, ERR_BADCHANNAME,
80 form_str(ERR_BADCHANNAME),
81 parv[2]);
82 return 0;
85 if(!IsChannelName(parv[2]))
87 if(MyClient(source_p))
88 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
89 form_str(ERR_NOSUCHCHANNEL), parv[2]);
90 return 0;
93 if((chptr = find_channel(parv[2])) == NULL)
95 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
96 form_str(ERR_NOSUCHCHANNEL), parv[2]);
97 return 0;
100 msptr = find_channel_membership(chptr, source_p);
101 if(MyClient(source_p) && (msptr == NULL))
103 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
104 form_str(ERR_NOTONCHANNEL), parv[2]);
105 return 0;
108 if(IsMember(target_p, chptr))
110 sendto_one_numeric(source_p, ERR_USERONCHANNEL,
111 form_str(ERR_USERONCHANNEL),
112 target_p->name, parv[2]);
113 return 0;
116 /* only store invites for +i channels */
117 /* if the invite could allow someone to join who otherwise could not,
118 * unconditionally require ops, unless the channel is +g */
119 if(ConfigChannel.invite_ops_only || (chptr->mode.mode & MODE_INVITEONLY))
121 /* treat remote clients as chanops */
122 if(MyClient(source_p) && !is_chanop(msptr) &&
123 !(chptr->mode.mode & MODE_FREEINVITE))
125 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
126 me.name, source_p->name, parv[2]);
127 return 0;
130 if(chptr->mode.mode & MODE_INVITEONLY)
131 store_invite = 1;
134 if(MyConnect(source_p))
136 sendto_one(source_p, form_str(RPL_INVITING),
137 me.name, source_p->name,
138 target_p->name, parv[2]);
139 if(target_p->user->away)
140 sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
141 target_p->name, target_p->user->away);
143 /* invite timestamp */
144 else if(parc > 3 && !EmptyString(parv[3]))
146 /* this should never be less than */
147 if(atol(parv[3]) > chptr->channelts)
148 return 0;
151 if(MyConnect(target_p))
153 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
154 source_p->name, source_p->username, source_p->host,
155 target_p->name, chptr->chname);
157 if(store_invite)
158 add_invite(chptr, target_p);
160 else if(target_p->from != client_p)
162 sendto_one_prefix(target_p, source_p, "INVITE", "%s %lu",
163 chptr->chname, (unsigned long) chptr->channelts);
166 return 0;
169 /* add_invite()
171 * input - channel to add invite to, client to add
172 * output -
173 * side effects - client is added to invite list.
175 static void
176 add_invite(struct Channel *chptr, struct Client *who)
178 dlink_node *ptr;
180 /* already invited? */
181 DLINK_FOREACH(ptr, who->user->invited.head)
183 if(ptr->data == chptr)
184 return;
187 /* ok, if their invite list is too long, remove the tail */
188 if((int)dlink_list_length(&who->user->invited) >=
189 ConfigChannel.max_chans_per_user)
191 ptr = who->user->invited.tail;
192 del_invite(ptr->data, who);
195 /* add user to channel invite list */
196 dlinkAddAlloc(who, &chptr->invites);
198 /* add channel to user invite list */
199 dlinkAddAlloc(chptr, &who->user->invited);