]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
5b56ceabe8e7ae0f1164b1ddf7339f8b1ae13ca0
[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 "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style umode +B */
17
18 /** Handles user mode +B
19  */
20 class BotMode : public ModeHandler
21 {
22  public:
23         BotMode(InspIRCd* Instance) : ModeHandler(Instance, 'B', 0, 0, false, MODETYPE_USER, false) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
26         {
27                 if (adding)
28                 {
29                         if (!dest->IsModeSet('B'))
30                         {
31                                 dest->SetMode('B',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('B'))
38                         {
39                                 dest->SetMode('B',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43                 
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModuleBotMode : public Module
49 {
50         
51         BotMode* bm;
52  public:
53         ModuleBotMode(InspIRCd* Me)
54                 : Module(Me)
55         {
56                 
57                 bm = new BotMode(ServerInstance);
58                 if (!ServerInstance->AddMode(bm))
59                         throw ModuleException("Could not add new modes!");
60                 Implementation eventlist[] = { I_OnWhois };
61                 ServerInstance->Modules->Attach(eventlist, this, 1);
62         }
63
64         void Implements(char* List)
65         {
66                 List[I_OnWhois] = 1;
67         }
68         
69         virtual ~ModuleBotMode()
70         {
71                 ServerInstance->Modes->DelMode(bm);
72                 DELETE(bm);
73         }
74         
75         virtual Version GetVersion()
76         {
77                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
78         }
79
80         virtual void OnWhois(User* src, User* dst)
81         {
82                 if (dst->IsModeSet('B'))
83                 {
84                         ServerInstance->SendWhoisLine(src, dst, 335, std::string(src->nick)+" "+std::string(dst->nick)+" :is a bot on "+ServerInstance->Config->Network);
85                 }
86         }
87
88 };
89
90
91 MODULE_INIT(ModuleBotMode)