]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
Updates, should be able to safely unload client modules with queries in progress...
[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 #include "helperfuncs.h"
27
28 extern InspIRCd *ServerInstance;
29          
30 class cmd_gloadmodule : public command_t
31 {
32  public:
33         cmd_gloadmodule () : command_t("GLOADMODULE", 'o', 1)
34         {
35                 this->source = "m_globalload.so";
36         }
37
38         void Handle (const char** parameters, int pcnt, userrec *user)
39         {
40                 if (ServerInstance->LoadModule(parameters[0]))
41                 {
42                         WriteOpers("*** NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0],user->nick);
43                         WriteServ(user->fd,"975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
44                 }
45                 else
46                 {
47                         WriteServ(user->fd,"974 %s %s :Failed to load module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
48                 }
49         }
50 };
51
52 class cmd_gunloadmodule : public command_t
53 {
54  public:
55         cmd_gunloadmodule () : command_t("GUNLOADMODULE", 'o', 1)
56         {
57                 this->source = "m_globalload.so";
58         }
59
60         void Handle (const char** parameters, int pcnt, userrec *user)
61         {
62                 if (ServerInstance->UnloadModule(parameters[0]))
63                 {
64                         WriteOpers("*** MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0],user->nick);
65                         WriteServ(user->fd,"973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
66                 }
67                 else
68                 {
69                         WriteServ(user->fd,"972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ServerInstance->ModuleError());
70                 }
71         }
72 };
73
74 class ModuleGlobalLoad : public Module
75 {
76         cmd_gloadmodule *mycommand;
77         cmd_gunloadmodule *mycommand2;
78         Server *Srv;
79  public:
80         ModuleGlobalLoad(Server* Me) : Module::Module(Me)
81         {
82                 Srv = Me;
83                 mycommand = new cmd_gloadmodule();
84                 mycommand2 = new cmd_gunloadmodule();
85                 Srv->AddCommand(mycommand);
86                 Srv->AddCommand(mycommand2);
87         }
88         
89         virtual ~ModuleGlobalLoad()
90         {
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1, 0, 0, 0, VF_VENDOR);
96         }
97 };
98
99
100 class ModuleGlobalLoadFactory : public ModuleFactory
101 {
102  public:
103         ModuleGlobalLoadFactory()
104         {
105         }
106         
107         ~ModuleGlobalLoadFactory()
108         {
109         }
110         
111         virtual Module * CreateModule(Server* Me)
112         {
113                 return new ModuleGlobalLoad(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleGlobalLoadFactory;
122 }