]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_permchannels.cpp
86e810bc29d3b149da175777e4a8b5df2e61d0d3
[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
42                                 if (channel->GetUserCounter() == 0)
43                                         delete channel;
44                                 return MODEACTION_ALLOW;
45                         }
46                 }
47
48                 return MODEACTION_DENY;
49         }
50 };
51
52 class ModulePermanentChannels : public Module
53 {
54         PermChannel *p;
55 public:
56
57         ModulePermanentChannels(InspIRCd* Me) : Module(Me)
58         {
59                 p = new PermChannel(ServerInstance);
60                 if (!ServerInstance->Modes->AddMode(p))
61                 {
62                         delete p;
63                         throw ModuleException("Could not add new modes!");
64                 }
65                 Implementation eventlist[] = { I_OnChannelPreDelete };
66                 ServerInstance->Modules->Attach(eventlist, this, 1);
67         }
68
69         virtual ~ModulePermanentChannels()
70         {
71                 ServerInstance->Modes->DelMode(p);
72                 delete p;
73         }
74
75         virtual Version GetVersion()
76         {
77                 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
78         }
79
80         virtual int OnChannelPreDelete(Channel *c)
81         {
82                 if (c->IsModeSet('P'))
83                         return 1;
84
85                 return 0;
86         }
87 };
88
89 MODULE_INIT(ModulePermanentChannels)