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