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