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