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