]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sapart.cpp
Refactor port binding, warning not yet tested fully
[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 <stdio.h>
15 #include <string>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "inspircd.h"
20
21 /* $ModDesc: Provides support for unreal-style SAPART command */
22
23 /** Handle /SAPART
24  */
25 class cmd_sapart : public command_t
26 {
27  public:
28         cmd_sapart (InspIRCd* Instance) : command_t(Instance,"SAPART", 'o', 2)
29         {
30                 this->source = "m_sapart.so";
31                 syntax = "<nick> <channel>";
32         }
33
34         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
35         {
36                 userrec* dest = ServerInstance->FindNick(parameters[0]);
37                 chanrec* channel = ServerInstance->FindChan(parameters[1]);
38                 if (dest && channel)
39                 {
40                         if (ServerInstance->ULine(dest->server))
41                         {
42                                 user->WriteServ("990 %s :Cannot use an SA command on a u-lined client",user->nick);
43                                 return CMD_FAILURE;
44                         }
45
46                         /* For local clients, directly part them generating a PART message. For remote clients,
47                          * just return CMD_SUCCESS knowing the protocol module will route the SAPART to the users
48                          * local server and that will generate the PART instead
49                          */
50                         if (IS_LOCAL(dest))
51                         {
52                                 if (!channel->PartUser(dest, dest->nick))
53                                         delete channel;
54                                 chanrec* n = ServerInstance->FindChan(parameters[1]);
55                                 if (!n)
56                                 {
57                                         ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
58                                         return CMD_SUCCESS;
59                                 }
60                                 else
61                                 {
62                                         if (!n->HasUser(dest))
63                                         {
64                                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
65                                                 return CMD_SUCCESS;
66                                         }
67                                         else
68                                         {
69                                                 user->WriteServ("NOTICE %s :*** Unable to make %s part %s",user->nick, dest->nick, parameters[1]);
70                                                 return CMD_FAILURE;
71                                         }
72                                 }
73                         }
74                         else
75                         {
76                                 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" sent remote SAPART to make "+dest->nick+" part "+parameters[1]);
77                         }
78
79                         return CMD_SUCCESS;
80                 }
81                 else
82                 {
83                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick);
84                 }
85
86                 return CMD_FAILURE;
87         }
88 };
89
90
91 class ModuleSapart : public Module
92 {
93         cmd_sapart*     mycommand;
94  public:
95         ModuleSapart(InspIRCd* Me)
96                 : Module::Module(Me)
97         {
98                 
99                 mycommand = new cmd_sapart(ServerInstance);
100                 ServerInstance->AddCommand(mycommand);
101         }
102         
103         virtual ~ModuleSapart()
104         {
105         }
106         
107         virtual Version GetVersion()
108         {
109                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
110         }
111         
112 };
113
114 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
115
116 class ModuleSapartFactory : public ModuleFactory
117 {
118  public:
119         ModuleSapartFactory()
120         {
121         }
122         
123         ~ModuleSapartFactory()
124         {
125         }
126         
127         virtual Module * CreateModule(InspIRCd* Me)
128         {
129                 return new ModuleSapart(Me);
130         }
131         
132 };
133
134
135 extern "C" void * init_module( void )
136 {
137         return new ModuleSapartFactory;
138 }
139