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