]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Opers haven't been able to change the modes of others since 1.0.
[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                 if (adding)
34                 {
35                         if (!dest->IsModeSet('B'))
36                         {
37                                 dest->SetMode('B',true);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41                 else
42                 {
43                         if (dest->IsModeSet('B'))
44                         {
45                                 dest->SetMode('B',false);
46                                 return MODEACTION_ALLOW;
47                         }
48                 }
49                 
50                 return MODEACTION_DENY;
51         }
52 };
53
54 class ModuleBotMode : public Module
55 {
56         
57         BotMode* bm;
58  public:
59         ModuleBotMode(InspIRCd* Me)
60                 : Module::Module(Me)
61         {
62                 
63                 bm = new BotMode(ServerInstance);
64                 if (!ServerInstance->AddMode(bm, 'B'))
65                         throw ModuleException("Could not add new modes!");
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnWhois] = 1;
71         }
72         
73         virtual ~ModuleBotMode()
74         {
75                 ServerInstance->Modes->DelMode(bm);
76                 DELETE(bm);
77         }
78         
79         virtual Version GetVersion()
80         {
81                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
82         }
83
84         virtual void OnWhois(userrec* src, userrec* dst)
85         {
86                 if (dst->IsModeSet('B'))
87                 {
88                         ServerInstance->SendWhoisLine(src, dst, 335, std::string(src->nick)+" "+std::string(dst->nick)+" :is a bot on "+ServerInstance->Config->Network);
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(InspIRCd* 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 }