]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/core/m_part.c
Branch Merge
[irc/rqf/shadowircd.git] / modules / core / m_part.c
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 */
25
26 #include "stdinc.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "common.h"
30 #include "hash.h"
31 #include "match.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "send.h"
35 #include "s_serv.h"
36 #include "msg.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "s_conf.h"
40 #include "packet.h"
41 #include "inline/stringops.h"
42 #include "channel.h"
43
44 static int m_part(struct Client *, struct Client *, int, const char **);
45
46 struct Message part_msgtab = {
47 "PART", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}}
49 };
50
51 mapi_clist_av1 part_clist[] = { &part_msgtab, NULL };
52
53 DECLARE_MODULE_AV1(part, NULL, NULL, part_clist, NULL, NULL, "$Revision: 98 $");
54
55 static void part_one_client(struct Client *client_p,
56 struct Client *source_p, char *name, char *reason);
57
58 struct module_modes ModuleModes;
59
60 /*
61 ** m_part
62 ** parv[1] = channel
63 ** parv[2] = reason
64 */
65 static int
66 m_part(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
67 {
68 char *p, *name;
69 char reason[REASONLEN + 1];
70 char *s = LOCAL_COPY(parv[1]);
71
72 reason[0] = '\0';
73
74 if(parc > 2)
75 rb_strlcpy(reason, parv[2], sizeof(reason));
76
77 name = rb_strtok_r(s, ",", &p);
78
79 /* Finish the flood grace period... */
80 if(MyClient(source_p) && !IsFloodDone(source_p))
81 flood_endgrace(source_p);
82
83 while(name)
84 {
85 part_one_client(client_p, source_p, name, reason);
86 name = rb_strtok_r(NULL, ",", &p);
87 }
88 return 0;
89 }
90
91 /*
92 * part_one_client
93 *
94 * inputs - pointer to server
95 * - pointer to source client to remove
96 * - char pointer of name of channel to remove from
97 * output - none
98 * side effects - remove ONE client given the channel name
99 */
100 static void
101 part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason)
102 {
103 struct Channel *chptr;
104 struct membership *msptr;
105 char reason2[BUFSIZE];
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 */
127 if(reason[0] && (is_any_op(msptr) || !MyConnect(source_p) ||
128 ((can_send(chptr, source_p, msptr) > 0 && ConfigFileEntry.use_part_messages &&
129 (source_p->localClient->firsttime +
130 ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time()))))
131 {
132 if(chptr->mode.mode & ModuleModes.MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr)))
133 {
134 rb_strlcpy(reason2, reason, BUFSIZE);
135 strip_colour(reason2);
136 reason = reason2;
137 }
138 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
139 ":%s PART %s :%s", use_id(source_p), chptr->chname, reason);
140 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
141 source_p->name, source_p->username,
142 source_p->host, chptr->chname, reason);
143 }
144 else
145 {
146 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
147 ":%s PART %s", use_id(source_p), chptr->chname);
148 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",
149 source_p->name, source_p->username,
150 source_p->host, chptr->chname);
151 }
152 remove_user_from_channel(msptr);
153 }