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 "list.h" |
27 |
#include "handlers.h" |
28 |
#include "channel.h" |
29 |
#include "channel_mode.h" |
30 |
#include "client.h" |
31 |
#include "hash.h" |
32 |
#include "irc_string.h" |
33 |
#include "ircd.h" |
34 |
#include "numeric.h" |
35 |
#include "send.h" |
36 |
#include "s_conf.h" |
37 |
#include "s_serv.h" |
38 |
#include "msg.h" |
39 |
#include "parse.h" |
40 |
#include "modules.h" |
41 |
#include "packet.h" |
42 |
|
43 |
static void m_invite(struct Client *, struct Client *, int, char *[]); |
44 |
|
45 |
struct Message invite_msgtab = { |
46 |
"INVITE", 0, 0, 3, 0, MFLG_SLOW, 0, |
47 |
{ m_unregistered, m_invite, m_invite, m_ignore, m_invite, m_ignore } |
48 |
}; |
49 |
|
50 |
#ifndef STATIC_MODULES |
51 |
void |
52 |
_modinit(void) |
53 |
{ |
54 |
mod_add_cmd(&invite_msgtab); |
55 |
} |
56 |
|
57 |
void |
58 |
_moddeinit(void) |
59 |
{ |
60 |
mod_del_cmd(&invite_msgtab); |
61 |
} |
62 |
|
63 |
const char *_version = "$Revision$"; |
64 |
#endif |
65 |
|
66 |
/* |
67 |
** m_invite |
68 |
** parv[0] - sender prefix |
69 |
** parv[1] - user to invite |
70 |
** parv[2] - channel name |
71 |
** parv[3] - invite timestamp |
72 |
*/ |
73 |
static void |
74 |
m_invite(struct Client *client_p, struct Client *source_p, |
75 |
int parc, char *parv[]) |
76 |
{ |
77 |
struct Client *target_p = NULL; |
78 |
struct Channel *chptr = NULL; |
79 |
struct Membership *ms = NULL; |
80 |
|
81 |
if (IsServer(source_p)) |
82 |
return; |
83 |
|
84 |
if (EmptyString(parv[2])) |
85 |
{ |
86 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
87 |
me.name, source_p->name, "INVITE"); |
88 |
return; |
89 |
} |
90 |
|
91 |
if (MyClient(source_p) && !IsFloodDone(source_p)) |
92 |
flood_endgrace(source_p); |
93 |
|
94 |
if ((target_p = find_person(client_p, parv[1])) == NULL) |
95 |
{ |
96 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
97 |
me.name, source_p->name, parv[1]); |
98 |
return; |
99 |
} |
100 |
|
101 |
/* Do not send local channel invites to users if they are not on the |
102 |
* same server as the person sending the INVITE message. |
103 |
*/ |
104 |
/* Possibly should be an error sent to source_p */ |
105 |
/* done .. there should be no problem because MyConnect(source_p) should |
106 |
* always be true if parse() and such is working correctly --is |
107 |
*/ |
108 |
if (!MyConnect(target_p) && (*parv[2] == '&')) |
109 |
{ |
110 |
if (ConfigServerHide.hide_servers == 0) |
111 |
sendto_one(source_p, form_str(ERR_USERNOTONSERV), |
112 |
me.name, source_p->name, target_p->name); |
113 |
return; |
114 |
} |
115 |
|
116 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
117 |
{ |
118 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
119 |
me.name, source_p->name, parv[2]); |
120 |
return; |
121 |
} |
122 |
|
123 |
if (MyConnect(source_p) && (ms = find_channel_link(source_p, chptr)) == NULL) |
124 |
{ |
125 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
126 |
me.name, source_p->name, chptr->chname); |
127 |
return; |
128 |
} |
129 |
|
130 |
if ((chptr->mode.mode & (MODE_INVITEONLY | MODE_PRIVATE))) |
131 |
{ |
132 |
if (MyConnect(source_p) && !has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
133 |
{ |
134 |
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
135 |
me.name, source_p->name, chptr->chname); |
136 |
return; |
137 |
} |
138 |
} |
139 |
|
140 |
if (IsMember(target_p, chptr)) |
141 |
{ |
142 |
sendto_one(source_p, form_str(ERR_USERONCHANNEL), |
143 |
me.name, source_p->name, target_p->name, chptr->chname); |
144 |
return; |
145 |
} |
146 |
|
147 |
if (MyConnect(source_p)) |
148 |
{ |
149 |
sendto_one(source_p, form_str(RPL_INVITING), me.name, |
150 |
source_p->name, target_p->name, chptr->chname); |
151 |
|
152 |
if (target_p->away) |
153 |
sendto_one(source_p, form_str(RPL_AWAY), |
154 |
me.name, source_p->name, target_p->name, |
155 |
target_p->away); |
156 |
} |
157 |
else if (parc > 3 && IsDigit(*parv[3])) |
158 |
if (atoi(parv[3]) > chptr->channelts) |
159 |
return; |
160 |
|
161 |
if (MyConnect(target_p)) |
162 |
{ |
163 |
sendto_one(target_p, ":%s!%s@%s INVITE %s :%s", |
164 |
source_p->name, source_p->username, |
165 |
source_p->host, |
166 |
target_p->name, chptr->chname); |
167 |
|
168 |
if (chptr->mode.mode & MODE_INVITEONLY) |
169 |
{ |
170 |
if (chptr->mode.mode & MODE_PRIVATE) |
171 |
{ |
172 |
/* Only do this if channel is set +i AND +p */ |
173 |
sendto_channel_local(CHFL_CHANOP|CHFL_HALFOP, 0, chptr, |
174 |
":%s NOTICE %s :%s is inviting %s to %s.", |
175 |
me.name, chptr->chname, source_p->name, |
176 |
target_p->name, chptr->chname); |
177 |
sendto_channel_remote(source_p, client_p, CHFL_CHANOP|CHFL_HALFOP, |
178 |
NOCAPS, NOCAPS, chptr, |
179 |
":%s NOTICE %s :%s is inviting %s to %s.", |
180 |
source_p->name, chptr->chname, source_p->name, |
181 |
target_p->name, chptr->chname); |
182 |
} |
183 |
|
184 |
/* Add the invite if channel is +i */ |
185 |
add_invite(chptr, target_p); |
186 |
} |
187 |
} |
188 |
else if (target_p->from != client_p) |
189 |
sendto_one(target_p, ":%s INVITE %s %s %lu", |
190 |
ID_or_name(source_p, target_p->from), |
191 |
ID_or_name(target_p, target_p->from), |
192 |
chptr->chname, (unsigned long)chptr->channelts); |
193 |
} |