]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Blah
[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 <stdio.h>
17 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20 #include "inspircd.h"
21
22 /** Handle /GLOADMODULE
23  */
24 class cmd_gloadmodule : public command_t
25 {
26  public:
27         cmd_gloadmodule (InspIRCd* Instance) : command_t(Instance,"GLOADMODULE", 'o', 1)
28         {
29                 this->source = "m_globalload.so";
30                 syntax = "<modulename>";
31         }
32
33         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
34         {
35                 if (ServerInstance->LoadModule(parameters[0]))
36                 {
37                         ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
38                         user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
39                         return CMD_SUCCESS;
40                 }
41                 else
42                 {
43                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
44                         return CMD_FAILURE;
45                 }
46         }
47 };
48
49 /** Handle /GUNLOADMODULE
50  */
51 class cmd_gunloadmodule : public command_t
52 {
53  public:
54         cmd_gunloadmodule (InspIRCd* Instance) : command_t(Instance,"GUNLOADMODULE", 'o', 1)
55         {
56                 this->source = "m_globalload.so";
57                 syntax = "<modulename>";
58         }
59
60         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
61         {
62                 if (ServerInstance->UnloadModule(parameters[0]))
63                 {
64                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
65                         user->WriteServ("973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
66                         return CMD_SUCCESS;
67                 }
68                 else
69                 {
70                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
71                         return CMD_FAILURE;
72                 }
73         }
74 };
75
76 /** Handle /GRELOADMODULE
77  */
78 class cmd_greloadmodule : public command_t
79 {
80  public:
81         cmd_greloadmodule (InspIRCd* Instance) : command_t(Instance, "GRELOADMODULE", 'o', 1)
82         {
83                 this->source = "m_globalload.so";
84                 syntax = "<modulename>";
85         }
86
87         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
88         {
89                 if (!ServerInstance->UnloadModule(parameters[0]))
90                 {
91                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
92                         return CMD_FAILURE;
93                 }
94
95                 if (!ServerInstance->LoadModule(parameters[0]))
96                 {
97                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
98                         return CMD_FAILURE;
99                 }
100
101                 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY RELOADED BY '%s'",parameters[0],user->nick);
102                 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
103                 
104                 return CMD_SUCCESS;
105         }
106 };
107
108 class ModuleGlobalLoad : public Module
109 {
110         cmd_gloadmodule *mycommand;
111         cmd_gunloadmodule *mycommand2;
112         cmd_greloadmodule *mycommand3;
113         
114  public:
115         ModuleGlobalLoad(InspIRCd* Me) : Module::Module(Me)
116         {
117                 
118                 mycommand = new cmd_gloadmodule(ServerInstance);
119                 mycommand2 = new cmd_gunloadmodule(ServerInstance);
120                 mycommand3 = new cmd_greloadmodule(ServerInstance);
121                 ServerInstance->AddCommand(mycommand);
122                 ServerInstance->AddCommand(mycommand2);
123                 ServerInstance->AddCommand(mycommand3);
124         }
125         
126         virtual ~ModuleGlobalLoad()
127         {
128         }
129         
130         virtual Version GetVersion()
131         {
132                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
133         }
134 };
135
136
137 class ModuleGlobalLoadFactory : public ModuleFactory
138 {
139  public:
140         ModuleGlobalLoadFactory()
141         {
142         }
143         
144         ~ModuleGlobalLoadFactory()
145         {
146         }
147         
148         virtual Module * CreateModule(InspIRCd* Me)
149         {
150                 return new ModuleGlobalLoad(Me);
151         }
152         
153 };
154
155
156 extern "C" void * init_module( void )
157 {
158         return new ModuleGlobalLoadFactory;
159 }