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