]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Someone is getting slapped for this; the new hidesplits/hidebans behavior doesn't...
[user/henk/code/inspircd.git] / src / modules / m_botmode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include <string>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "configreader.h"
20 #include "inspircd.h"
21
22 /* $ModDesc: Provides support for unreal-style umode +B */
23
24 /** Handles user mode +B
25  */
26 class BotMode : public ModeHandler
27 {
28  public:
29         BotMode(InspIRCd* Instance) : ModeHandler(Instance, 'B', 0, 0, false, MODETYPE_USER, false) { }
30
31         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
32         {
33                 /* Only opers can change other users modes */
34                 if ((source != dest) && (!*source->oper))
35                         return MODEACTION_DENY;
36
37                 if (adding)
38                 {
39                         if (!dest->IsModeSet('B'))
40                         {
41                                 dest->SetMode('B',true);
42                                 return MODEACTION_ALLOW;
43                         }
44                 }
45                 else
46                 {
47                         if (dest->IsModeSet('B'))
48                         {
49                                 dest->SetMode('B',false);
50                                 return MODEACTION_ALLOW;
51                         }
52                 }
53                 
54                 return MODEACTION_DENY;
55         }
56 };
57
58 class ModuleBotMode : public Module
59 {
60         
61         BotMode* bm;
62  public:
63         ModuleBotMode(InspIRCd* Me)
64                 : Module::Module(Me)
65         {
66                 
67                 bm = new BotMode(ServerInstance);
68                 if (!ServerInstance->AddMode(bm, 'B'))
69                         throw ModuleException("Could not add new modes!");
70         }
71
72         void Implements(char* List)
73         {
74                 List[I_OnWhois] = 1;
75         }
76         
77         virtual ~ModuleBotMode()
78         {
79                 ServerInstance->Modes->DelMode(bm);
80                 DELETE(bm);
81         }
82         
83         virtual Version GetVersion()
84         {
85                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
86         }
87
88         virtual void OnWhois(userrec* src, userrec* dst)
89         {
90                 if (dst->IsModeSet('B'))
91                 {
92                         ServerInstance->SendWhoisLine(src, dst, 335, std::string(src->nick)+" "+std::string(dst->nick)+" :is a bot on "+ServerInstance->Config->Network);
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(InspIRCd* 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 }