| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file m_part.c |
| 23 |
* \brief Includes required functions for processing the PART command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "list.h" |
| 29 |
#include "channel.h" |
| 30 |
#include "channel_mode.h" |
| 31 |
#include "client.h" |
| 32 |
#include "hash.h" |
| 33 |
#include "irc_string.h" |
| 34 |
#include "ircd.h" |
| 35 |
#include "numeric.h" |
| 36 |
#include "send.h" |
| 37 |
#include "s_serv.h" |
| 38 |
#include "parse.h" |
| 39 |
#include "modules.h" |
| 40 |
#include "conf.h" |
| 41 |
#include "packet.h" |
| 42 |
|
| 43 |
|
| 44 |
/* part_one_client() |
| 45 |
* |
| 46 |
* inputs - pointer to server |
| 47 |
* - pointer to source client to remove |
| 48 |
* - char pointer of name of channel to remove from |
| 49 |
* output - none |
| 50 |
* side effects - remove ONE client given the channel name |
| 51 |
*/ |
| 52 |
static void |
| 53 |
part_one_client(struct Client *source_p, const char *name, const char *reason) |
| 54 |
{ |
| 55 |
struct Channel *chptr = NULL; |
| 56 |
struct Membership *ms = NULL; |
| 57 |
|
| 58 |
if ((chptr = hash_find_channel(name)) == NULL) |
| 59 |
{ |
| 60 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
| 61 |
me.name, source_p->name, name); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
| 66 |
{ |
| 67 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
| 68 |
me.name, source_p->name, name); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
| 73 |
check_spambot_warning(source_p, NULL); |
| 74 |
|
| 75 |
/* |
| 76 |
* Remove user from the old channel (if any) |
| 77 |
* only allow /part reasons in -m chans |
| 78 |
*/ |
| 79 |
if (*reason && (!MyConnect(source_p) || |
| 80 |
((can_send(chptr, source_p, ms, reason) && |
| 81 |
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) |
| 82 |
< CurrentTime)))) |
| 83 |
{ |
| 84 |
sendto_server(source_p->from, CAP_TS6, NOCAPS, |
| 85 |
":%s PART %s :%s", ID(source_p), chptr->chname, |
| 86 |
reason); |
| 87 |
sendto_server(source_p->from, NOCAPS, CAP_TS6, |
| 88 |
":%s PART %s :%s", source_p->name, chptr->chname, |
| 89 |
reason); |
| 90 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s", |
| 91 |
source_p->name, source_p->username, |
| 92 |
source_p->host, chptr->chname, reason); |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
sendto_server(source_p->from, CAP_TS6, NOCAPS, |
| 97 |
":%s PART %s", ID(source_p), chptr->chname); |
| 98 |
sendto_server(source_p->from, NOCAPS, CAP_TS6, |
| 99 |
":%s PART %s", source_p->name, chptr->chname); |
| 100 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
| 101 |
source_p->name, source_p->username, |
| 102 |
source_p->host, chptr->chname); |
| 103 |
} |
| 104 |
|
| 105 |
remove_user_from_channel(ms); |
| 106 |
} |
| 107 |
|
| 108 |
/* |
| 109 |
** m_part |
| 110 |
** parv[0] = sender prefix |
| 111 |
** parv[1] = channel |
| 112 |
** parv[2] = reason |
| 113 |
*/ |
| 114 |
static int |
| 115 |
m_part(struct Client *client_p, struct Client *source_p, |
| 116 |
int parc, char *parv[]) |
| 117 |
{ |
| 118 |
char *p = NULL, *name = NULL; |
| 119 |
char reason[KICKLEN + 1] = { '\0' }; |
| 120 |
|
| 121 |
if (IsServer(source_p)) |
| 122 |
return 0; |
| 123 |
|
| 124 |
if (EmptyString(parv[1])) |
| 125 |
{ |
| 126 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 127 |
me.name, source_p->name, "PART"); |
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
if (parc > 2 && !EmptyString(parv[2])) |
| 132 |
strlcpy(reason, parv[2], sizeof(reason)); |
| 133 |
|
| 134 |
/* Finish the flood grace period... */ |
| 135 |
if (MyClient(source_p) && !IsFloodDone(source_p)) |
| 136 |
flood_endgrace(source_p); |
| 137 |
|
| 138 |
for (name = strtoken(&p, parv[1], ","); name; |
| 139 |
name = strtoken(&p, NULL, ",")) |
| 140 |
part_one_client(source_p, name, reason); |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
static struct Message part_msgtab = |
| 145 |
{ |
| 146 |
"PART", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 147 |
{ m_unregistered, m_part, m_part, m_ignore, m_part, m_ignore } |
| 148 |
}; |
| 149 |
|
| 150 |
static void |
| 151 |
module_init(void) |
| 152 |
{ |
| 153 |
mod_add_cmd(&part_msgtab); |
| 154 |
} |
| 155 |
|
| 156 |
static void |
| 157 |
module_exit(void) |
| 158 |
{ |
| 159 |
mod_del_cmd(&part_msgtab); |
| 160 |
} |
| 161 |
|
| 162 |
struct module module_entry = |
| 163 |
{ |
| 164 |
.node = { NULL, NULL, NULL }, |
| 165 |
.name = NULL, |
| 166 |
.version = "$Revision$", |
| 167 |
.handle = NULL, |
| 168 |
.modinit = module_init, |
| 169 |
.modexit = module_exit, |
| 170 |
.flags = MODULE_FLAG_CORE |
| 171 |
}; |