]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
Add OnSendWhoLine hook, and use it in the oper hiding modules
[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(Instance, Creator, '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 (adding)
28                 {
29                         if (!dest->IsModeSet('H'))
30                         {
31                                 dest->SetMode('H',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('H'))
38                         {
39                                 dest->SetMode('H',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModuleHideOper : public Module
49 {
50         HideOper hm;
51  public:
52         ModuleHideOper(InspIRCd* Me)
53                 : Module(Me), hm(Me, this)
54         {
55
56                 if (!ServerInstance->Modes->AddMode(&hm))
57                         throw ModuleException("Could not add new modes!");
58                 Implementation eventlist[] = { I_OnWhoisLine };
59                 ServerInstance->Modules->Attach(eventlist, this, 1);
60         }
61
62
63         virtual ~ModuleHideOper()
64         {
65                 ServerInstance->Modes->DelMode(&hm);
66         }
67
68         virtual Version GetVersion()
69         {
70                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
71         }
72
73         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
74         {
75                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
76                  * person doing the WHOIS is not an oper
77                  */
78                 if (numeric != 313)
79                         return MOD_RES_PASSTHRU;
80
81                 if (!dest->IsModeSet('H'))
82                         return MOD_RES_PASSTHRU;
83
84                 if (!user->HasPrivPermission("users/auspex"))
85                         return MOD_RES_DENY;
86
87                 return MOD_RES_PASSTHRU;
88         }
89
90         void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line)
91         {
92                 if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
93                 {
94                         // hide the "*" that marks the user as an oper from the /WHO line
95                         std::string::size_type pos = line.find("* ");
96                         if (pos != std::string::npos)
97                                 line.erase(pos);
98                 }
99         }
100 };
101
102
103 MODULE_INIT(ModuleHideOper)