]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Add extra parameter to OnUserPreNotice and OnUserPrePrivmsg, CUList &exempt_list...
[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 /** Handle /GLOADMODULE
28  */
29 class cmd_gloadmodule : public command_t
30 {
31  public:
32         cmd_gloadmodule (InspIRCd* Instance) : command_t(Instance,"GLOADMODULE", 'o', 1)
33         {
34                 this->source = "m_globalload.so";
35                 syntax = "<modulename>";
36         }
37
38         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
39         {
40                 if (ServerInstance->LoadModule(parameters[0]))
41                 {
42                         ServerInstance->WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
43                         user->WriteServ("975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
44                         return CMD_SUCCESS;
45                 }
46                 else
47                 {
48                         user->WriteServ("974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
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                         return CMD_SUCCESS;
72                 }
73                 else
74                 {
75                         user->WriteServ("972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
76                         return CMD_FAILURE;
77                 }
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::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_VENDOR, API_VERSION);
138         }
139 };
140
141
142 class ModuleGlobalLoadFactory : public ModuleFactory
143 {
144  public:
145         ModuleGlobalLoadFactory()
146         {
147         }
148         
149         ~ModuleGlobalLoadFactory()
150         {
151         }
152         
153         virtual Module * CreateModule(InspIRCd* Me)
154         {
155                 return new ModuleGlobalLoad(Me);
156         }
157         
158 };
159
160
161 extern "C" void * init_module( void )
162 {
163         return new ModuleGlobalLoadFactory;
164 }