]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globops.cpp
Actually compiles now :p
[user/henk/code/inspircd.git] / src / modules / m_globops.cpp
1 // Globops and +g support module by C.J.Edwards
2
3 #include <stdio.h>
4 #include <string>
5 #include "users.h"
6 #include "channels.h"
7 #include "modules.h"
8
9 /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */
10
11 Server *Srv;
12          
13 void handle_globops(char **parameters, int pcnt, userrec *user)
14 {
15         std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": ";
16         for (int i = 0; i < pcnt; i++)
17         {
18                 line = line + std::string(parameters[i]) + " ";
19         }
20         Srv->SendToModeMask("og",WM_AND,line);
21 }
22
23
24 class ModuleGlobops : public Module
25 {
26  public:
27         ModuleGlobops()
28         {
29                 Srv = new Server;
30                 
31                 if (!Srv->AddExtendedMode('g',MT_CLIENT,true,0,0))
32                 {
33                         Srv->Log(DEFAULT,"*** m_globops: ERROR, failed to allocate user mode +g!");
34                         printf("Could not claim usermode +g for this module!");
35                         exit(0);
36                 }
37                 Srv->AddCommand("GLOBOPS",handle_globops,'o',1);
38         }
39         
40         virtual ~ModuleGlobops()
41         {
42                 delete Srv;
43         }
44         
45         virtual Version GetVersion()
46         {
47                 return Version(1,0,0,1);
48         }
49         
50         virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
51         {
52                 // check if this is our mode character...
53                 if ((modechar == 'g') && (type == MT_CLIENT))
54                 {
55                         // we dont actually do anything with the mode in this module -
56                         // just tell the core its been claimed and is ok to give users.                         
57                         return 1;
58                 }
59                 else
60                 {
61                         // this mode isn't ours, we have to bail and return 0 to not handle it.
62                         return 0;
63                 }
64         }
65
66         virtual void OnOper(userrec* user)
67         {
68                 char* modes[2];                 // only two parameters
69                 modes[0] = user->nick;          // first parameter is the nick
70                 modes[1] = "+g";                // second parameter is the mode
71                 Srv->SendMode(modes,2,user);    // send these, forming the command "MODE <nick> +g"
72         }
73
74 };
75
76 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
77
78 class ModuleGlobopsFactory : public ModuleFactory
79 {
80  public:
81         ModuleGlobopsFactory()
82         {
83         }
84         
85         ~ModuleGlobopsFactory()
86         {
87         }
88         
89         virtual Module * CreateModule()
90         {
91                 return new ModuleGlobops;
92         }
93         
94 };
95
96
97 extern "C" void * init_module( void )
98 {
99         return new ModuleGlobopsFactory;
100 }
101