]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidechans.cpp
Add names for all modes (part 1 of named channel mode list)
[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(Module* Creator) : ModeHandler(Creator, "hidechans", 'I', PARAM_NONE, MODETYPE_USER) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
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() : hm(this)
54         {
55                 if (!ServerInstance->Modes->AddMode(&hm))
56                         throw ModuleException("Could not add new modes!");
57                 Implementation eventlist[] = { I_OnWhoisLine, I_OnRehash };
58                 ServerInstance->Modules->Attach(eventlist, this, 2);
59                 OnRehash(NULL);
60         }
61
62         virtual ~ModuleHideChans()
63         {
64         }
65
66         virtual Version GetVersion()
67         {
68                 return Version("Provides support for hiding channels with user mode +I", VF_COMMON | VF_VENDOR, API_VERSION);
69         }
70
71         virtual void OnRehash(User* user)
72         {
73                 ConfigReader conf;
74                 AffectsOpers = conf.ReadFlag("hidechans", "affectsopers", 0);
75         }
76
77         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
78         {
79                 /* always show to self */
80                 if (user == dest)
81                         return MOD_RES_PASSTHRU;
82
83                 /* don't touch anything except 319 */
84                 if (numeric != 319)
85                         return MOD_RES_PASSTHRU;
86
87                 /* don't touch if -I */
88                 if (!dest->IsModeSet('I'))
89                         return MOD_RES_PASSTHRU;
90
91                 /* if it affects opers, we don't care if they are opered */
92                 if (AffectsOpers)
93                         return MOD_RES_DENY;
94
95                 /* doesn't affect opers, sender is opered */
96                 if (user->HasPrivPermission("users/auspex"))
97                         return MOD_RES_PASSTHRU;
98
99                 /* user must be opered, boned. */
100                 return MOD_RES_DENY;
101         }
102 };
103
104
105 MODULE_INIT(ModuleHideChans)