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