| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_lljoin.c: Joins a user on a lazy-link to 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: m_lljoin.c,v 1.70 2005/08/30 18:28:39 adx Exp $ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "tools.h" |
| 27 |
#include "channel.h" |
| 28 |
#include "channel_mode.h" |
| 29 |
#include "client.h" |
| 30 |
#include "hash.h" |
| 31 |
#include "common.h" |
| 32 |
#include "irc_string.h" |
| 33 |
#include "ircd.h" |
| 34 |
#include "list.h" |
| 35 |
#include "numeric.h" |
| 36 |
#include "s_serv.h" |
| 37 |
#include "s_conf.h" |
| 38 |
#include "send.h" |
| 39 |
#include "handlers.h" |
| 40 |
#include "msg.h" |
| 41 |
#include "parse.h" |
| 42 |
#include "modules.h" |
| 43 |
|
| 44 |
|
| 45 |
static void ms_lljoin(struct Client *,struct Client *,int,char **); |
| 46 |
|
| 47 |
struct Message lljoin_msgtab = { |
| 48 |
"LLJOIN", 0, 0, 3, 0, MFLG_SLOW | MFLG_UNREG, 0L, |
| 49 |
{m_unregistered, m_ignore, ms_lljoin, m_ignore, m_ignore, m_ignore} |
| 50 |
}; |
| 51 |
#ifndef STATIC_MODULES |
| 52 |
|
| 53 |
void |
| 54 |
_modinit(void) |
| 55 |
{ |
| 56 |
mod_add_cmd(&lljoin_msgtab); |
| 57 |
} |
| 58 |
|
| 59 |
void |
| 60 |
_moddeinit(void) |
| 61 |
{ |
| 62 |
mod_del_cmd(&lljoin_msgtab); |
| 63 |
} |
| 64 |
|
| 65 |
const char *_version = "$Revision: 1.70 $"; |
| 66 |
#endif |
| 67 |
/* |
| 68 |
* m_lljoin |
| 69 |
* parv[0] = sender prefix |
| 70 |
* parv[1] = channel |
| 71 |
* parv[2] = nick ("!nick" == cjoin) |
| 72 |
* parv[3] = key (optional) |
| 73 |
* |
| 74 |
* If a lljoin is received, from our uplink, join |
| 75 |
* the requested client to the given channel, or ignore it |
| 76 |
* if there is an error. |
| 77 |
* |
| 78 |
* Ok, the way this works. Leaf client tries to join a channel, |
| 79 |
* it doesn't exist so the join does a cburst request on behalf of the |
| 80 |
* client, and aborts that join. The cburst sjoin's the channel if it |
| 81 |
* exists on the hub, and sends back an LLJOIN to the leaf. Thats where |
| 82 |
* this is now.. |
| 83 |
* |
| 84 |
*/ |
| 85 |
static void |
| 86 |
ms_lljoin(struct Client *client_p, struct Client *source_p, |
| 87 |
int parc, char *parv[]) |
| 88 |
{ |
| 89 |
char *chname = NULL; |
| 90 |
char *nick = NULL; |
| 91 |
char *key = NULL; |
| 92 |
int flags; |
| 93 |
int i; |
| 94 |
struct Client *target_p; |
| 95 |
struct Channel *chptr; |
| 96 |
|
| 97 |
if (uplink && !IsCapable(uplink,CAP_LL)) |
| 98 |
{ |
| 99 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 100 |
"*** LLJOIN requested from non LL server %s", |
| 101 |
client_p->name); |
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
chname = parv[1]; |
| 106 |
if(chname == NULL) |
| 107 |
return; |
| 108 |
|
| 109 |
nick = parv[2]; |
| 110 |
if(nick == NULL) |
| 111 |
return; |
| 112 |
|
| 113 |
if (parc >3) |
| 114 |
key = parv[3]; |
| 115 |
|
| 116 |
flags = 0; |
| 117 |
|
| 118 |
target_p = find_person(client_p, nick); |
| 119 |
|
| 120 |
if (!target_p) |
| 121 |
return; |
| 122 |
|
| 123 |
if (!MyClient(target_p)) |
| 124 |
return; |
| 125 |
|
| 126 |
chptr = get_or_create_channel(target_p, chname, NULL); |
| 127 |
flags = CHFL_CHANOP; |
| 128 |
|
| 129 |
if(!chptr) |
| 130 |
return; |
| 131 |
|
| 132 |
if (dlink_list_length(&chptr->members) == 0) |
| 133 |
flags = CHFL_CHANOP; |
| 134 |
else |
| 135 |
flags = 0; |
| 136 |
|
| 137 |
/* XXX in m_join.c :( */ |
| 138 |
/* check_spambot_warning(target_p, chname); */ |
| 139 |
|
| 140 |
/* They _could_ join a channel twice due to lag */ |
| 141 |
if(chptr) |
| 142 |
{ |
| 143 |
if (IsMember(target_p, chptr)) /* already a member, ignore this */ |
| 144 |
return; |
| 145 |
} |
| 146 |
else |
| 147 |
{ |
| 148 |
sendto_one(target_p, form_str(ERR_UNAVAILRESOURCE), |
| 149 |
me.name, nick, chptr->chname); |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
if ((i = can_join(target_p, chptr, key))) |
| 154 |
{ |
| 155 |
sendto_one(target_p, form_str(i), |
| 156 |
me.name, nick, chptr->chname); |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
if ((dlink_list_length(&target_p->channel) >= ConfigChannel.max_chans_per_user) && |
| 161 |
(!IsOper(target_p) || (dlink_list_length(&target_p->channel) >= |
| 162 |
ConfigChannel.max_chans_per_user*3))) |
| 163 |
{ |
| 164 |
sendto_one(target_p, form_str(ERR_TOOMANYCHANNELS), |
| 165 |
me.name, nick, chptr->chname ); |
| 166 |
return; |
| 167 |
} |
| 168 |
|
| 169 |
if (flags == CHFL_CHANOP) |
| 170 |
{ |
| 171 |
chptr->channelts = CurrentTime; |
| 172 |
|
| 173 |
sendto_one(uplink, |
| 174 |
":%s SJOIN %lu %s + :@%s", |
| 175 |
me.name, |
| 176 |
(unsigned long) chptr->channelts, |
| 177 |
chptr->chname, |
| 178 |
nick); |
| 179 |
} |
| 180 |
|
| 181 |
sendto_one(uplink, |
| 182 |
":%s SJOIN %lu %s + :%s", |
| 183 |
me.name, |
| 184 |
(unsigned long) chptr->channelts, |
| 185 |
chptr->chname, |
| 186 |
nick); |
| 187 |
|
| 188 |
add_user_to_channel(chptr, target_p, flags, YES); |
| 189 |
|
| 190 |
sendto_channel_local(ALL_MEMBERS, NO, chptr, |
| 191 |
":%s!%s@%s JOIN :%s", |
| 192 |
target_p->name, |
| 193 |
target_p->username, |
| 194 |
target_p->host, |
| 195 |
chptr->chname); |
| 196 |
|
| 197 |
if (flags & CHFL_CHANOP) |
| 198 |
{ |
| 199 |
chptr->mode.mode |= MODE_TOPICLIMIT; |
| 200 |
chptr->mode.mode |= MODE_NOPRIVMSGS; |
| 201 |
|
| 202 |
sendto_channel_local(ALL_MEMBERS, NO, chptr, |
| 203 |
":%s MODE %s +nt", |
| 204 |
me.name, chptr->chname); |
| 205 |
sendto_one(uplink, |
| 206 |
":%s MODE %s +nt", |
| 207 |
me.name, chptr->chname); |
| 208 |
} |
| 209 |
|
| 210 |
channel_member_names(target_p, chptr, 1); |
| 211 |
} |