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