ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 3431
Committed: Thu May 1 12:44:31 2014 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 6207 byte(s)
Log Message:
- Replace few hash_find_id() with find_person()

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     #include "hash.h"
33     #include "irc_string.h"
34     #include "ircd.h"
35     #include "numeric.h"
36     #include "send.h"
37 michael 3347 #include "server.h"
38 adx 30 #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     struct Membership *ms = NULL;
61    
62 michael 885 if (EmptyString(parv[2]))
63 adx 30 {
64 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE");
65 michael 2820 return 0;
66 adx 30 }
67    
68 michael 3205 if (IsFloodDone(source_p))
69 adx 30 flood_endgrace(source_p);
70    
71 michael 3156 if ((target_p = find_person(source_p, parv[1])) == NULL)
72 adx 30 {
73 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
74 michael 2820 return 0;
75 adx 30 }
76    
77     if ((chptr = hash_find_channel(parv[2])) == NULL)
78     {
79 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
80 michael 2820 return 0;
81 adx 30 }
82    
83 michael 3205 if ((ms = find_channel_link(source_p, chptr)) == NULL)
84 adx 30 {
85 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
86 michael 2820 return 0;
87 adx 30 }
88    
89 michael 3205 if (!has_member_flags(ms, CHFL_CHANOP))
90 adx 30 {
91 michael 3109 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
92 michael 2820 return 0;
93 adx 30 }
94    
95     if (IsMember(target_p, chptr))
96     {
97 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname);
98 michael 2820 return 0;
99 adx 30 }
100    
101 michael 3205 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->chname);
102    
103     if (target_p->away[0])
104     sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
105    
106     if (MyConnect(target_p))
107 adx 30 {
108 michael 3205 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
109     source_p->name, source_p->username,
110     source_p->host,
111     target_p->name, chptr->chname);
112 adx 30
113 michael 3205 if (chptr->mode.mode & MODE_INVITEONLY)
114     {
115     sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
116     "NOTICE @%s :%s is inviting %s to %s.",
117     chptr->chname, source_p->name,
118     target_p->name, chptr->chname);
119    
120     /* Add the invite if channel is +i */
121     add_invite(chptr, target_p);
122     }
123 adx 30 }
124 michael 3205 else if (target_p->from != source_p->from)
125     sendto_one(target_p, ":%s INVITE %s %s %lu",
126     source_p->id, target_p->id,
127     chptr->chname, (unsigned long)chptr->channelts);
128     return 0;
129     }
130    
131 michael 3294 /*! \brief INVITE command handler
132     *
133     * \param source_p Pointer to allocated Client struct from which the message
134     * originally comes from. This can be a local or remote client.
135     * \param parc Integer holding the number of supplied arguments.
136     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
137     * pointers.
138     * \note Valid arguments for this command are:
139 michael 3299 * - parv[0] = command
140     * - parv[1] = user to invite
141     * - parv[2] = channel name
142     * - parv[3] = channel timestamp
143 michael 3294 */
144 michael 3205 static int
145     ms_invite(struct Client *source_p, int parc, char *parv[])
146     {
147     struct Client *target_p = NULL;
148     struct Channel *chptr = NULL;
149    
150     if (EmptyString(parv[2]))
151     return 0;
152    
153 michael 3431 if ((target_p = find_person(source_p, parv[1])) == NULL)
154 michael 3205 return 0;
155    
156     if ((chptr = hash_find_channel(parv[2])) == NULL)
157     return 0;
158    
159     if (IsMember(target_p, chptr))
160     return 0;
161    
162     if (parc > 3 && IsDigit(*parv[3]))
163 adx 30 if (atoi(parv[3]) > chptr->channelts)
164 michael 2820 return 0;
165 adx 30
166     if (MyConnect(target_p))
167     {
168     sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
169     source_p->name, source_p->username,
170     source_p->host,
171     target_p->name, chptr->chname);
172    
173     if (chptr->mode.mode & MODE_INVITEONLY)
174     {
175 michael 1721 sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
176     "NOTICE @%s :%s is inviting %s to %s.",
177     chptr->chname, source_p->name,
178     target_p->name, chptr->chname);
179 michael 1479
180 adx 30 /* Add the invite if channel is +i */
181     add_invite(chptr, target_p);
182     }
183     }
184 michael 3156 else if (target_p->from != source_p->from)
185 adx 30 sendto_one(target_p, ":%s INVITE %s %s %lu",
186 michael 3205 source_p->id, target_p->id,
187 adx 30 chptr->chname, (unsigned long)chptr->channelts);
188 michael 2820 return 0;
189 adx 30 }
190 michael 1230
191 michael 3205
192 michael 2820 static struct Message invite_msgtab =
193     {
194 michael 1230 "INVITE", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
195 michael 3205 { m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore }
196 michael 1230 };
197    
198     static void
199     module_init(void)
200     {
201     mod_add_cmd(&invite_msgtab);
202     }
203    
204     static void
205     module_exit(void)
206     {
207     mod_del_cmd(&invite_msgtab);
208     }
209    
210 michael 2820 struct module module_entry =
211     {
212 michael 1230 .node = { NULL, NULL, NULL },
213     .name = NULL,
214     .version = "$Revision$",
215     .handle = NULL,
216     .modinit = module_init,
217     .modexit = module_exit,
218     .flags = 0
219     };

Properties

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