]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidechans.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_hidechans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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                 Implementation eventlist[] = { I_OnWhoisLine };
65                 ServerInstance->Modules->Attach(eventlist, this, 1);
66         }
67
68         
69         virtual ~ModuleHideChans()
70         {
71                 ServerInstance->Modes->DelMode(hm);
72                 delete hm;
73         }
74         
75         virtual Version GetVersion()
76         {
77                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
78         }
79
80         int OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
81         {
82                 /* Dont display channels if they have +I set and the
83                  * person doing the WHOIS is not an oper
84                  */
85                 return ((user != dest) && (!IS_OPER(user)) && (numeric == 319) && dest->IsModeSet('I'));
86         }
87 };
88
89
90 MODULE_INIT(ModuleHideChans)