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