]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Someone forgot the blindingly obvious - APPLY the glines/zlines you add! they dont...
[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                         return CMD_FAILURE;
47                 }
48         }
49 };
50
51 /** Handle /GUNLOADMODULE
52  */
53 class cmd_gunloadmodule : public command_t
54 {
55  public:
56         cmd_gunloadmodule (InspIRCd* Instance) : command_t(Instance,"GUNLOADMODULE", 'o', 1)
57         {
58                 this->source = "m_globalload.so";
59                 syntax = "<modulename>";
60         }
61
62         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
63         {
64                 if (ServerInstance->UnloadModule(parameters[0]))
65                 {
66                         ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
67                         user->WriteServ("973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
68                         /* route it! */
69                         return CMD_SUCCESS;
70                 }
71                 else
72                 {
73                         /* XXX - see above note about returning CMD_FAILURE here -- w00t */
74                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
75                         return CMD_FAILURE;
76                 }
77         }
78 };
79
80 /** Handle /GRELOADMODULE
81  */
82 class cmd_greloadmodule : public command_t
83 {
84  public:
85         cmd_greloadmodule (InspIRCd* Instance) : command_t(Instance, "GRELOADMODULE", 'o', 1)
86         {
87                 this->source = "m_globalload.so";
88                 syntax = "<modulename>";
89         }
90
91         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
92         {
93                 if (!ServerInstance->UnloadModule(parameters[0]))
94                 {
95                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
96                         return CMD_FAILURE;
97                 }
98
99                 if (!ServerInstance->LoadModule(parameters[0]))
100                 {
101                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
102                         return CMD_FAILURE;
103                 }
104
105                 ServerInstance->WriteOpers("*** MODULE '%s' GLOBALLY RELOADED BY '%s'",parameters[0],user->nick);
106                 user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
107                 
108                 return CMD_SUCCESS;
109         }
110 };
111
112 class ModuleGlobalLoad : public Module
113 {
114         cmd_gloadmodule *mycommand;
115         cmd_gunloadmodule *mycommand2;
116         cmd_greloadmodule *mycommand3;
117         
118  public:
119         ModuleGlobalLoad(InspIRCd* Me) : Module(Me)
120         {
121                 
122                 mycommand = new cmd_gloadmodule(ServerInstance);
123                 mycommand2 = new cmd_gunloadmodule(ServerInstance);
124                 mycommand3 = new cmd_greloadmodule(ServerInstance);
125                 ServerInstance->AddCommand(mycommand);
126                 ServerInstance->AddCommand(mycommand2);
127                 ServerInstance->AddCommand(mycommand3);
128         }
129         
130         virtual ~ModuleGlobalLoad()
131         {
132         }
133         
134         virtual Version GetVersion()
135         {
136                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
137         }
138 };
139
140
141 class ModuleGlobalLoadFactory : public ModuleFactory
142 {
143  public:
144         ModuleGlobalLoadFactory()
145         {
146         }
147         
148         ~ModuleGlobalLoadFactory()
149         {
150         }
151         
152         virtual Module * CreateModule(InspIRCd* Me)
153         {
154                 return new ModuleGlobalLoad(Me);
155         }
156         
157 };
158
159
160 extern "C" DllExport void * init_module( void )
161 {
162         return new ModuleGlobalLoadFactory;
163 }