]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globops.cpp
f744895ecfa8e3736fe5472800b5cc79a552276c
[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 extern InspIRCd* ServerInstance;
32
33 class cmd_globops : public command_t
34 {
35  public:
36         cmd_globops () : command_t("GLOBOPS",'o',1)
37         {
38                 this->source = "m_globops.so";
39                 syntax = "<any-text>";
40         }
41         
42         void Handle (const char** parameters, int pcnt, userrec *user)
43         {
44                 std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": ";
45                 for (int i = 0; i < pcnt; i++)
46                 {
47                         line = line + std::string(parameters[i]) + " ";
48                 }
49                 ServerInstance->WriteMode("og",WM_AND,line.c_str());
50         }
51 };
52
53 class ModeGlobops : public ModeHandler
54 {
55  public:
56         ModeGlobops(InspIRCd* Instance) : ModeHandler(Instance, 'g', 0, 0, false, MODETYPE_USER, true) { }
57
58         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
59         {
60                 if (adding)
61                 {
62                         if (!dest->IsModeSet('g'))
63                         {
64                                 dest->SetMode('P',true);
65                                 return MODEACTION_ALLOW;
66                         }
67                 }
68                 else
69                 {
70                         if (dest->IsModeSet('g'))
71                         {
72                                 dest->SetMode('P',false);
73                                 return MODEACTION_ALLOW;
74                         }
75                 }
76
77                 return MODEACTION_DENY;
78         }
79 };
80
81
82 class ModuleGlobops : public Module
83 {
84         cmd_globops* mycommand;
85         ModeGlobops* mg;
86  public:
87         ModuleGlobops(InspIRCd* Me)
88                 : Module::Module(Me)
89         {
90                 
91                 mg = new ModeGlobops(ServerInstance);
92                 Srv->AddMode(mg, 'g');
93                 mycommand = new cmd_globops();
94                 Srv->AddCommand(mycommand);
95         }
96         
97         virtual ~ModuleGlobops()
98         {
99                 DELETE(mycommand);
100                 DELETE(mg);
101         }
102         
103         virtual Version GetVersion()
104         {
105                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
106         }
107
108         void Implements(char* List)
109         {
110         }
111 };
112
113 class ModuleGlobopsFactory : public ModuleFactory
114 {
115  public:
116         ModuleGlobopsFactory()
117         {
118         }
119         
120         ~ModuleGlobopsFactory()
121         {
122         }
123         
124         virtual Module * CreateModule(InspIRCd* Me)
125         {
126                 return new ModuleGlobops(Me);
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleGlobopsFactory;
135 }
136