2 * IRC - Internet Relay Chat, ircd/m_part.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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 1, or (at your option)
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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
94 #include "ircd_reply.h"
95 #include "ircd_string.h"
104 * m_part - generic message handler
106 * parv[0] = sender prefix
108 * parv[parc - 1] = comment
110 int m_part(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
112 struct Channel* chptr;
113 struct Membership* member;
117 char* comment = (parc > 2 && !EmptyString(parv[parc - 1])) ? parv[parc - 1] : 0;
119 *pbuf = '\0'; /* Initialize the part buffer... -Kev */
121 sptr->flags &= ~FLAGS_TS8;
123 if (parc < 2 || parv[1][0] == '\0')
124 return need_more_params(sptr, "PART");
126 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
128 chptr = get_channel(sptr, name, CGT_NO_CREATE);
130 sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
133 if (*name == '&' && !MyUser(sptr))
136 * Do not use find_channel_member here: zombies must be able to part too
138 if (!(member = find_member_link(chptr, sptr)))
140 /* Normal to get when our client did a kick
141 * for a remote client (who sends back a PART),
142 * so check for remote client or not --Run
145 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
149 /* Recreate the /part list for sending to servers */
157 || !member_can_send_to_channel(member)) /* Returns 1 if we CAN send */
159 /* Send part to all clients */
160 if (!IsZombie(member))
163 sendto_channel_butserv(chptr, sptr, PartFmt2, parv[0], chptr->chname,
166 sendto_channel_butserv(chptr, sptr, PartFmt1, parv[0], chptr->chname);
168 else if (MyUser(sptr))
171 sendto_one(sptr, PartFmt2, parv[0], chptr->chname, comment);
173 sendto_one(sptr, PartFmt1, parv[0], chptr->chname);
175 remove_user_from_channel(sptr, chptr);
177 /* Send out the parts to all servers... -Kev */
181 sendto_serv_butone(cptr, PartFmt2serv, NumNick(sptr), pbuf, comment);
183 sendto_serv_butone(cptr, PartFmt1serv, NumNick(sptr), pbuf);
189 * ms_part - server message handler
191 * parv[0] = sender prefix
193 * parv[parc - 1] = comment
195 int ms_part(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
197 struct Channel* chptr;
198 struct Membership* member;
202 char* comment = (parc > 2 && !EmptyString(parv[parc - 1])) ? parv[parc - 1] : 0;
204 *pbuf = '\0'; /* Initialize the part buffer... -Kev */
206 sptr->flags &= ~FLAGS_TS8;
208 if (parc < 2 || parv[1][0] == '\0')
209 return need_more_params(sptr, "PART");
211 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
213 chptr = get_channel(sptr, name, CGT_NO_CREATE);
215 sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
218 if (*name == '&' && !MyUser(sptr))
221 * Do not use find_channel_member here: zombies must be able to part too
223 if (!(member = find_member_link(chptr, sptr)))
225 /* Normal to get when our client did a kick
226 * for a remote client (who sends back a PART),
227 * so check for remote client or not --Run
230 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
234 /* Recreate the /part list for sending to servers */
242 || !member_can_send_to_channel(member)) /* Returns 1 if we CAN send */
244 /* Send part to all clients */
245 if (!IsZombie(member))
248 sendto_channel_butserv(chptr, sptr, PartFmt2, parv[0], chptr->chname,
251 sendto_channel_butserv(chptr, sptr, PartFmt1, parv[0], chptr->chname);
253 else if (MyUser(sptr))
256 sendto_one(sptr, PartFmt2, parv[0], chptr->chname, comment);
258 sendto_one(sptr, PartFmt1, parv[0], chptr->chname);
260 remove_user_from_channel(sptr, chptr);
262 /* Send out the parts to all servers... -Kev */
266 sendto_serv_butone(cptr, PartFmt2serv, NumNick(sptr), pbuf, comment);
268 sendto_serv_butone(cptr, PartFmt1serv, NumNick(sptr), pbuf);
277 * parv[0] = sender prefix
279 * parv[parc - 1] = comment
281 int m_part(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
283 struct Channel* chptr;
284 struct Membership* member;
288 char* comment = (parc > 2 && !EmptyString(parv[parc - 1])) ? parv[parc - 1] : 0;
290 *pbuf = '\0'; /* Initialize the part buffer... -Kev */
292 sptr->flags &= ~FLAGS_TS8;
294 if (parc < 2 || parv[1][0] == '\0')
295 return need_more_params(sptr, "PART");
297 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
299 chptr = get_channel(sptr, name, CGT_NO_CREATE);
301 sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
304 if (*name == '&' && !MyUser(sptr))
307 * Do not use find_channel_member here: zombies must be able to part too
309 if (!(member = find_member_link(chptr, sptr)))
311 /* Normal to get when our client did a kick
312 * for a remote client (who sends back a PART),
313 * so check for remote client or not --Run
316 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
320 /* Recreate the /part list for sending to servers */
328 || !member_can_send_to_channel(member)) /* Returns 1 if we CAN send */
330 /* Send part to all clients */
331 if (!IsZombie(member))
334 sendto_channel_butserv(chptr, sptr, PartFmt2, parv[0], chptr->chname,
337 sendto_channel_butserv(chptr, sptr, PartFmt1, parv[0], chptr->chname);
339 else if (MyUser(sptr))
342 sendto_one(sptr, PartFmt2, parv[0], chptr->chname, comment);
344 sendto_one(sptr, PartFmt1, parv[0], chptr->chname);
346 remove_user_from_channel(sptr, chptr);
348 /* Send out the parts to all servers... -Kev */
352 sendto_serv_butone(cptr, PartFmt2serv, NumNick(sptr), pbuf, comment);
354 sendto_serv_butone(cptr, PartFmt1serv, NumNick(sptr), pbuf);