1 |
/* |
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 |
* $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 "s_serv.h" |
36 |
#include "parse.h" |
37 |
#include "modules.h" |
38 |
#include "conf.h" |
39 |
#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 |
part_one_client(struct Client *client_p, struct Client *source_p, |
52 |
const char *name, const char *reason) |
53 |
{ |
54 |
struct Channel *chptr = NULL; |
55 |
struct Membership *ms = NULL; |
56 |
|
57 |
if ((chptr = hash_find_channel(name)) == NULL) |
58 |
{ |
59 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
60 |
me.name, source_p->name, name); |
61 |
return; |
62 |
} |
63 |
|
64 |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
65 |
{ |
66 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
67 |
me.name, source_p->name, name); |
68 |
return; |
69 |
} |
70 |
|
71 |
if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER)) |
72 |
check_spambot_warning(source_p, NULL); |
73 |
|
74 |
/* |
75 |
* Remove user from the old channel (if any) |
76 |
* only allow /part reasons in -m chans |
77 |
*/ |
78 |
if (reason[0] && (!MyConnect(source_p) || |
79 |
((can_send(chptr, source_p, ms) && |
80 |
(source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) |
81 |
< CurrentTime)))) |
82 |
{ |
83 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
84 |
":%s PART %s :%s", ID(source_p), chptr->chname, |
85 |
reason); |
86 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
87 |
":%s PART %s :%s", source_p->name, chptr->chname, |
88 |
reason); |
89 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s", |
90 |
source_p->name, source_p->username, |
91 |
source_p->host, chptr->chname, reason); |
92 |
} |
93 |
else |
94 |
{ |
95 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
96 |
":%s PART %s", ID(source_p), chptr->chname); |
97 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
98 |
":%s PART %s", source_p->name, chptr->chname); |
99 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s", |
100 |
source_p->name, source_p->username, |
101 |
source_p->host, chptr->chname); |
102 |
} |
103 |
|
104 |
remove_user_from_channel(ms); |
105 |
} |
106 |
|
107 |
/* |
108 |
** m_part |
109 |
** parv[0] = sender prefix |
110 |
** parv[1] = channel |
111 |
** parv[2] = reason |
112 |
*/ |
113 |
static void |
114 |
m_part(struct Client *client_p, struct Client *source_p, |
115 |
int parc, char *parv[]) |
116 |
{ |
117 |
char *p = NULL, *name = NULL; |
118 |
char reason[KICKLEN + 1] = { '\0' }; |
119 |
|
120 |
if (IsServer(source_p)) |
121 |
return; |
122 |
|
123 |
if (EmptyString(parv[1])) |
124 |
{ |
125 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
126 |
me.name, source_p->name, "PART"); |
127 |
return; |
128 |
} |
129 |
|
130 |
if (parc > 2) |
131 |
strlcpy(reason, parv[2], sizeof(reason)); |
132 |
|
133 |
/* Finish the flood grace period... */ |
134 |
if (MyClient(source_p) && !IsFloodDone(source_p)) |
135 |
flood_endgrace(source_p); |
136 |
|
137 |
for (name = strtoken(&p, parv[1], ","); name; |
138 |
name = strtoken(&p, NULL, ",")) |
139 |
part_one_client(client_p, source_p, name, reason); |
140 |
} |
141 |
|
142 |
static struct Message part_msgtab = { |
143 |
"PART", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
144 |
{ m_unregistered, m_part, m_part, m_ignore, m_part, m_ignore } |
145 |
}; |
146 |
|
147 |
static void |
148 |
module_init(void) |
149 |
{ |
150 |
mod_add_cmd(&part_msgtab); |
151 |
} |
152 |
|
153 |
static void |
154 |
module_exit(void) |
155 |
{ |
156 |
mod_del_cmd(&part_msgtab); |
157 |
} |
158 |
|
159 |
struct module module_entry = { |
160 |
.node = { NULL, NULL, NULL }, |
161 |
.name = NULL, |
162 |
.version = "$Revision$", |
163 |
.handle = NULL, |
164 |
.modinit = module_init, |
165 |
.modexit = module_exit, |
166 |
.flags = MODULE_FLAG_CORE |
167 |
}; |