]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
ce627f44800025a61f35e4458bdfa4bafdaede94
[user/henk/code/inspircd.git] / src / modules / m_hideoper.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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for hiding oper status with user mode +H */
20
21 /** Handles user mode +B
22  */
23 class HideOper : public ModeHandler
24 {
25  public:
26         HideOper(InspIRCd* Instance) : ModeHandler(Instance, 'H', 0, 'o', false, MODETYPE_USER, true) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 if (source != dest)
31                         return MODEACTION_DENY;
32
33                 if (adding)
34                 {
35                         if (!dest->IsModeSet('H'))
36                         {
37                                 dest->SetMode('H',true);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41                 else
42                 {
43                         if (dest->IsModeSet('H'))
44                         {
45                                 dest->SetMode('H',false);
46                                 return MODEACTION_ALLOW;
47                         }
48                 }
49                 
50                 return MODEACTION_DENY;
51         }
52 };
53
54 class ModuleHideOper : public Module
55 {
56         
57         HideOper* hm;
58  public:
59         ModuleHideOper(InspIRCd* Me)
60                 : Module::Module(Me)
61         {
62                 
63                 hm = new HideOper(ServerInstance);
64                 if (!ServerInstance->AddMode(hm, 'H'))
65                         throw ModuleException("Could not add new modes!");
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnWhoisLine] = 1;
71         }
72         
73         virtual ~ModuleHideOper()
74         {
75                 ServerInstance->Modes->DelMode(hm);
76                 DELETE(hm);
77         }
78         
79         virtual Version GetVersion()
80         {
81                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
82         }
83
84         int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
85         {
86                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
87                  * person doing the WHOIS is not an oper
88                  */
89                 return ((!IS_OPER(user)) && (numeric == 313) && dest->IsModeSet('H'));
90         }
91 };
92
93 class ModuleHideOperFactory : public ModuleFactory
94 {
95  public:
96         ModuleHideOperFactory()
97         {
98         }
99         
100         ~ModuleHideOperFactory()
101         {
102         }
103         
104         virtual Module * CreateModule(InspIRCd* Me)
105         {
106                 return new ModuleHideOper(Me);
107         }
108         
109 };
110
111
112 extern "C" void * init_module( void )
113 {
114         return new ModuleHideOperFactory;
115 }