]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
b5ae6b32a22a5f520a4602649e787504714b7bcc
[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 "configreader.h"
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for unreal-style umode +B */
28
29 /** Handles user mode +B
30  */
31 class BotMode : public ModeHandler
32 {
33  public:
34         BotMode(InspIRCd* Instance) : ModeHandler(Instance, 'B', 0, 0, false, MODETYPE_USER, false) { }
35
36         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
37         {
38                 /* Only opers can change other users modes */
39                 if ((source != dest) && (!*source->oper))
40                         return MODEACTION_DENY;
41
42                 if (adding)
43                 {
44                         if (!dest->IsModeSet('B'))
45                         {
46                                 dest->SetMode('B',true);
47                                 return MODEACTION_ALLOW;
48                         }
49                 }
50                 else
51                 {
52                         if (dest->IsModeSet('B'))
53                         {
54                                 dest->SetMode('B',false);
55                                 return MODEACTION_ALLOW;
56                         }
57                 }
58                 
59                 return MODEACTION_DENY;
60         }
61 };
62
63 class ModuleBotMode : public Module
64 {
65         
66         BotMode* bm;
67  public:
68         ModuleBotMode(InspIRCd* Me)
69                 : Module::Module(Me)
70         {
71                 
72                 bm = new BotMode(ServerInstance);
73                 ServerInstance->AddMode(bm, 'B');
74         }
75
76         void Implements(char* List)
77         {
78                 List[I_OnWhois] = 1;
79         }
80         
81         virtual ~ModuleBotMode()
82         {
83                 ServerInstance->Modes->DelMode(bm);
84                 DELETE(bm);
85         }
86         
87         virtual Version GetVersion()
88         {
89                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
90         }
91
92         virtual void OnWhois(userrec* src, userrec* dst)
93         {
94                 if (dst->IsModeSet('B'))
95                 {
96                         ServerInstance->SendWhoisLine(src, dst, 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(InspIRCd* 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 }