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 "hash.h" |
33 |
#include "irc_string.h" |
34 |
#include "ircd.h" |
35 |
#include "numeric.h" |
36 |
#include "send.h" |
37 |
#include "conf.h" |
38 |
#include "s_serv.h" |
39 |
#include "parse.h" |
40 |
#include "modules.h" |
41 |
#include "packet.h" |
42 |
|
43 |
|
44 |
/* |
45 |
** m_invite |
46 |
** parv[0] - command |
47 |
** parv[1] - user to invite |
48 |
** parv[2] - channel name |
49 |
*/ |
50 |
static int |
51 |
m_invite(struct Client *source_p, int parc, char *parv[]) |
52 |
{ |
53 |
struct Client *target_p = NULL; |
54 |
struct Channel *chptr = NULL; |
55 |
struct Membership *ms = NULL; |
56 |
|
57 |
if (EmptyString(parv[2])) |
58 |
{ |
59 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE"); |
60 |
return 0; |
61 |
} |
62 |
|
63 |
if (IsFloodDone(source_p)) |
64 |
flood_endgrace(source_p); |
65 |
|
66 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
67 |
{ |
68 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]); |
69 |
return 0; |
70 |
} |
71 |
|
72 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
73 |
{ |
74 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]); |
75 |
return 0; |
76 |
} |
77 |
|
78 |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
79 |
{ |
80 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname); |
81 |
return 0; |
82 |
} |
83 |
|
84 |
if (!has_member_flags(ms, CHFL_CHANOP)) |
85 |
{ |
86 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname); |
87 |
return 0; |
88 |
} |
89 |
|
90 |
if (IsMember(target_p, chptr)) |
91 |
{ |
92 |
sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, chptr->chname); |
93 |
return 0; |
94 |
} |
95 |
|
96 |
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 |
{ |
103 |
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 |
|
108 |
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 |
} |
119 |
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 = hash_find_id(parv[1])) == NULL || !IsClient(target_p)) |
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 |
if (atoi(parv[3]) > chptr->channelts) |
153 |
return 0; |
154 |
|
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 |
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 |
|
169 |
/* Add the invite if channel is +i */ |
170 |
add_invite(chptr, target_p); |
171 |
} |
172 |
} |
173 |
else if (target_p->from != source_p->from) |
174 |
sendto_one(target_p, ":%s INVITE %s %s %lu", |
175 |
source_p->id, target_p->id, |
176 |
chptr->chname, (unsigned long)chptr->channelts); |
177 |
return 0; |
178 |
} |
179 |
|
180 |
|
181 |
static struct Message invite_msgtab = |
182 |
{ |
183 |
"INVITE", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
184 |
{ m_unregistered, m_invite, ms_invite, m_ignore, m_invite, m_ignore } |
185 |
}; |
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 |
struct module module_entry = |
200 |
{ |
201 |
.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 |
}; |