]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
8294f53905790976fccbeb38ece6cef6e0552cd3
[user/henk/code/inspircd.git] / src / modules / m_hideoper.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 +H
19  */
20 class HideOper : public ModeHandler
21 {
22  public:
23         HideOper(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, 'H', PARAM_NONE, MODETYPE_USER)
24         {
25                 oper = true;
26         }
27
28         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
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         HideOper hm;
54  public:
55         ModuleHideOper(InspIRCd* Me)
56                 : Module(Me), hm(Me, this)
57         {
58
59                 if (!ServerInstance->Modes->AddMode(&hm))
60                         throw ModuleException("Could not add new modes!");
61                 Implementation eventlist[] = { I_OnWhoisLine };
62                 ServerInstance->Modules->Attach(eventlist, this, 1);
63         }
64
65
66         virtual ~ModuleHideOper()
67         {
68                 ServerInstance->Modes->DelMode(&hm);
69         }
70
71         virtual Version GetVersion()
72         {
73                 return Version("Provides support for hiding oper status with user mode +H", VF_COMMON | VF_VENDOR, API_VERSION);
74         }
75
76         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
77         {
78                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
79                  * person doing the WHOIS is not an oper
80                  */
81                 if (numeric != 313)
82                         return MOD_RES_PASSTHRU;
83
84                 if (!dest->IsModeSet('H'))
85                         return MOD_RES_PASSTHRU;
86
87                 if (!user->HasPrivPermission("users/auspex"))
88                         return MOD_RES_DENY;
89
90                 return MOD_RES_PASSTHRU;
91         }
92
93         void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line)
94         {
95                 if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
96                 {
97                         // hide the "*" that marks the user as an oper from the /WHO line
98                         std::string::size_type pos = line.find("* ");
99                         if (pos != std::string::npos)
100                                 line.erase(pos);
101                 }
102         }
103 };
104
105
106 MODULE_INIT(ModuleHideOper)