]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hidechans.cpp
Change to use std::string::iterator rather than making a copy of the pointer and...
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for hiding oper status with user mode +I */
20
21 /** Handles user mode +I
22  */
23 class HideChans : public ModeHandler
24 {
25  public:
26         HideChans(InspIRCd* Instance) : ModeHandler(Instance, 'I', 0, 0, false, MODETYPE_USER, true) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 /* Only opers can change other users modes */
31                 if ((source != dest) && (!*source->oper))
32                         return MODEACTION_DENY;
33
34                 if (adding)
35                 {
36                         if (!dest->IsModeSet('I'))
37                         {
38                                 dest->SetMode('I',true);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42                 else
43                 {
44                         if (dest->IsModeSet('I'))
45                         {
46                                 dest->SetMode('I',false);
47                                 return MODEACTION_ALLOW;
48                         }
49                 }
50                 
51                 return MODEACTION_DENY;
52         }
53 };
54
55 class ModuleHideChans : public Module
56 {
57         
58         HideChans* hm;
59  public:
60         ModuleHideChans(InspIRCd* Me)
61                 : Module::Module(Me)
62         {
63                 
64                 hm = new HideChans(ServerInstance);
65                 ServerInstance->AddMode(hm, 'I');
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnWhoisLine] = 1;
71         }
72         
73         virtual ~ModuleHideChans()
74         {
75                 ServerInstance->Modes->DelMode(hm);
76                 DELETE(hm);
77         }
78         
79         virtual Version GetVersion()
80         {
81                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
82         }
83
84         int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
85         {
86                 /* Dont display channels if they have +I set and the
87                  * person doing the WHOIS is not an oper
88                  */
89                 return ((!*user->oper) && (numeric == 319) && dest->IsModeSet('I'));
90         }
91 };
92
93 class ModuleHideChansFactory : public ModuleFactory
94 {
95  public:
96         ModuleHideChansFactory()
97         {
98         }
99         
100         ~ModuleHideChansFactory()
101         {
102         }
103         
104         virtual Module * CreateModule(InspIRCd* Me)
105         {
106                 return new ModuleHideChans(Me);
107         }
108         
109 };
110
111
112 extern "C" void * init_module( void )
113 {
114         return new ModuleHideChansFactory;
115 }