]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidechans.cpp
This file *BROKEN AGAIN* in windows builds (VC9) - uint_16t and uint_32t do not exist...
[user/henk/code/inspircd.git] / src / modules / m_hidechans.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 channels with user mode +I */
17
18 /** Handles user mode +I
19  */
20 class HideChans : public ModeHandler
21 {
22  public:
23         HideChans(InspIRCd* Instance) : ModeHandler(Instance, 'I', 0, 0, false, MODETYPE_USER, false) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
26         {
27                 if (adding)
28                 {
29                         if (!dest->IsModeSet('I'))
30                         {
31                                 dest->SetMode('I',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('I'))
38                         {
39                                 dest->SetMode('I',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModuleHideChans : public Module
49 {
50         bool AffectsOpers;
51         HideChans* hm;
52  public:
53         ModuleHideChans(InspIRCd* Me) : Module(Me)
54         {
55
56                 hm = new HideChans(ServerInstance);
57                 if (!ServerInstance->Modes->AddMode(hm))
58                         throw ModuleException("Could not add new modes!");
59                 Implementation eventlist[] = { I_OnWhoisLine, I_OnRehash };
60                 ServerInstance->Modules->Attach(eventlist, this, 2);
61                 OnRehash(NULL);
62         }
63
64         virtual ~ModuleHideChans()
65         {
66                 ServerInstance->Modes->DelMode(hm);
67                 delete hm;
68         }
69
70         virtual Version GetVersion()
71         {
72                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
73         }
74
75         virtual void OnRehash(User* user)
76         {
77                 ConfigReader conf(ServerInstance);
78                 AffectsOpers = conf.ReadFlag("hidechans", "affectsopers", 0);
79         }
80
81         int OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
82         {
83                 /* always show to self */
84                 if (user == dest)
85                         return 0;
86
87                 /* don't touch anything except 319 */
88                 if (numeric != 319)
89                         return 0;
90
91                 /* don't touch if -I */
92                 if (!dest->IsModeSet('I'))
93                         return 0;
94
95                 /* if it affects opers, we don't care if they are opered */
96                 if (AffectsOpers)
97                         return 1;
98
99                 /* doesn't affect opers, sender is opered */
100                 if (user->HasPrivPermission("users/auspex"))
101                         return 0;
102
103                 /* user must be opered, boned. */
104                 return 1;
105         }
106 };
107
108
109 MODULE_INIT(ModuleHideChans)