]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_permchannels.cpp
f24a908004a5dc4aff18588c3a95df09ae5936f5
[user/henk/code/inspircd.git] / src / modules / m_permchannels.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 channel mode +P to provide permanent channels */
17
18
19 /** Handles the +P channel mode
20  */
21 class PermChannel : public ModeHandler
22 {
23  public:
24         PermChannel(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
25
26         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
27         {
28                 if (adding)
29                 {
30                         if (!channel->IsModeSet('P'))
31                         {
32                                 channel->SetMode('P',true);
33                                 return MODEACTION_ALLOW;
34                         }
35                 }
36                 else
37                 {
38                         if (channel->IsModeSet('P'))
39                         {
40                                 channel->SetMode('P',false);
41                                 return MODEACTION_ALLOW;
42                         }
43                 }
44
45                 return MODEACTION_DENY;
46         }
47 };
48
49 class ModulePermanentChannels : public Module
50 {
51         PermChannel *p;
52 public:
53         
54         ModulePermanentChannels(InspIRCd* Me) : Module(Me)
55         {
56                 p = new PermChannel(ServerInstance);
57                 if (!ServerInstance->Modes->AddMode(p))
58                 {
59                         delete p;
60                         throw ModuleException("Could not add new modes!");
61                 }
62                 Implementation eventlist[] = { I_OnChannelPreDelete };
63                 ServerInstance->Modules->Attach(eventlist, this, 1);
64         }
65
66         virtual ~ModulePermanentChannels()
67         {
68                 ServerInstance->Modes->DelMode(p);
69                 delete p;
70         }
71
72         virtual Version GetVersion()
73         {
74                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
75         }
76
77         virtual int OnChannelPreDelete(Channel *c)
78         {
79                 if (c->IsModeSet('P'))
80                         return 1;
81
82                 return 0;
83         }
84 };
85
86 MODULE_INIT(ModulePermanentChannels)