]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sapart.cpp
40a4c54e59eb581f101495bb76fba9de8e2286e9
[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 std::vector<std::string>& parameters, 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                         if (parameters.size() == 3)
39                                 reason = parameters[2];
40                         else
41                                 reason = dest->nick;
42
43                         if (ServerInstance->ULine(dest->server))
44                         {
45                                 user->WriteNumeric(990, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
46                                 return CMD_FAILURE;
47                         }
48
49                         /* For local clients, directly part them generating a PART message. For remote clients,
50                          * just return CMD_SUCCESS knowing the protocol module will route the SAPART to the users
51                          * local server and that will generate the PART instead
52                          */
53                         if (IS_LOCAL(dest))
54                         {
55                                 if (!channel->PartUser(dest, reason.c_str()))
56                                         delete channel;
57                                 Channel* n = ServerInstance->FindChan(parameters[1]);
58                                 if (!n)
59                                 {
60                                         ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
61                                         return CMD_SUCCESS;
62                                 }
63                                 else
64                                 {
65                                         if (!n->HasUser(dest))
66                                         {
67                                                 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
68                                                 return CMD_SUCCESS;
69                                         }
70                                         else
71                                         {
72                                                 user->WriteServ("NOTICE %s :*** Unable to make %s part %s",user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str());
73                                                 return CMD_FAILURE;
74                                         }
75                                 }
76                         }
77                         else
78                         {
79                                 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" sent remote SAPART to make "+dest->nick+" part "+parameters[1]);
80                         }
81
82                         return CMD_SUCCESS;
83                 }
84                 else
85                 {
86                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
87                 }
88
89                 return CMD_FAILURE;
90         }
91 };
92
93
94 class ModuleSapart : public Module
95 {
96         CommandSapart*  mycommand;
97  public:
98         ModuleSapart(InspIRCd* Me)
99                 : Module(Me)
100         {
101                 
102                 mycommand = new CommandSapart(ServerInstance);
103                 ServerInstance->AddCommand(mycommand);
104
105         }
106         
107         virtual ~ModuleSapart()
108         {
109         }
110         
111         virtual Version GetVersion()
112         {
113                 return Version(1, 2, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
114         }
115         
116 };
117
118 MODULE_INIT(ModuleSapart)
119