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