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