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