Initial import
[ratbox-ambernet.git] / modules / core / m_part.c
blob16d1af80a0210f1036423a361b1c83127a8a70b5
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_part.c: Parts a user from a channel.
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
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.
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.
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
24 * $Id: m_part.c 20702 2005-08-31 20:59:02Z leeh $
27 #include "stdinc.h"
28 #include "tools.h"
29 #include "channel.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"
44 static int m_part(struct Client *, struct Client *, int, const char **);
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}}
51 mapi_clist_av1 part_clist[] = { &part_msgtab, NULL };
52 DECLARE_MODULE_AV1(part, NULL, NULL, part_clist, NULL, NULL, "$Revision: 20702 $");
54 static void part_one_client(struct Client *client_p,
55 struct Client *source_p, char *name, char *reason);
59 ** m_part
60 ** parv[0] = sender prefix
61 ** parv[1] = channel
62 ** parv[2] = reason
64 static int
65 m_part(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
67 char *p, *name;
68 char reason[REASONLEN + 1];
69 char *s = LOCAL_COPY(parv[1]);
71 reason[0] = '\0';
73 if(parc > 2)
74 strlcpy(reason, parv[2], sizeof(reason));
76 name = strtoken(&p, s, ",");
78 /* Finish the flood grace period... */
79 if(MyClient(source_p) && !IsFloodDone(source_p))
80 flood_endgrace(source_p);
82 while (name)
84 part_one_client(client_p, source_p, name, reason);
85 name = strtoken(&p, NULL, ",");
87 return 0;
91 * part_one_client
93 * inputs - pointer to server
94 * - pointer to source client to remove
95 * - char pointer of name of channel to remove from
96 * output - none
97 * side effects - remove ONE client given the channel name
99 static void
100 part_one_client(struct Client *client_p, struct Client *source_p, char *name, char *reason)
102 struct Channel *chptr;
103 struct membership *msptr;
105 if((chptr = find_channel(name)) == NULL)
107 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
108 form_str(ERR_NOSUCHCHANNEL), name);
109 return;
112 msptr = find_channel_membership(chptr, source_p);
113 if(msptr == NULL)
115 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
116 form_str(ERR_NOTONCHANNEL), name);
117 return;
120 if(MyConnect(source_p) && !IsOper(source_p) && !IsExemptSpambot(source_p))
121 check_spambot_warning(source_p, NULL);
124 * Remove user from the old channel (if any)
125 * only allow /part reasons in -m chans
127 if(reason[0] && (is_chanop(msptr) || !MyConnect(source_p) ||
128 ((can_send(chptr, source_p, msptr) > 0 &&
129 (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time)
130 < CurrentTime))))
132 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
133 ":%s PART %s :%s",
134 use_id(source_p), chptr->chname, reason);
135 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
136 ":%s PART %s :%s",
137 source_p->name, 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);
142 else
144 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
145 ":%s PART %s",
146 use_id(source_p), chptr->chname);
147 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
148 ":%s PART %s",
149 source_p->name, chptr->chname);
150 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",
151 source_p->name, source_p->username,
152 source_p->host, chptr->chname);
154 remove_user_from_channel(msptr);