]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globops.cpp
Review and optimize
[user/henk/code/inspircd.git] / src / modules / m_globops.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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
27 /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */
28
29 Server *Srv;
30
31 class cmd_globops : public command_t
32 {
33  public:
34         cmd_globops () : command_t("GLOBOPS",'o',1)
35         {
36                 this->source = "m_globops.so";
37         }
38         
39         void Handle (char **parameters, int pcnt, userrec *user)
40         {
41                 std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": ";
42                 for (int i = 0; i < pcnt; i++)
43                 {
44                         line = line + std::string(parameters[i]) + " ";
45                 }
46                 Srv->SendToModeMask("og",WM_AND,line);
47         }
48 };
49
50
51 class ModuleGlobops : public Module
52 {
53         cmd_globops* mycommand;
54  public:
55         ModuleGlobops(Server* Me)
56                 : Module::Module(Me)
57         {
58                 Srv = Me;
59                 
60                 if (!Srv->AddExtendedMode('g',MT_CLIENT,true,0,0))
61                 {
62                         Srv->Log(DEFAULT,"*** m_globops: ERROR, failed to allocate user mode +g!");
63                         printf("Could not claim usermode +g for this module!");
64                         return;
65                 }
66                 else
67                 {
68                         mycommand = new cmd_globops();
69                         Srv->AddCommand(mycommand);
70                 }
71         }
72         
73         virtual ~ModuleGlobops()
74         {
75         }
76         
77         virtual Version GetVersion()
78         {
79                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
80         }
81         
82         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
83         {
84                 // check if this is our mode character...
85                 if ((modechar == 'g') && (type == MT_CLIENT))
86                 {
87                         // we dont actually do anything with the mode in this module -
88                         // just tell the core its been claimed and is ok to give users.                         
89                         return 1;
90                 }
91                 else
92                 {
93                         // this mode isn't ours, we have to bail and return 0 to not handle it.
94                         return 0;
95                 }
96         }
97 };
98
99 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
100
101 class ModuleGlobopsFactory : public ModuleFactory
102 {
103  public:
104         ModuleGlobopsFactory()
105         {
106         }
107         
108         ~ModuleGlobopsFactory()
109         {
110         }
111         
112         virtual Module * CreateModule(Server* Me)
113         {
114                 return new ModuleGlobops(Me);
115         }
116         
117 };
118
119
120 extern "C" void * init_module( void )
121 {
122         return new ModuleGlobopsFactory;
123 }
124