]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_part.c: Parts a user from a channel. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 AC |
26 | #include "channel.h" |
27 | #include "client.h" | |
28 | #include "common.h" | |
29 | #include "hash.h" | |
4562c604 | 30 | #include "match.h" |
212380e3 AC |
31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "send.h" | |
34 | #include "s_serv.h" | |
35 | #include "msg.h" | |
36 | #include "parse.h" | |
37 | #include "modules.h" | |
38 | #include "s_conf.h" | |
39 | #include "packet.h" | |
ab428518 | 40 | #include "inline/stringops.h" |
62cf5b40 | 41 | #include "hook.h" |
212380e3 | 42 | |
428ca87b | 43 | static int m_part(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
44 | |
45 | struct Message part_msgtab = { | |
7baa37a9 | 46 | "PART", 0, 0, 0, 0, |
212380e3 AC |
47 | {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}} |
48 | }; | |
49 | ||
50 | mapi_clist_av1 part_clist[] = { &part_msgtab, NULL }; | |
51 | ||
ee6dcb05 EM |
52 | static const char part_desc[] = |
53 | "Provides the PART client and server commands"; | |
54 | ||
55 | DECLARE_MODULE_AV2(part, NULL, NULL, part_clist, NULL, NULL, NULL, NULL, part_desc); | |
212380e3 AC |
56 | |
57 | static void part_one_client(struct Client *client_p, | |
29c451d0 JT |
58 | struct Client *source_p, char *name, |
59 | const char *reason); | |
62cf5b40 | 60 | static int can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr); |
29c451d0 | 61 | static int do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason); |
212380e3 AC |
62 | |
63 | ||
64 | /* | |
65 | ** m_part | |
212380e3 AC |
66 | ** parv[1] = channel |
67 | ** parv[2] = reason | |
68 | */ | |
69 | static int | |
428ca87b | 70 | m_part(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
71 | { |
72 | char *p, *name; | |
73 | char reason[REASONLEN + 1]; | |
74 | char *s = LOCAL_COPY(parv[1]); | |
75 | ||
76 | reason[0] = '\0'; | |
77 | ||
78 | if(parc > 2) | |
f427c8b0 | 79 | rb_strlcpy(reason, parv[2], sizeof(reason)); |
212380e3 | 80 | |
4a2651e5 | 81 | name = rb_strtok_r(s, ",", &p); |
212380e3 AC |
82 | |
83 | /* Finish the flood grace period... */ | |
84 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
85 | flood_endgrace(source_p); | |
86 | ||
212380e3 AC |
87 | while(name) |
88 | { | |
89 | part_one_client(client_p, source_p, name, reason); | |
4a2651e5 | 90 | name = rb_strtok_r(NULL, ",", &p); |
212380e3 AC |
91 | } |
92 | return 0; | |
93 | } | |
94 | ||
95 | /* | |
96 | * part_one_client | |
97 | * | |
98 | * inputs - pointer to server | |
99 | * - pointer to source client to remove | |
100 | * - char pointer of name of channel to remove from | |
101 | * output - none | |
55abcbb2 | 102 | * side effects - remove ONE client given the channel name |
212380e3 AC |
103 | */ |
104 | static void | |
29c451d0 | 105 | part_one_client(struct Client *client_p, struct Client *source_p, char *name, const char *reason) |
212380e3 AC |
106 | { |
107 | struct Channel *chptr; | |
108 | struct membership *msptr; | |
109 | ||
110 | if((chptr = find_channel(name)) == NULL) | |
111 | { | |
112 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); | |
113 | return; | |
114 | } | |
115 | ||
116 | msptr = find_channel_membership(chptr, source_p); | |
117 | if(msptr == NULL) | |
118 | { | |
119 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); | |
120 | return; | |
121 | } | |
122 | ||
123 | if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
124 | check_spambot_warning(source_p, NULL); | |
125 | ||
126 | /* | |
127 | * Remove user from the old channel (if any) | |
128 | * only allow /part reasons in -m chans | |
129 | */ | |
62cf5b40 KB |
130 | if(!EmptyString(reason) && |
131 | (!MyConnect(source_p) || | |
132 | (can_send_part(source_p, chptr, msptr) && do_message_hook(source_p, chptr, &reason)) | |
133 | ) | |
134 | ) | |
212380e3 | 135 | { |
62cf5b40 | 136 | |
212380e3 AC |
137 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
138 | ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); | |
212380e3 AC |
139 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", |
140 | source_p->name, source_p->username, | |
141 | source_p->host, chptr->chname, reason); | |
142 | } | |
143 | else | |
144 | { | |
145 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
146 | ":%s PART %s", use_id(source_p), chptr->chname); | |
212380e3 AC |
147 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", |
148 | source_p->name, source_p->username, | |
149 | source_p->host, chptr->chname); | |
150 | } | |
151 | remove_user_from_channel(msptr); | |
152 | } | |
62cf5b40 KB |
153 | |
154 | /* | |
155 | * can_send_part - whether a part message can be sent. | |
156 | * | |
157 | * inputs: | |
158 | * - client parting | |
159 | * - channel being parted | |
160 | * - membership pointer | |
161 | * outputs: | |
162 | * - 1 if message allowed | |
163 | * - 0 if message denied | |
164 | * side effects: | |
165 | * - none. | |
166 | */ | |
167 | static int | |
168 | can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr) | |
169 | { | |
170 | if (!can_send(chptr, source_p, msptr)) | |
171 | return 0; | |
172 | /* Allow chanops to bypass anti_spam_exit_message_time for part messages. */ | |
173 | if (is_chanop(msptr)) | |
174 | return 1; | |
175 | return (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time(); | |
176 | } | |
177 | ||
178 | /* | |
179 | * do_message_hook - execute the message hook on a part message reason. | |
180 | * | |
181 | * inputs: | |
182 | * - client parting | |
183 | * - channel being parted | |
184 | * - pointer to reason | |
185 | * outputs: | |
186 | * - 1 if message is allowed | |
187 | * - 0 if message is denied or message is now empty | |
188 | * side effects: | |
189 | * - reason may be modified. | |
190 | */ | |
191 | static int | |
29c451d0 | 192 | do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason) |
62cf5b40 KB |
193 | { |
194 | hook_data_privmsg_channel hdata; | |
195 | ||
196 | hdata.msgtype = MESSAGE_TYPE_PART; | |
197 | hdata.source_p = source_p; | |
198 | hdata.chptr = chptr; | |
199 | hdata.text = *reason; | |
200 | hdata.approved = 0; | |
201 | ||
202 | call_hook(h_privmsg_channel, &hdata); | |
203 | ||
204 | /* The reason may have been changed by a hook... */ | |
205 | *reason = hdata.text; | |
206 | ||
207 | return (hdata.approved == 0 && !EmptyString(*reason)); | |
208 | } |