ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 4545
Committed: Fri Aug 22 08:46:13 2014 UTC (11 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 7002 byte(s)
Log Message:
- Implemented pseudo {} blocks (service aliases)
- Fixed compile warnings with -Wmissing-field-initializers

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 2820 * Copyright (c) 1997-2014 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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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 3762 #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 michael 3347 #include "server.h"
39 adx 30 #include "parse.h"
40     #include "modules.h"
41     #include "packet.h"
42    
43    
44 michael 3294 /*! \brief INVITE command handler
45     *
46     * \param source_p Pointer to allocated Client struct from which the message
47     * originally comes from. This can be a local or remote client.
48     * \param parc Integer holding the number of supplied arguments.
49     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
50     * pointers.
51     * \note Valid arguments for this command are:
52 michael 3299 * - parv[0] = command
53     * - parv[1] = user to invite
54     * - parv[2] = channel name
55 michael 3294 */
56 michael 2820 static int
57 michael 3156 m_invite(struct Client *source_p, int parc, char *parv[])
58 adx 30 {
59     struct Client *target_p = NULL;
60     struct Channel *chptr = NULL;
61     struct Membership *ms = NULL;
62    
63 michael 3767 if (parc < 2)
64 adx 30 {
65 michael 3767 const dlink_node *ptr = NULL;
66    
67     DLINK_FOREACH(ptr, source_p->localClient->invited.head)
68     sendto_one_numeric(source_p, &me, RPL_INVITELIST,
69     ((struct Channel *)ptr->data)->chname);
70     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 3205 if ((ms = find_channel_link(source_p, chptr)) == NULL)
96 adx 30 {
97 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
98 michael 2820 return 0;
99 adx 30 }
100    
101 michael 3205 if (!has_member_flags(ms, CHFL_CHANOP))
102 adx 30 {
103 michael 3109 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
104 michael 2820 return 0;
105 adx 30 }
106    
107     if (IsMember(target_p, chptr))
108     {
109 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname);
110 michael 2820 return 0;
111 adx 30 }
112    
113 michael 3866 if ((source_p->localClient->invite.last_attempt + ConfigChannel.invite_client_time) < CurrentTime)
114 michael 3860 source_p->localClient->invite.count = 0;
115    
116     if (source_p->localClient->invite.count > ConfigChannel.invite_client_count)
117 michael 3762 {
118     sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->chname, "user");
119     return 0;
120     }
121    
122 michael 4081 source_p->localClient->invite.last_attempt = CurrentTime;
123     source_p->localClient->invite.count++;
124    
125 michael 3205 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->chname);
126    
127     if (target_p->away[0])
128     sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
129    
130     if (MyConnect(target_p))
131 adx 30 {
132 michael 3205 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
133     source_p->name, source_p->username,
134     source_p->host,
135     target_p->name, chptr->chname);
136 adx 30
137 michael 3205 if (chptr->mode.mode & MODE_INVITEONLY)
138     {
139     sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
140     "NOTICE @%s :%s is inviting %s to %s.",
141     chptr->chname, source_p->name,
142     target_p->name, chptr->chname);
143    
144     /* Add the invite if channel is +i */
145     add_invite(chptr, target_p);
146     }
147 adx 30 }
148 michael 3205 else if (target_p->from != source_p->from)
149     sendto_one(target_p, ":%s INVITE %s %s %lu",
150     source_p->id, target_p->id,
151     chptr->chname, (unsigned long)chptr->channelts);
152     return 0;
153     }
154    
155 michael 3294 /*! \brief INVITE command handler
156     *
157     * \param source_p Pointer to allocated Client struct from which the message
158     * originally comes from. This can be a local or remote client.
159     * \param parc Integer holding the number of supplied arguments.
160     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
161     * pointers.
162     * \note Valid arguments for this command are:
163 michael 3299 * - parv[0] = command
164     * - parv[1] = user to invite
165     * - parv[2] = channel name
166     * - parv[3] = channel timestamp
167 michael 3294 */
168 michael 3205 static int
169     ms_invite(struct Client *source_p, int parc, char *parv[])
170     {
171     struct Client *target_p = NULL;
172     struct Channel *chptr = NULL;
173    
174 michael 3767 if (parc < 3 || EmptyString(parv[2]))
175 michael 3205 return 0;
176    
177 michael 3431 if ((target_p = find_person(source_p, parv[1])) == NULL)
178 michael 3205 return 0;
179    
180     if ((chptr = hash_find_channel(parv[2])) == NULL)
181     return 0;
182    
183     if (IsMember(target_p, chptr))
184     return 0;
185    
186     if (parc > 3 && IsDigit(*parv[3]))
187 adx 30 if (atoi(parv[3]) > chptr->channelts)
188 michael 2820 return 0;
189 adx 30
190     if (MyConnect(target_p))
191     {
192     sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
193     source_p->name, source_p->username,
194     source_p->host,
195     target_p->name, chptr->chname);
196    
197     if (chptr->mode.mode & MODE_INVITEONLY)
198     {
199 michael 1721 sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
200     "NOTICE @%s :%s is inviting %s to %s.",
201     chptr->chname, source_p->name,
202     target_p->name, chptr->chname);
203 michael 1479
204 adx 30 /* Add the invite if channel is +i */
205     add_invite(chptr, target_p);
206     }
207     }
208 michael 3156 else if (target_p->from != source_p->from)
209 adx 30 sendto_one(target_p, ":%s INVITE %s %s %lu",
210 michael 3205 source_p->id, target_p->id,
211 adx 30 chptr->chname, (unsigned long)chptr->channelts);
212 michael 2820 return 0;
213 adx 30 }
214 michael 1230
215 michael 3205
216 michael 2820 static struct Message invite_msgtab =
217     {
218 michael 4545 "INVITE", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
219 michael 3205 { m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore }
220 michael 1230 };
221    
222     static void
223     module_init(void)
224     {
225     mod_add_cmd(&invite_msgtab);
226     }
227    
228     static void
229     module_exit(void)
230     {
231     mod_del_cmd(&invite_msgtab);
232     }
233    
234 michael 2820 struct module module_entry =
235     {
236 michael 1230 .node = { NULL, NULL, NULL },
237     .name = NULL,
238     .version = "$Revision$",
239     .handle = NULL,
240     .modinit = module_init,
241     .modexit = module_exit,
242     .flags = 0
243     };

Properties

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