]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Cut down on debug on restart
[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                 ServerInstance->AddMode(bm, 'B');
69         }
70
71         void Implements(char* List)
72         {
73                 List[I_OnWhois] = 1;
74         }
75         
76         virtual ~ModuleBotMode()
77         {
78                 ServerInstance->Modes->DelMode(bm);
79                 DELETE(bm);
80         }
81         
82         virtual Version GetVersion()
83         {
84                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
85         }
86
87         virtual void OnWhois(userrec* src, userrec* dst)
88         {
89                 if (dst->IsModeSet('B'))
90                 {
91                         ServerInstance->SendWhoisLine(src, dst, 335, std::string(src->nick)+" "+std::string(dst->nick)+" :is a \2bot\2 on "+ServerInstance->Config->Network);
92                 }
93         }
94
95 };
96
97 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
98
99 class ModuleBotModeFactory : public ModuleFactory
100 {
101  public:
102         ModuleBotModeFactory()
103         {
104         }
105         
106         ~ModuleBotModeFactory()
107         {
108         }
109         
110         virtual Module * CreateModule(InspIRCd* Me)
111         {
112                 return new ModuleBotMode(Me);
113         }
114         
115 };
116
117
118 extern "C" void * init_module( void )
119 {
120         return new ModuleBotModeFactory;
121 }