]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Convert all to new Attach() system. The Implements() method needs removing from all...
[user/henk/code/inspircd.git] / src / modules / m_globalload.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 /* $ModDesc: Allows global loading of a module. */
15
16 #include "inspircd.h"
17
18 /** Handle /GLOADMODULE
19  */
20 class CommandGloadmodule : public Command
21 {
22  public:
23         CommandGloadmodule (InspIRCd* Instance) : Command(Instance,"GLOADMODULE", 'o', 1)
24         {
25                 this->source = "m_globalload.so";
26                 syntax = "<modulename> [servermask]";
27                 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, User *user)
31         {
32                 std::string servername = pcnt > 1 ? parameters[1] : "*";
33
34                 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
35                 {
36                         if (ServerInstance->Modules->Load(parameters[0]))
37                         {
38                                 ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
39                                 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
40                         }
41                         else
42                         {
43                                 user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
44                         }
45                 }
46                 else
47                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0],user->nick);
48
49                 return CMD_SUCCESS;
50         }
51 };
52
53 /** Handle /GUNLOADMODULE
54  */
55 class CommandGunloadmodule : public Command
56 {
57  public:
58         CommandGunloadmodule (InspIRCd* Instance) : Command(Instance,"GUNLOADMODULE", 'o', 1)
59         {
60                 this->source = "m_globalload.so";
61                 syntax = "<modulename> [servermask]";
62         }
63
64         CmdResult Handle (const char** parameters, int pcnt, User *user)
65         {
66                 std::string servername = pcnt > 1 ? parameters[1] : "*";
67
68                 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
69                 {
70                         if (ServerInstance->Modules->Unload(parameters[0]))
71                         {
72                                 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
73                                 user->WriteServ("973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
74                         }
75                         else
76                         {
77                                 user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
78                         }
79                 }
80                 else
81                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0],user->nick);
82
83                 return CMD_SUCCESS;
84         }
85 };
86
87 /** Handle /GRELOADMODULE
88  */
89 class CommandGreloadmodule : public Command
90 {
91  public:
92         CommandGreloadmodule (InspIRCd* Instance) : Command(Instance, "GRELOADMODULE", 'o', 1)
93         {
94                 this->source = "m_globalload.so";
95                 syntax = "<modulename> [servermask]";
96         }
97
98         CmdResult Handle(const char** parameters, int pcnt, User *user)
99         {
100                 std::string servername = pcnt > 1 ? parameters[1] : "*";
101
102                 if (ServerInstance->MatchText(ServerInstance->Config->ServerName, servername))
103                 {
104                         if (!ServerInstance->Modules->Unload(parameters[0]))
105                         {
106                                 user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
107                         }
108                         if (!ServerInstance->Modules->Load(parameters[0]))
109                         {
110                                 user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->Modules->LastError());
111                         }
112                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY RELOADED BY '%s'",parameters[0],user->nick);
113                         user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
114                 }
115                 else
116                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0],user->nick);
117
118                 return CMD_SUCCESS;
119         }
120 };
121
122 class ModuleGlobalLoad : public Module
123 {
124         CommandGloadmodule *mycommand;
125         CommandGunloadmodule *mycommand2;
126         CommandGreloadmodule *mycommand3;
127         
128  public:
129         ModuleGlobalLoad(InspIRCd* Me) : Module(Me)
130         {
131                 
132                 mycommand = new CommandGloadmodule(ServerInstance);
133                 mycommand2 = new CommandGunloadmodule(ServerInstance);
134                 mycommand3 = new CommandGreloadmodule(ServerInstance);
135                 ServerInstance->AddCommand(mycommand);
136                 ServerInstance->AddCommand(mycommand2);
137                 ServerInstance->AddCommand(mycommand3);
138
139         }
140         
141         virtual ~ModuleGlobalLoad()
142         {
143         }
144         
145         virtual Version GetVersion()
146         {
147                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
148         }
149 };
150
151 MODULE_INIT(ModuleGlobalLoad)