added some debug information to ssl.c
[ircu2.10.12-pk.git] / ircd / m_svspart.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_svspart.c
3  * Written by Pierre Schweitzer.
4  */
5
6 #include "config.h"
7
8 #include "channel.h"
9 #include "client.h"
10 #include "handlers.h"
11 #include "hash.h"
12 #include "ircd.h"
13 #include "ircd_chattr.h"
14 #include "ircd_features.h"
15 #include "ircd_reply.h"
16 #include "ircd_string.h"
17 #include "msg.h"
18 #include "numeric.h"
19 #include "numnicks.h"
20 #include "s_debug.h"
21 #include "s_user.h"
22 #include "send.h"
23
24 #include <string.h>
25 #include <ctype.h>
26 #include <stdlib.h>
27
28 /** SVSPART
29  * SVSPART is forwarded to the server where the user is connected to.
30  * This allows to send SVSPARTs from all servers in the network but additionally causes
31  * some overhead. Though, SVSPART is not often called and this overhead can be ignored.
32  */
33 /* ms_svspart - server message handler
34  *
35  * parv[0] = sender prefix
36  * parv[1] = numeric of client
37  * parv[2] = channel, NO CHANLIST!
38  * parv[3] = comment (optional)
39  */
40 signed int ms_svspart(struct Client* cptr, struct Client* sptr, signed int parc, char* parv[]) {
41     struct Client *acptr;
42     struct Channel *chptr;
43     struct JoinBuf part;
44     struct Membership *member;
45     unsigned int flags = 0;
46     int use_comment;
47
48     if(parc < 3) {
49         return protocol_violation(cptr, "Too few arguments for SVSPART");
50     }
51
52     /* Ignore if the user has already quitted. */
53     if(!(acptr = findNUser(parv[1]))) {
54         return 0;
55     }
56
57     /* Check channelname. */
58     if(!IsChannelName(parv[2]) || !strIsIrcCh(parv[2])) {
59         return 0;
60     }
61
62     /* Get the channel */
63     chptr = get_channel(acptr, parv[2], CGT_NO_CREATE);
64
65     /* Ensure the user is in channel */
66     if (!(member = find_member_link(chptr, acptr))) return 0;
67
68     /* Forward the message to the server where the user is connected to. */
69     if(!MyConnect(acptr)) {
70         if (parc > 3)
71             sendcmdto_one(sptr, CMD_SVSPART, acptr, "%s %s :%s", parv[1], chptr->chname, parv[3]);
72         else
73             sendcmdto_one(sptr, CMD_SVSPART, acptr, "%s %s", parv[1], chptr->chname);
74         return 0;
75     }
76
77     /* Check if we can put part message */
78     use_comment = (parc > 3 && !EmptyString(parv[3]) &&
79                    member_can_send_to_channel(member, 0));
80
81     /* Use join buf to make him leave - use comment if provided */
82     joinbuf_init(&part, acptr, acptr, JOINBUF_TYPE_PART,
83                      use_comment ? parv[3] : 0, 0);
84
85     if (!member_can_send_to_channel(member, 0))
86       flags |= CHFL_BANNED;
87
88     if (IsDelayedJoin(member))
89       flags |= CHFL_DELAYED;
90
91     /* Make the user leave */
92     joinbuf_join(&part, chptr, flags);
93
94     joinbuf_flush(&part);
95
96     return 0;
97 }
98