ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_invite.c
Revision: 7007
Committed: Fri Jan 1 00:09:08 2016 UTC (10 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 7777 byte(s)
Log Message:
- Update copyright years

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7007 * Copyright (c) 1997-2016 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_invite.c
23     * \brief Includes required functions for processing the INVITE command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32 michael 3763 #include "conf.h"
33 adx 30 #include "hash.h"
34     #include "irc_string.h"
35     #include "ircd.h"
36     #include "numeric.h"
37     #include "send.h"
38     #include "parse.h"
39     #include "modules.h"
40     #include "packet.h"
41    
42    
43 michael 3294 /*! \brief INVITE command handler
44     *
45     * \param source_p Pointer to allocated Client struct from which the message
46     * originally comes from. This can be a local or remote client.
47     * \param parc Integer holding the number of supplied arguments.
48     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
49     * pointers.
50     * \note Valid arguments for this command are:
51 michael 3299 * - parv[0] = command
52     * - parv[1] = user to invite
53     * - parv[2] = channel name
54 michael 3294 */
55 michael 2820 static int
56 michael 3156 m_invite(struct Client *source_p, int parc, char *parv[])
57 adx 30 {
58     struct Client *target_p = NULL;
59     struct Channel *chptr = NULL;
60 michael 4816 struct Membership *member = NULL;
61 adx 30
62 michael 3766 if (parc < 2)
63 adx 30 {
64 michael 4816 const dlink_node *node = NULL;
65 michael 3766
66 michael 4816 DLINK_FOREACH(node, source_p->connection->invited.head)
67 michael 3766 sendto_one_numeric(source_p, &me, RPL_INVITELIST,
68 michael 4816 ((struct Channel *)node->data)->name);
69 michael 4889
70 michael 3766 sendto_one_numeric(source_p, &me, RPL_ENDOFINVITELIST);
71     return 0;
72     }
73    
74     if (parc < 3 || EmptyString(parv[2]))
75     {
76 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE");
77 michael 2820 return 0;
78 adx 30 }
79    
80 michael 3205 if (IsFloodDone(source_p))
81 adx 30 flood_endgrace(source_p);
82    
83 michael 3156 if ((target_p = find_person(source_p, parv[1])) == NULL)
84 adx 30 {
85 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
86 michael 2820 return 0;
87 adx 30 }
88    
89     if ((chptr = hash_find_channel(parv[2])) == NULL)
90     {
91 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
92 michael 2820 return 0;
93 adx 30 }
94    
95 michael 4816 if ((member = find_channel_link(source_p, chptr)) == NULL)
96 adx 30 {
97 michael 4617 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
98 michael 2820 return 0;
99 adx 30 }
100    
101 michael 4816 if (!has_member_flags(member, CHFL_CHANOP | CHFL_HALFOP))
102 adx 30 {
103 michael 4617 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name);
104 michael 2820 return 0;
105 adx 30 }
106    
107     if (IsMember(target_p, chptr))
108     {
109 michael 4617 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->name);
110 michael 2820 return 0;
111 adx 30 }
112    
113 michael 4589 if ((source_p->connection->invite.last_attempt + ConfigChannel.invite_client_time) < CurrentTime)
114     source_p->connection->invite.count = 0;
115 michael 3863
116 michael 4589 if (source_p->connection->invite.count > ConfigChannel.invite_client_count)
117 michael 3763 {
118 michael 4617 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->name, "user");
119 michael 3763 return 0;
120     }
121    
122 michael 6794 if ((chptr->last_invite + ConfigChannel.invite_delay_channel) > CurrentTime)
123     {
124     sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->name, "channel");
125     return 0;
126     }
127    
128 michael 4589 source_p->connection->invite.last_attempt = CurrentTime;
129     source_p->connection->invite.count++;
130 michael 4082
131 michael 4617 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->name);
132 michael 3205
133     if (target_p->away[0])
134     sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
135    
136 michael 6794 chptr->last_invite = CurrentTime;
137    
138 michael 3205 if (MyConnect(target_p))
139 adx 30 {
140 michael 3205 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
141     source_p->name, source_p->username,
142     source_p->host,
143 michael 4617 target_p->name, chptr->name);
144 adx 30
145 michael 3205 if (chptr->mode.mode & MODE_INVITEONLY)
146 michael 6404 add_invite(chptr, target_p); /* Add the invite if channel is +i */
147     }
148 michael 3205
149 michael 6404 if (chptr->mode.mode & MODE_INVITEONLY)
150 michael 6768 {
151 michael 6772 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
152 michael 6768 ":%s NOTICE %%%s :%s is inviting %s to %s.",
153     me.name, chptr->name, source_p->name, target_p->name, chptr->name);
154     sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
155     ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
156     source_p->host, target_p->name, chptr->name);
157     }
158 michael 6404
159 michael 6781 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
160 michael 6404 source_p->id, target_p->id,
161 michael 6781 chptr->name, chptr->creationtime);
162 michael 3205 return 0;
163     }
164    
165 michael 3294 /*! \brief INVITE command handler
166     *
167     * \param source_p Pointer to allocated Client struct from which the message
168     * originally comes from. This can be a local or remote client.
169     * \param parc Integer holding the number of supplied arguments.
170     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
171     * pointers.
172     * \note Valid arguments for this command are:
173 michael 3299 * - parv[0] = command
174     * - parv[1] = user to invite
175     * - parv[2] = channel name
176     * - parv[3] = channel timestamp
177 michael 3294 */
178 michael 3205 static int
179     ms_invite(struct Client *source_p, int parc, char *parv[])
180     {
181     struct Client *target_p = NULL;
182     struct Channel *chptr = NULL;
183    
184 michael 3766 if (parc < 3 || EmptyString(parv[2]))
185 michael 3205 return 0;
186    
187 michael 3432 if ((target_p = find_person(source_p, parv[1])) == NULL)
188 michael 3205 return 0;
189    
190     if ((chptr = hash_find_channel(parv[2])) == NULL)
191     return 0;
192    
193     if (IsMember(target_p, chptr))
194     return 0;
195    
196     if (parc > 3 && IsDigit(*parv[3]))
197 michael 6901 if (strtoimax(parv[3], NULL, 10) > chptr->creationtime)
198 michael 2820 return 0;
199 adx 30
200 michael 6794 chptr->last_invite = CurrentTime;
201    
202 adx 30 if (MyConnect(target_p))
203     {
204     sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
205     source_p->name, source_p->username,
206     source_p->host,
207 michael 4617 target_p->name, chptr->name);
208 adx 30
209     if (chptr->mode.mode & MODE_INVITEONLY)
210 michael 6404 add_invite(chptr, target_p); /* Add the invite if channel is +i */
211     }
212 michael 1479
213 michael 6404 if (chptr->mode.mode & MODE_INVITEONLY)
214 michael 6768 {
215     sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
216 michael 6760 ":%s NOTICE %%%s :%s is inviting %s to %s.",
217 michael 6404 me.name, chptr->name, source_p->name, target_p->name, chptr->name);
218 michael 6768 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
219     ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
220     source_p->host, target_p->name, chptr->name);
221     }
222 michael 6404
223 michael 6781 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
224 michael 6404 source_p->id, target_p->id,
225 michael 6781 chptr->name, chptr->creationtime);
226 michael 2820 return 0;
227 adx 30 }
228 michael 1230
229 michael 3205
230 michael 2820 static struct Message invite_msgtab =
231     {
232 michael 5880 .cmd = "INVITE",
233     .args_max = MAXPARA,
234     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
235     .handlers[CLIENT_HANDLER] = m_invite,
236     .handlers[SERVER_HANDLER] = ms_invite,
237     .handlers[ENCAP_HANDLER] = m_ignore,
238     .handlers[OPER_HANDLER] = m_invite
239 michael 1230 };
240    
241     static void
242     module_init(void)
243     {
244     mod_add_cmd(&invite_msgtab);
245     }
246    
247     static void
248     module_exit(void)
249     {
250     mod_del_cmd(&invite_msgtab);
251     }
252    
253 michael 2820 struct module module_entry =
254     {
255 michael 1230 .version = "$Revision$",
256     .modinit = module_init,
257     .modexit = module_exit,
258     };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision