]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Server::GetAdmin, Server::GetServerDescription, Server::GetNetworkName --- *REMOVED*
[user/henk/code/inspircd.git] / src / modules / m_botmode.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 #include <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25 #include "configreader.h"
26 #include "inspircd.h"
27
28 /* $ModDesc: Provides support for unreal-style umode +B */
29
30 extern InspIRCd* ServerInstance;
31
32 class BotMode : public ModeHandler
33 {
34  public:
35         BotMode() : ModeHandler('B', 0, 0, false, MODETYPE_USER, false) { }
36
37         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
38         {
39                 /* Only opers can change other users modes */
40                 if ((source != dest) && (!*source->oper))
41                         return MODEACTION_DENY;
42
43                 if (adding)
44                 {
45                         if (!dest->IsModeSet('B'))
46                         {
47                                 dest->SetMode('B',true);
48                                 return MODEACTION_ALLOW;
49                         }
50                 }
51                 else
52                 {
53                         if (dest->IsModeSet('B'))
54                         {
55                                 dest->SetMode('B',false);
56                                 return MODEACTION_ALLOW;
57                         }
58                 }
59                 
60                 return MODEACTION_DENY;
61         }
62 };
63
64 class ModuleBotMode : public Module
65 {
66         Server *Srv;
67         BotMode* bm;
68  public:
69         ModuleBotMode(Server* Me)
70                 : Module::Module(Me)
71         {
72                 Srv = Me;
73                 bm = new BotMode();
74                 Srv->AddMode(bm, 'B');
75         }
76
77         void Implements(char* List)
78         {
79                 List[I_OnWhois] = 1;
80         }
81         
82         virtual ~ModuleBotMode()
83         {
84                 DELETE(bm);
85         }
86         
87         virtual Version GetVersion()
88         {
89                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
90         }
91
92         virtual void OnWhois(userrec* src, userrec* dst)
93         {
94                 if (dst->IsModeSet('B'))
95                 {
96                         src->WriteServ("335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a \2bot\2 on "+ServerInstance->Config->Network);
97                 }
98         }
99
100 };
101
102 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
103
104 class ModuleBotModeFactory : public ModuleFactory
105 {
106  public:
107         ModuleBotModeFactory()
108         {
109         }
110         
111         ~ModuleBotModeFactory()
112         {
113         }
114         
115         virtual Module * CreateModule(Server* Me)
116         {
117                 return new ModuleBotMode(Me);
118         }
119         
120 };
121
122
123 extern "C" void * init_module( void )
124 {
125         return new ModuleBotModeFactory;
126 }