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 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

# 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
116 if (source_p->localClient->invite.count > ConfigChannel.invite_client_count)
117 {
118 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->chname, "user");
119 return 0;
120 }
121
122 source_p->localClient->invite.last_attempt = CurrentTime;
123 source_p->localClient->invite.count++;
124
125 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 {
132 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
137 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 }
148 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 /*! \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 * - parv[0] = command
164 * - parv[1] = user to invite
165 * - parv[2] = channel name
166 * - parv[3] = channel timestamp
167 */
168 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 if (parc < 3 || EmptyString(parv[2]))
175 return 0;
176
177 if ((target_p = find_person(source_p, parv[1])) == NULL)
178 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 if (atoi(parv[3]) > chptr->channelts)
188 return 0;
189
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 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
204 /* Add the invite if channel is +i */
205 add_invite(chptr, target_p);
206 }
207 }
208 else if (target_p->from != source_p->from)
209 sendto_one(target_p, ":%s INVITE %s %s %lu",
210 source_p->id, target_p->id,
211 chptr->chname, (unsigned long)chptr->channelts);
212 return 0;
213 }
214
215
216 static struct Message invite_msgtab =
217 {
218 "INVITE", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
219 { m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore }
220 };
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 struct module module_entry =
235 {
236 .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