]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Annotations
[user/henk/code/inspircd.git] / src / modules / m_globalload.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 /* $ModDesc: Allows global loading of a module. */
20
21 #include <stdio.h>
22 #include "users.h"
23 #include "channels.h"
24 #include "modules.h"
25 #include "inspircd.h"
26
27
28 class cmd_gloadmodule : public command_t
29 {
30  public:
31         cmd_gloadmodule (InspIRCd* Instance) : command_t(Instance,"GLOADMODULE", 'o', 1)
32         {
33                 this->source = "m_globalload.so";
34                 syntax = "<modulename>";
35         }
36
37         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
38         {
39                 if (ServerInstance->LoadModule(parameters[0]))
40                 {
41                         ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
42                         user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
43                         return CMD_SUCCESS;
44                 }
45                 else
46                 {
47                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
48                         return CMD_FAILURE;
49                 }
50         }
51 };
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                         return CMD_SUCCESS;
69                 }
70                 else
71                 {
72                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
73                         return CMD_FAILURE;
74                 }
75         }
76 };
77
78 class ModuleGlobalLoad : public Module
79 {
80         cmd_gloadmodule *mycommand;
81         cmd_gunloadmodule *mycommand2;
82         
83  public:
84         ModuleGlobalLoad(InspIRCd* Me) : Module::Module(Me)
85         {
86                 
87                 mycommand = new cmd_gloadmodule(ServerInstance);
88                 mycommand2 = new cmd_gunloadmodule(ServerInstance);
89                 ServerInstance->AddCommand(mycommand);
90                 ServerInstance->AddCommand(mycommand2);
91         }
92         
93         virtual ~ModuleGlobalLoad()
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1, 0, 0, 0, VF_VENDOR);
100         }
101 };
102
103
104 class ModuleGlobalLoadFactory : public ModuleFactory
105 {
106  public:
107         ModuleGlobalLoadFactory()
108         {
109         }
110         
111         ~ModuleGlobalLoadFactory()
112         {
113         }
114         
115         virtual Module * CreateModule(InspIRCd* Me)
116         {
117                 return new ModuleGlobalLoad(Me);
118         }
119         
120 };
121
122
123 extern "C" void * init_module( void )
124 {
125         return new ModuleGlobalLoadFactory;
126 }