ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 3205
Committed: Mon Mar 24 20:41:24 2014 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 5403 byte(s)
Log Message:
- m_invite.c: add ms_invite(). Cleaned up m_invite()

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 1309 #include "conf.h"
38 adx 30 #include "s_serv.h"
39     #include "parse.h"
40     #include "modules.h"
41     #include "packet.h"
42    
43    
44     /*
45     ** m_invite
46 michael 3096 ** parv[0] - command
47 adx 30 ** parv[1] - user to invite
48     ** parv[2] - channel name
49     */
50 michael 2820 static int
51 michael 3156 m_invite(struct Client *source_p, int parc, char *parv[])
52 adx 30 {
53     struct Client *target_p = NULL;
54     struct Channel *chptr = NULL;
55     struct Membership *ms = NULL;
56    
57 michael 885 if (EmptyString(parv[2]))
58 adx 30 {
59 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE");
60 michael 2820 return 0;
61 adx 30 }
62    
63 michael 3205 if (IsFloodDone(source_p))
64 adx 30 flood_endgrace(source_p);
65    
66 michael 3156 if ((target_p = find_person(source_p, parv[1])) == NULL)
67 adx 30 {
68 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
69 michael 2820 return 0;
70 adx 30 }
71    
72     if ((chptr = hash_find_channel(parv[2])) == NULL)
73     {
74 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
75 michael 2820 return 0;
76 adx 30 }
77    
78 michael 3205 if ((ms = find_channel_link(source_p, chptr)) == NULL)
79 adx 30 {
80 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
81 michael 2820 return 0;
82 adx 30 }
83    
84 michael 3205 if (!has_member_flags(ms, CHFL_CHANOP))
85 adx 30 {
86 michael 3109 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
87 michael 2820 return 0;
88 adx 30 }
89    
90     if (IsMember(target_p, chptr))
91     {
92 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname);
93 michael 2820 return 0;
94 adx 30 }
95    
96 michael 3205 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->chname);
97    
98     if (target_p->away[0])
99     sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
100    
101     if (MyConnect(target_p))
102 adx 30 {
103 michael 3205 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
104     source_p->name, source_p->username,
105     source_p->host,
106     target_p->name, chptr->chname);
107 adx 30
108 michael 3205 if (chptr->mode.mode & MODE_INVITEONLY)
109     {
110     sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
111     "NOTICE @%s :%s is inviting %s to %s.",
112     chptr->chname, source_p->name,
113     target_p->name, chptr->chname);
114    
115     /* Add the invite if channel is +i */
116     add_invite(chptr, target_p);
117     }
118 adx 30 }
119 michael 3205 else if (target_p->from != source_p->from)
120     sendto_one(target_p, ":%s INVITE %s %s %lu",
121     source_p->id, target_p->id,
122     chptr->chname, (unsigned long)chptr->channelts);
123     return 0;
124     }
125    
126     /*
127     ** ms_invite
128     ** parv[0] - command
129     ** parv[1] - user to invite
130     ** parv[2] - channel name
131     ** parv[3] - invite timestamp
132     */
133     static int
134     ms_invite(struct Client *source_p, int parc, char *parv[])
135     {
136     struct Client *target_p = NULL;
137     struct Channel *chptr = NULL;
138    
139     if (EmptyString(parv[2]))
140     return 0;
141    
142     if ((target_p = find_person(source_p, parv[1])) == NULL)
143     return 0;
144    
145     if ((chptr = hash_find_channel(parv[2])) == NULL)
146     return 0;
147    
148     if (IsMember(target_p, chptr))
149     return 0;
150    
151     if (parc > 3 && IsDigit(*parv[3]))
152 adx 30 if (atoi(parv[3]) > chptr->channelts)
153 michael 2820 return 0;
154 adx 30
155     if (MyConnect(target_p))
156     {
157     sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
158     source_p->name, source_p->username,
159     source_p->host,
160     target_p->name, chptr->chname);
161    
162     if (chptr->mode.mode & MODE_INVITEONLY)
163     {
164 michael 1721 sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
165     "NOTICE @%s :%s is inviting %s to %s.",
166     chptr->chname, source_p->name,
167     target_p->name, chptr->chname);
168 michael 1479
169 adx 30 /* Add the invite if channel is +i */
170     add_invite(chptr, target_p);
171     }
172     }
173 michael 3156 else if (target_p->from != source_p->from)
174 adx 30 sendto_one(target_p, ":%s INVITE %s %s %lu",
175 michael 3205 source_p->id, target_p->id,
176 adx 30 chptr->chname, (unsigned long)chptr->channelts);
177 michael 2820 return 0;
178 adx 30 }
179 michael 1230
180 michael 3205
181 michael 2820 static struct Message invite_msgtab =
182     {
183 michael 1230 "INVITE", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
184 michael 3205 { m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore }
185 michael 1230 };
186    
187     static void
188     module_init(void)
189     {
190     mod_add_cmd(&invite_msgtab);
191     }
192    
193     static void
194     module_exit(void)
195     {
196     mod_del_cmd(&invite_msgtab);
197     }
198    
199 michael 2820 struct module module_entry =
200     {
201 michael 1230 .node = { NULL, NULL, NULL },
202     .name = NULL,
203     .version = "$Revision$",
204     .handle = NULL,
205     .modinit = module_init,
206     .modexit = module_exit,
207     .flags = 0
208     };

Properties

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