]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globops.cpp
Updates, should be able to safely unload client modules with queries in progress...
[user/henk/code/inspircd.git] / src / modules / m_globops.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 // Globops and +g support module by C.J.Edwards
20
21 #include <stdio.h>
22 #include <string>
23 #include "users.h"
24 #include "channels.h"
25 #include "modules.h"
26 #include "inspircd.h"
27
28 /* $ModDesc: Provides support for GLOBOPS and user mode +g */
29
30 static Server *Srv;
31
32 class cmd_globops : public command_t
33 {
34  public:
35         cmd_globops () : command_t("GLOBOPS",'o',1)
36         {
37                 this->source = "m_globops.so";
38         }
39         
40         void Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": ";
43                 for (int i = 0; i < pcnt; i++)
44                 {
45                         line = line + std::string(parameters[i]) + " ";
46                 }
47                 Srv->SendToModeMask("og",WM_AND,line);
48         }
49 };
50
51 class ModeGlobops : public ModeHandler
52 {
53  public:
54         ModeGlobops() : ModeHandler('g', 0, 0, false, MODETYPE_USER, true) { }
55
56         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
57         {
58                 if (adding)
59                 {
60                         if (!dest->IsModeSet('g'))
61                         {
62                                 dest->SetMode('P',true);
63                                 return MODEACTION_ALLOW;
64                         }
65                 }
66                 else
67                 {
68                         if (dest->IsModeSet('g'))
69                         {
70                                 dest->SetMode('P',false);
71                                 return MODEACTION_ALLOW;
72                         }
73                 }
74
75                 return MODEACTION_DENY;
76         }
77 };
78
79
80 class ModuleGlobops : public Module
81 {
82         cmd_globops* mycommand;
83         ModeGlobops* mg;
84  public:
85         ModuleGlobops(Server* Me)
86                 : Module::Module(Me)
87         {
88                 Srv = Me;
89                 mg = new ModeGlobops();
90                 Srv->AddMode(mg, 'g');
91                 mycommand = new cmd_globops();
92                 Srv->AddCommand(mycommand);
93         }
94         
95         virtual ~ModuleGlobops()
96         {
97                 DELETE(mycommand);
98                 DELETE(mg);
99         }
100         
101         virtual Version GetVersion()
102         {
103                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
104         }
105
106         void Implements(char* List)
107         {
108         }
109 };
110
111 class ModuleGlobopsFactory : public ModuleFactory
112 {
113  public:
114         ModuleGlobopsFactory()
115         {
116         }
117         
118         ~ModuleGlobopsFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(Server* Me)
123         {
124                 return new ModuleGlobops(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleGlobopsFactory;
133 }
134