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