]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sapart.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_sapart.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style SAPART command */
17
18 /** Handle /SAPART
19  */
20 class CommandSapart : public Command
21 {
22  public:
23         CommandSapart (InspIRCd* Instance) : Command(Instance,"SAPART", 'o', 2, false, 0)
24         {
25                 this->source = "m_sapart.so";
26                 syntax = "<nick> <channel> [reason]";
27                 TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, User *user)
31         {
32                 User* dest = ServerInstance->FindNick(parameters[0]);
33                 Channel* channel = ServerInstance->FindChan(parameters[1]);
34                 std::string reason;
35
36                 if (dest && channel)
37                 {
38                         ServerInstance->Log(DEBUG, "SAPART: pcnt is %d", pcnt);
39                         if (pcnt == 3)
40                                 reason = parameters[2];
41                         else
42                                 reason = dest->nick;
43
44                         if (ServerInstance->ULine(dest->server))
45                         {
46                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
47                                 return CMD_FAILURE;
48                         }
49
50                         /* For local clients, directly part them generating a PART message. For remote clients,
51                          * just return CMD_SUCCESS knowing the protocol module will route the SAPART to the users
52                          * local server and that will generate the PART instead
53                          */
54                         if (IS_LOCAL(dest))
55                         {
56                                 if (!channel->PartUser(dest, reason.c_str()))
57                                         delete channel;
58                                 Channel* n = ServerInstance->FindChan(parameters[1]);
59                                 if (!n)
60                                 {
61                                         ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
62                                         return CMD_SUCCESS;
63                                 }
64                                 else
65                                 {
66                                         if (!n->HasUser(dest))
67                                         {
68                                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
69                                                 return CMD_SUCCESS;
70                                         }
71                                         else
72                                         {
73                                                 user->WriteServ("NOTICE %s :*** Unable to make %s part %s",user->nick, dest->nick, parameters[1]);
74                                                 return CMD_FAILURE;
75                                         }
76                                 }
77                         }
78                         else
79                         {
80                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" sent remote SAPART to make "+dest->nick+" part "+parameters[1]);
81                         }
82
83                         return CMD_SUCCESS;
84                 }
85                 else
86                 {
87                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick);
88                 }
89
90                 return CMD_FAILURE;
91         }
92 };
93
94
95 class ModuleSapart : public Module
96 {
97         CommandSapart*  mycommand;
98  public:
99         ModuleSapart(InspIRCd* Me)
100                 : Module(Me)
101         {
102                 
103                 mycommand = new CommandSapart(ServerInstance);
104                 ServerInstance->AddCommand(mycommand);
105
106         }
107         
108         virtual ~ModuleSapart()
109         {
110         }
111         
112         virtual Version GetVersion()
113         {
114                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
115         }
116         
117 };
118
119 MODULE_INIT(ModuleSapart)
120