]>
Commit | Line | Data |
---|---|---|
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 | |
23 | * | |
24 | * $Id: m_part.c 98 2005-09-11 03:37:47Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "channel.h" | |
29 | #include "client.h" | |
30 | #include "common.h" | |
31 | #include "hash.h" | |
32 | #include "match.h" | |
33 | #include "ircd.h" | |
34 | #include "numeric.h" | |
35 | #include "send.h" | |
36 | #include "s_serv.h" | |
37 | #include "msg.h" | |
38 | #include "parse.h" | |
39 | #include "modules.h" | |
40 | #include "s_conf.h" | |
41 | #include "packet.h" | |
42 | #include "inline/stringops.h" | |
43 | #include "hook.h" | |
44 | ||
45 | static int m_part(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
46 | ||
47 | struct Message part_msgtab = { | |
48 | "PART", 0, 0, 0, 0, | |
49 | {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}} | |
50 | }; | |
51 | ||
52 | mapi_clist_av1 part_clist[] = { &part_msgtab, NULL }; | |
53 | ||
54 | DECLARE_MODULE_AV1(part, NULL, NULL, part_clist, NULL, NULL, "$Revision: 98 $"); | |
55 | ||
56 | static void part_one_client(struct Client *client_p, | |
57 | struct Client *source_p, char *name, | |
58 | const char *reason); | |
59 | static int can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr); | |
60 | static int do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason); | |
61 | ||
62 | ||
63 | /* | |
64 | ** m_part | |
65 | ** parv[1] = channel | |
66 | ** parv[2] = reason | |
67 | */ | |
68 | static int | |
69 | m_part(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
70 | { | |
71 | char *p, *name; | |
72 | char reason[REASONLEN + 1]; | |
73 | char *s = LOCAL_COPY(parv[1]); | |
74 | ||
75 | reason[0] = '\0'; | |
76 | ||
77 | if(parc > 2) | |
78 | rb_strlcpy(reason, parv[2], sizeof(reason)); | |
79 | ||
80 | name = rb_strtok_r(s, ",", &p); | |
81 | ||
82 | /* Finish the flood grace period... */ | |
83 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
84 | flood_endgrace(source_p); | |
85 | ||
86 | while(name) | |
87 | { | |
88 | part_one_client(client_p, source_p, name, reason); | |
89 | name = rb_strtok_r(NULL, ",", &p); | |
90 | } | |
91 | return 0; | |
92 | } | |
93 | ||
94 | /* | |
95 | * part_one_client | |
96 | * | |
97 | * inputs - pointer to server | |
98 | * - pointer to source client to remove | |
99 | * - char pointer of name of channel to remove from | |
100 | * output - none | |
101 | * side effects - remove ONE client given the channel name | |
102 | */ | |
103 | static void | |
104 | part_one_client(struct Client *client_p, struct Client *source_p, char *name, const char *reason) | |
105 | { | |
106 | struct Channel *chptr; | |
107 | struct membership *msptr; | |
108 | ||
109 | if((chptr = find_channel(name)) == NULL) | |
110 | { | |
111 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); | |
112 | return; | |
113 | } | |
114 | ||
115 | msptr = find_channel_membership(chptr, source_p); | |
116 | if(msptr == NULL) | |
117 | { | |
118 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); | |
119 | return; | |
120 | } | |
121 | ||
122 | if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
123 | check_spambot_warning(source_p, NULL); | |
124 | ||
125 | /* | |
126 | * Remove user from the old channel (if any) | |
127 | * only allow /part reasons in -m chans | |
128 | */ | |
129 | if(!EmptyString(reason) && | |
130 | (!MyConnect(source_p) || | |
131 | (can_send_part(source_p, chptr, msptr) && do_message_hook(source_p, chptr, &reason)) | |
132 | ) | |
133 | ) | |
134 | { | |
135 | ||
136 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
137 | ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); | |
138 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s", | |
139 | source_p->name, source_p->username, | |
140 | source_p->host, chptr->chname, reason); | |
141 | } | |
142 | else | |
143 | { | |
144 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, | |
145 | ":%s PART %s", use_id(source_p), chptr->chname); | |
146 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", | |
147 | source_p->name, source_p->username, | |
148 | source_p->host, chptr->chname); | |
149 | } | |
150 | remove_user_from_channel(msptr); | |
151 | } | |
152 | ||
153 | /* | |
154 | * can_send_part - whether a part message can be sent. | |
155 | * | |
156 | * inputs: | |
157 | * - client parting | |
158 | * - channel being parted | |
159 | * - membership pointer | |
160 | * outputs: | |
161 | * - 1 if message allowed | |
162 | * - 0 if message denied | |
163 | * side effects: | |
164 | * - none. | |
165 | */ | |
166 | static int | |
167 | can_send_part(struct Client *source_p, struct Channel *chptr, struct membership *msptr) | |
168 | { | |
169 | if (!can_send(chptr, source_p, msptr)) | |
170 | return 0; | |
171 | /* Allow chanops to bypass anti_spam_exit_message_time for part messages. */ | |
172 | if (is_chanop(msptr)) | |
173 | return 1; | |
174 | return (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time(); | |
175 | } | |
176 | ||
177 | /* | |
178 | * do_message_hook - execute the message hook on a part message reason. | |
179 | * | |
180 | * inputs: | |
181 | * - client parting | |
182 | * - channel being parted | |
183 | * - pointer to reason | |
184 | * outputs: | |
185 | * - 1 if message is allowed | |
186 | * - 0 if message is denied or message is now empty | |
187 | * side effects: | |
188 | * - reason may be modified. | |
189 | */ | |
190 | static int | |
191 | do_message_hook(struct Client *source_p, struct Channel *chptr, const char **reason) | |
192 | { | |
193 | hook_data_privmsg_channel hdata; | |
194 | ||
195 | hdata.msgtype = MESSAGE_TYPE_PART; | |
196 | hdata.source_p = source_p; | |
197 | hdata.chptr = chptr; | |
198 | hdata.text = *reason; | |
199 | hdata.approved = 0; | |
200 | ||
201 | call_hook(h_privmsg_channel, &hdata); | |
202 | ||
203 | /* The reason may have been changed by a hook... */ | |
204 | *reason = hdata.text; | |
205 | ||
206 | return (hdata.approved == 0 && !EmptyString(*reason)); | |
207 | } |