]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidechans.cpp
42614e937c877605fc2f272bb1ece6e9d5c8477e
[user/henk/code/inspircd.git] / src / modules / m_hidechans.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 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)
26         {
27                 /* Only opers can change other users modes */
28                 if (source != dest)
29                         return MODEACTION_DENY;
30
31                 if (adding)
32                 {
33                         if (!dest->IsModeSet('I'))
34                         {
35                                 dest->SetMode('I',true);
36                                 return MODEACTION_ALLOW;
37                         }
38                 }
39                 else
40                 {
41                         if (dest->IsModeSet('I'))
42                         {
43                                 dest->SetMode('I',false);
44                                 return MODEACTION_ALLOW;
45                         }
46                 }
47                 
48                 return MODEACTION_DENY;
49         }
50 };
51
52 class ModuleHideChans : public Module
53 {
54         
55         HideChans* hm;
56  public:
57         ModuleHideChans(InspIRCd* Me)
58                 : Module(Me)
59         {
60                 
61                 hm = new HideChans(ServerInstance);
62                 if (!ServerInstance->AddMode(hm))
63                         throw ModuleException("Could not add new modes!");
64         }
65
66         void Implements(char* List)
67         {
68                 List[I_OnWhoisLine] = 1;
69         }
70         
71         virtual ~ModuleHideChans()
72         {
73                 ServerInstance->Modes->DelMode(hm);
74                 DELETE(hm);
75         }
76         
77         virtual Version GetVersion()
78         {
79                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
80         }
81
82         int OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
83         {
84                 /* Dont display channels if they have +I set and the
85                  * person doing the WHOIS is not an oper
86                  */
87                 return ((user != dest) && (!IS_OPER(user)) && (numeric == 319) && dest->IsModeSet('I'));
88         }
89 };
90
91
92 MODULE_INIT(ModuleHideChans)