1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_invite.c: Invites the user to join a channel. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "handlers.h" |
27 |
#include "common.h" |
28 |
#include "channel.h" |
29 |
#include "channel_mode.h" |
30 |
#include "client.h" |
31 |
#include "hash.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "send.h" |
35 |
#include "s_conf.h" |
36 |
#include "s_serv.h" |
37 |
#include "msg.h" |
38 |
#include "parse.h" |
39 |
#include "conf/modules.h" |
40 |
#include "packet.h" |
41 |
|
42 |
static void m_invite(struct Client *, struct Client *, int, char *[]); |
43 |
|
44 |
struct Message invite_msgtab = { |
45 |
"INVITE", 0, 0, 3, 0, MFLG_SLOW, 0, |
46 |
{ m_unregistered, m_invite, m_invite, m_ignore, m_invite, m_ignore } |
47 |
}; |
48 |
|
49 |
INIT_MODULE(m_invite, "$Revision$") |
50 |
{ |
51 |
mod_add_cmd(&invite_msgtab); |
52 |
} |
53 |
|
54 |
CLEANUP_MODULE |
55 |
{ |
56 |
mod_del_cmd(&invite_msgtab); |
57 |
} |
58 |
|
59 |
/*! \brief INVITE command handler (called for clients only) |
60 |
* |
61 |
* \param client_p Pointer to allocated Client struct with physical connection |
62 |
* to this server, i.e. with an open socket connected. |
63 |
* \param source_p Pointer to allocated Client struct from which the message |
64 |
* originally comes from. This can be a local or remote client. |
65 |
* \param parc Integer holding the number of supplied arguments. |
66 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
67 |
* pointers. |
68 |
* \note Valid arguments for this command are: |
69 |
* - parv[0] = sender prefix |
70 |
* - parv[1] = user to invite |
71 |
* - parv[2] = channel name |
72 |
* - parv[3] = invite timestamp |
73 |
*/ |
74 |
static void |
75 |
m_invite(struct Client *client_p, struct Client *source_p, |
76 |
int parc, char *parv[]) |
77 |
{ |
78 |
struct Client *target_p = NULL; |
79 |
struct Channel *chptr = NULL; |
80 |
struct Membership *ms = NULL; |
81 |
|
82 |
if (IsServer(source_p)) |
83 |
return; |
84 |
|
85 |
if (*parv[2] == '\0') |
86 |
{ |
87 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
88 |
me.name, source_p->name, "INVITE"); |
89 |
return; |
90 |
} |
91 |
|
92 |
if (MyClient(source_p) && !IsFloodDone(source_p)) |
93 |
flood_endgrace(source_p); |
94 |
|
95 |
if ((target_p = find_person(client_p, parv[1])) == NULL) |
96 |
{ |
97 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
98 |
me.name, source_p->name, parv[1]); |
99 |
return; |
100 |
} |
101 |
|
102 |
/* |
103 |
* Do not send local channel invites to users if they are not on the |
104 |
* same server as the person sending the INVITE message. |
105 |
*/ |
106 |
if ((*parv[2] == '&') && !MyConnect(target_p)) |
107 |
{ |
108 |
if (!ConfigServerHide.hide_servers) |
109 |
sendto_one(source_p, form_str(ERR_USERNOTONSERV), |
110 |
me.name, source_p->name, target_p->name); |
111 |
return; |
112 |
} |
113 |
|
114 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
115 |
{ |
116 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
117 |
me.name, source_p->name, parv[2]); |
118 |
return; |
119 |
} |
120 |
|
121 |
if (MyConnect(source_p) && (ms = find_channel_link(source_p, chptr)) == NULL) |
122 |
{ |
123 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
124 |
me.name, source_p->name, chptr->chname); |
125 |
return; |
126 |
} |
127 |
|
128 |
if (chptr->mode.mode & (MODE_INVITEONLY | MODE_PARANOID)) |
129 |
{ |
130 |
if (MyConnect(source_p) && !has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
131 |
{ |
132 |
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
133 |
me.name, source_p->name, chptr->chname); |
134 |
return; |
135 |
} |
136 |
} |
137 |
|
138 |
if (IsMember(target_p, chptr)) |
139 |
{ |
140 |
sendto_one(source_p, form_str(ERR_USERONCHANNEL), |
141 |
me.name, source_p->name, target_p->name, chptr->chname); |
142 |
return; |
143 |
} |
144 |
|
145 |
if (MyConnect(source_p)) |
146 |
{ |
147 |
sendto_one(source_p, form_str(RPL_INVITING), me.name, |
148 |
source_p->name, target_p->name, chptr->chname); |
149 |
|
150 |
if (target_p->away) |
151 |
sendto_one(source_p, form_str(RPL_AWAY), |
152 |
me.name, source_p->name, target_p->name, |
153 |
target_p->away); |
154 |
} |
155 |
else if (parc > 3 && IsDigit(*parv[3])) |
156 |
if (atoi(parv[3]) > chptr->channelts) |
157 |
return; |
158 |
|
159 |
if (MyConnect(target_p)) |
160 |
{ |
161 |
sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", |
162 |
source_p->name, source_p->username, |
163 |
source_p->host, |
164 |
target_p->name, chptr->chname); |
165 |
|
166 |
if (chptr->mode.mode & MODE_INVITEONLY) |
167 |
{ |
168 |
if (chptr->mode.mode & MODE_PARANOID) |
169 |
{ |
170 |
/* Only do this if channel is set +i AND +p */ |
171 |
sendto_channel_local(CHFL_CHANOP|CHFL_HALFOP, NO, chptr, |
172 |
":%s NOTICE %s :%s is inviting %s to %s.", |
173 |
me.name, chptr->chname, source_p->name, |
174 |
target_p->name, chptr->chname); |
175 |
sendto_channel_remote(source_p, client_p, CHFL_CHANOP|CHFL_HALFOP, |
176 |
NOCAPS, NOCAPS, chptr, |
177 |
":%s NOTICE %s :%s is inviting %s to %s.", |
178 |
source_p->name, chptr->chname, source_p->name, |
179 |
target_p->name, chptr->chname); |
180 |
} |
181 |
|
182 |
/* Add the invite if channel is +i */ |
183 |
add_invite(chptr, target_p); |
184 |
} |
185 |
} |
186 |
else if (target_p->from != client_p) |
187 |
sendto_one(target_p, ":%s INVITE %s %s %lu", |
188 |
ID_or_name(source_p, target_p->from), |
189 |
ID_or_name(target_p, target_p->from), |
190 |
chptr->chname, (unsigned long)chptr->channelts); |
191 |
} |