| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_part.c: Parts a user from 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 |
knight |
31 |
* $Id$ |
| 23 |
adx |
30 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
michael |
1011 |
#include "list.h" |
| 27 |
adx |
30 |
#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 "s_serv.h" |
| 36 |
|
|
#include "parse.h" |
| 37 |
|
|
#include "modules.h" |
| 38 |
michael |
1309 |
#include "conf.h" |
| 39 |
adx |
30 |
#include "packet.h" |
| 40 |
|
|
|
| 41 |
|
|
|
| 42 |
|
|
/* part_one_client() |
| 43 |
|
|
* |
| 44 |
|
|
* inputs - pointer to server |
| 45 |
|
|
* - pointer to source client to remove |
| 46 |
|
|
* - char pointer of name of channel to remove from |
| 47 |
|
|
* output - none |
| 48 |
|
|
* side effects - remove ONE client given the channel name |
| 49 |
|
|
*/ |
| 50 |
|
|
static void |
| 51 |
michael |
2007 |
part_one_client(struct Client *source_p, const char *name, const char *reason) |
| 52 |
adx |
30 |
{ |
| 53 |
|
|
struct Channel *chptr = NULL; |
| 54 |
|
|
struct Membership *ms = NULL; |
| 55 |
|
|
|
| 56 |
|
|
if ((chptr = hash_find_channel(name)) == NULL) |
| 57 |
|
|
{ |
| 58 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
| 59 |
adx |
30 |
me.name, source_p->name, name); |
| 60 |
|
|
return; |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
| 64 |
|
|
{ |
| 65 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
| 66 |
adx |
30 |
me.name, source_p->name, name); |
| 67 |
|
|
return; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
michael |
1219 |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
| 71 |
adx |
30 |
check_spambot_warning(source_p, NULL); |
| 72 |
|
|
|
| 73 |
|
|
/* |
| 74 |
michael |
2004 |
* Remove user from the old channel (if any) |
| 75 |
|
|
* only allow /part reasons in -m chans |
| 76 |
adx |
30 |
*/ |
| 77 |
michael |
2004 |
if (*reason && (!MyConnect(source_p) || |
| 78 |
michael |
1937 |
((can_send(chptr, source_p, ms, reason) && |
| 79 |
michael |
1241 |
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) |
| 80 |
adx |
30 |
< CurrentTime)))) |
| 81 |
|
|
{ |
| 82 |
michael |
2007 |
sendto_server(source_p->from, CAP_TS6, NOCAPS, |
| 83 |
adx |
30 |
":%s PART %s :%s", ID(source_p), chptr->chname, |
| 84 |
|
|
reason); |
| 85 |
michael |
2007 |
sendto_server(source_p->from, NOCAPS, CAP_TS6, |
| 86 |
adx |
30 |
":%s PART %s :%s", source_p->name, chptr->chname, |
| 87 |
|
|
reason); |
| 88 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s", |
| 89 |
adx |
30 |
source_p->name, source_p->username, |
| 90 |
|
|
source_p->host, chptr->chname, reason); |
| 91 |
|
|
} |
| 92 |
|
|
else |
| 93 |
|
|
{ |
| 94 |
michael |
2007 |
sendto_server(source_p->from, CAP_TS6, NOCAPS, |
| 95 |
adx |
30 |
":%s PART %s", ID(source_p), chptr->chname); |
| 96 |
michael |
2007 |
sendto_server(source_p->from, NOCAPS, CAP_TS6, |
| 97 |
adx |
30 |
":%s PART %s", source_p->name, chptr->chname); |
| 98 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
| 99 |
adx |
30 |
source_p->name, source_p->username, |
| 100 |
|
|
source_p->host, chptr->chname); |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
remove_user_from_channel(ms); |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
/* |
| 107 |
|
|
** m_part |
| 108 |
|
|
** parv[0] = sender prefix |
| 109 |
|
|
** parv[1] = channel |
| 110 |
|
|
** parv[2] = reason |
| 111 |
|
|
*/ |
| 112 |
|
|
static void |
| 113 |
|
|
m_part(struct Client *client_p, struct Client *source_p, |
| 114 |
|
|
int parc, char *parv[]) |
| 115 |
|
|
{ |
| 116 |
michael |
875 |
char *p = NULL, *name = NULL; |
| 117 |
michael |
885 |
char reason[KICKLEN + 1] = { '\0' }; |
| 118 |
adx |
30 |
|
| 119 |
|
|
if (IsServer(source_p)) |
| 120 |
|
|
return; |
| 121 |
|
|
|
| 122 |
michael |
885 |
if (EmptyString(parv[1])) |
| 123 |
adx |
30 |
{ |
| 124 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 125 |
adx |
30 |
me.name, source_p->name, "PART"); |
| 126 |
|
|
return; |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
michael |
1888 |
if (parc > 2 && !EmptyString(parv[2])) |
| 130 |
adx |
30 |
strlcpy(reason, parv[2], sizeof(reason)); |
| 131 |
|
|
|
| 132 |
|
|
/* Finish the flood grace period... */ |
| 133 |
|
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
| 134 |
|
|
flood_endgrace(source_p); |
| 135 |
|
|
|
| 136 |
michael |
885 |
for (name = strtoken(&p, parv[1], ","); name; |
| 137 |
|
|
name = strtoken(&p, NULL, ",")) |
| 138 |
michael |
2007 |
part_one_client(source_p, name, reason); |
| 139 |
adx |
30 |
} |
| 140 |
michael |
1230 |
|
| 141 |
|
|
static struct Message part_msgtab = { |
| 142 |
|
|
"PART", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 143 |
|
|
{ m_unregistered, m_part, m_part, m_ignore, m_part, m_ignore } |
| 144 |
|
|
}; |
| 145 |
|
|
|
| 146 |
|
|
static void |
| 147 |
|
|
module_init(void) |
| 148 |
|
|
{ |
| 149 |
|
|
mod_add_cmd(&part_msgtab); |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
|
|
static void |
| 153 |
|
|
module_exit(void) |
| 154 |
|
|
{ |
| 155 |
|
|
mod_del_cmd(&part_msgtab); |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
struct module module_entry = { |
| 159 |
|
|
.node = { NULL, NULL, NULL }, |
| 160 |
|
|
.name = NULL, |
| 161 |
|
|
.version = "$Revision$", |
| 162 |
|
|
.handle = NULL, |
| 163 |
|
|
.modinit = module_init, |
| 164 |
|
|
.modexit = module_exit, |
| 165 |
|
|
.flags = MODULE_FLAG_CORE |
| 166 |
|
|
}; |