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