]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
f65e01d883f44bf5c4392b761f42d928c73b371d
[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 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20
21 /** Handle /GLOADMODULE
22  */
23 class cmd_gloadmodule : public command_t
24 {
25  public:
26         cmd_gloadmodule (InspIRCd* Instance) : command_t(Instance,"GLOADMODULE", 'o', 1)
27         {
28                 this->source = "m_globalload.so";
29                 syntax = "<modulename>";
30         }
31
32         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
33         {
34                 if (ServerInstance->LoadModule(parameters[0]))
35                 {
36                         ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
37                         user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
38
39                         /* route it! */
40                         return CMD_SUCCESS;
41                 }
42                 else
43                 {
44                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
45                         /* XXX - returning CMD_FAILURE here could potentially mean half the net loads it, half doesn't. pass it on anyway? -- w00t
46                          *
47                          * Returning CMD_SUCCESS would have the same effect, just with less servers. Someone should update this module to properly
48                          * pass the success/failure for each server to the caller (or to all opers) -Special */
49                         return CMD_FAILURE;
50                 }
51         }
52 };
53
54 /** Handle /GUNLOADMODULE
55  */
56 class cmd_gunloadmodule : public command_t
57 {
58  public:
59         cmd_gunloadmodule (InspIRCd* Instance) : command_t(Instance,"GUNLOADMODULE", 'o', 1)
60         {
61                 this->source = "m_globalload.so";
62                 syntax = "<modulename>";
63         }
64
65         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
66         {
67                 if (ServerInstance->UnloadModule(parameters[0]))
68                 {
69                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
70                         user->WriteServ("973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
71                 }
72                 else
73                 {
74                         /* Return CMD_SUCCESS so the module will be unloaded on any servers it is loaded on - this is a seperate case entirely from loading -Special */
75                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
76                 }
77                 return CMD_SUCCESS;
78         }
79 };
80
81 /** Handle /GRELOADMODULE
82  */
83 class cmd_greloadmodule : public command_t
84 {
85  public:
86         cmd_greloadmodule (InspIRCd* Instance) : command_t(Instance, "GRELOADMODULE", 'o', 1)
87         {
88                 this->source = "m_globalload.so";
89                 syntax = "<modulename>";
90         }
91
92         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
93         {
94                 if (!ServerInstance->UnloadModule(parameters[0]))
95                 {
96                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
97                         return CMD_FAILURE;
98                 }
99
100                 if (!ServerInstance->LoadModule(parameters[0]))
101                 {
102                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
103                         return CMD_FAILURE;
104                 }
105
106                 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY RELOADED BY '%s'",parameters[0],user->nick);
107                 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
108                 
109                 return CMD_SUCCESS;
110         }
111 };
112
113 class ModuleGlobalLoad : public Module
114 {
115         cmd_gloadmodule *mycommand;
116         cmd_gunloadmodule *mycommand2;
117         cmd_greloadmodule *mycommand3;
118         
119  public:
120         ModuleGlobalLoad(InspIRCd* Me) : Module(Me)
121         {
122                 
123                 mycommand = new cmd_gloadmodule(ServerInstance);
124                 mycommand2 = new cmd_gunloadmodule(ServerInstance);
125                 mycommand3 = new cmd_greloadmodule(ServerInstance);
126                 ServerInstance->AddCommand(mycommand);
127                 ServerInstance->AddCommand(mycommand2);
128                 ServerInstance->AddCommand(mycommand3);
129         }
130         
131         virtual ~ModuleGlobalLoad()
132         {
133         }
134         
135         virtual Version GetVersion()
136         {
137                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
138         }
139 };
140
141 MODULE_INIT(ModuleGlobalLoad)