]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Did some renaming so that the methods for modes in chanrec and userrec are identical.
[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
25 /* $ModDesc: Provides support for unreal-style umode +B */
26
27 class BotMode : public ModeHandler
28 {
29         BotMode() : ModeHandler('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                                 user->SetMode('B',true);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41                 else
42                 {
43                         if (dest->IsModeSet('B'))
44                         {
45                                 user->SetMode('B',false);
46                                 return MODEACTION_ALLOW;
47                         }
48                 }
49         }
50 };
51
52 class ModuleBotMode : public Module
53 {
54         Server *Srv; 
55  public:
56         ModuleBotMode(Server* Me)
57                 : Module::Module(Me)
58         {
59                 Srv = Me;
60                 
61                 if (!Srv->AddExtendedMode('B',MT_CLIENT,false,0,0))
62                 {
63                         Srv->Log(DEFAULT,"*** m_botmode: ERROR, failed to allocate user mode +B!");
64                         return;
65                 }
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnWhois] = List[I_OnExtendedMode] = 1;
71         }
72         
73         virtual ~ModuleBotMode()
74         {
75         }
76         
77         virtual Version GetVersion()
78         {
79                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
80         }
81         
82         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
83         {
84                 if ((modechar == 'B') && (type == MT_CLIENT))
85                 {
86                         return 1;
87                 }
88                 else
89                 {
90                         return 0;
91                 }
92         }
93
94         virtual void OnWhois(userrec* src, userrec* dst)
95         {
96                 if (dst->modes['B'-65])
97                 {
98                         Srv->SendTo(NULL,src,"335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a \2bot\2 on "+Srv->GetNetworkName());
99                 }
100         }
101
102 };
103
104 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
105
106 class ModuleBotModeFactory : public ModuleFactory
107 {
108  public:
109         ModuleBotModeFactory()
110         {
111         }
112         
113         ~ModuleBotModeFactory()
114         {
115         }
116         
117         virtual Module * CreateModule(Server* Me)
118         {
119                 return new ModuleBotMode(Me);
120         }
121         
122 };
123
124
125 extern "C" void * init_module( void )
126 {
127         return new ModuleBotModeFactory;
128 }
129