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