ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 3866
Committed: Thu Jun 5 21:07:55 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 6995 byte(s)
Log Message:
- m_invite.c, m_knock.c: fixed stupid logic error

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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 /*! \file m_invite.c
23 * \brief Includes required functions for processing the INVITE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "conf.h"
33 #include "hash.h"
34 #include "irc_string.h"
35 #include "ircd.h"
36 #include "numeric.h"
37 #include "send.h"
38 #include "server.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "packet.h"
42
43
44 /*! \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 * - parv[0] = command
53 * - parv[1] = user to invite
54 * - parv[2] = channel name
55 */
56 static int
57 m_invite(struct Client *source_p, int parc, char *parv[])
58 {
59 struct Client *target_p = NULL;
60 struct Channel *chptr = NULL;
61 struct Membership *ms = NULL;
62
63 if (parc < 2)
64 {
65 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 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE");
77 return 0;
78 }
79
80 if (IsFloodDone(source_p))
81 flood_endgrace(source_p);
82
83 if ((target_p = find_person(source_p, parv[1])) == NULL)
84 {
85 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
86 return 0;
87 }
88
89 if ((chptr = hash_find_channel(parv[2])) == NULL)
90 {
91 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
92 return 0;
93 }
94
95 if ((ms = find_channel_link(source_p, chptr)) == NULL)
96 {
97 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
98 return 0;
99 }
100
101 if (!has_member_flags(ms, CHFL_CHANOP))
102 {
103 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
104 return 0;
105 }
106
107 if (IsMember(target_p, chptr))
108 {
109 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname);
110 return 0;
111 }
112
113 if ((source_p->localClient->invite.last_attempt + ConfigChannel.invite_client_time) < CurrentTime)
114 source_p->localClient->invite.count = 0;
115 source_p->localClient->invite.last_attempt = CurrentTime;
116 source_p->localClient->invite.count++;
117
118 if (source_p->localClient->invite.count > ConfigChannel.invite_client_count)
119 {
120 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->chname, "user");
121 return 0;
122 }
123
124 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->chname);
125
126 if (target_p->away[0])
127 sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
128
129 if (MyConnect(target_p))
130 {
131 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
132 source_p->name, source_p->username,
133 source_p->host,
134 target_p->name, chptr->chname);
135
136 if (chptr->mode.mode & MODE_INVITEONLY)
137 {
138 sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
139 "NOTICE @%s :%s is inviting %s to %s.",
140 chptr->chname, source_p->name,
141 target_p->name, chptr->chname);
142
143 /* Add the invite if channel is +i */
144 add_invite(chptr, target_p);
145 }
146 }
147 else if (target_p->from != source_p->from)
148 sendto_one(target_p, ":%s INVITE %s %s %lu",
149 source_p->id, target_p->id,
150 chptr->chname, (unsigned long)chptr->channelts);
151 return 0;
152 }
153
154 /*! \brief INVITE command handler
155 *
156 * \param source_p Pointer to allocated Client struct from which the message
157 * originally comes from. This can be a local or remote client.
158 * \param parc Integer holding the number of supplied arguments.
159 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
160 * pointers.
161 * \note Valid arguments for this command are:
162 * - parv[0] = command
163 * - parv[1] = user to invite
164 * - parv[2] = channel name
165 * - parv[3] = channel timestamp
166 */
167 static int
168 ms_invite(struct Client *source_p, int parc, char *parv[])
169 {
170 struct Client *target_p = NULL;
171 struct Channel *chptr = NULL;
172
173 if (parc < 3 || EmptyString(parv[2]))
174 return 0;
175
176 if ((target_p = find_person(source_p, parv[1])) == NULL)
177 return 0;
178
179 if ((chptr = hash_find_channel(parv[2])) == NULL)
180 return 0;
181
182 if (IsMember(target_p, chptr))
183 return 0;
184
185 if (parc > 3 && IsDigit(*parv[3]))
186 if (atoi(parv[3]) > chptr->channelts)
187 return 0;
188
189 if (MyConnect(target_p))
190 {
191 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
192 source_p->name, source_p->username,
193 source_p->host,
194 target_p->name, chptr->chname);
195
196 if (chptr->mode.mode & MODE_INVITEONLY)
197 {
198 sendto_channel_butone(NULL, &me, chptr, CHFL_CHANOP,
199 "NOTICE @%s :%s is inviting %s to %s.",
200 chptr->chname, source_p->name,
201 target_p->name, chptr->chname);
202
203 /* Add the invite if channel is +i */
204 add_invite(chptr, target_p);
205 }
206 }
207 else if (target_p->from != source_p->from)
208 sendto_one(target_p, ":%s INVITE %s %s %lu",
209 source_p->id, target_p->id,
210 chptr->chname, (unsigned long)chptr->channelts);
211 return 0;
212 }
213
214
215 static struct Message invite_msgtab =
216 {
217 "INVITE", 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
218 { m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore }
219 };
220
221 static void
222 module_init(void)
223 {
224 mod_add_cmd(&invite_msgtab);
225 }
226
227 static void
228 module_exit(void)
229 {
230 mod_del_cmd(&invite_msgtab);
231 }
232
233 struct module module_entry =
234 {
235 .node = { NULL, NULL, NULL },
236 .name = NULL,
237 .version = "$Revision$",
238 .handle = NULL,
239 .modinit = module_init,
240 .modexit = module_exit,
241 .flags = 0
242 };

Properties

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