1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for channel mode +P to provide permanent channels */
19 /** Handles the +P channel mode
21 class PermChannel : public ModeHandler
24 PermChannel(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
26 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
30 if (!channel->IsModeSet('P'))
32 channel->SetMode('P',true);
33 return MODEACTION_ALLOW;
38 if (channel->IsModeSet('P'))
40 channel->SetMode('P',false);
42 if (channel->GetUserCounter() == 0)
44 return MODEACTION_ALLOW;
48 return MODEACTION_DENY;
52 class ModulePermanentChannels : public Module
57 ModulePermanentChannels(InspIRCd* Me) : Module(Me)
59 p = new PermChannel(ServerInstance);
60 if (!ServerInstance->Modes->AddMode(p))
63 throw ModuleException("Could not add new modes!");
65 Implementation eventlist[] = { I_OnChannelPreDelete };
66 ServerInstance->Modules->Attach(eventlist, this, 1);
71 virtual ~ModulePermanentChannels()
73 ServerInstance->Modes->DelMode(p);
77 virtual void OnRehash(User *user, const std::string ¶meter)
80 * Process config-defined list of permanent channels.
83 ConfigReader MyConf(ServerInstance);
84 for (int i = 0; i < MyConf.Enumerate("permchannels"); i++)
86 std::string channel = MyConf.ReadValue("permchannels", "channel", i);
87 std::string topic = MyConf.ReadValue("permchannels", "topic", i);
88 std::string modes = MyConf.ReadValue("permchannels", "modes", i);
90 if (channel.empty() || topic.empty())
92 ServerInstance->Logs->Log("blah", DEBUG, "Malformed permchannels tag with empty topic or channel name.");
96 Channel *c = ServerInstance->FindChan(channel);
100 c = new Channel(ServerInstance, channel, ServerInstance->Time());
101 c->SetTopic(NULL, topic, true);
102 ServerInstance->Logs->Log("blah", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
107 irc::spacesepstream list(modes);
111 list.GetToken(modeseq);
113 // XXX bleh, should we pass this to the mode parser instead? ugly. --w00t
114 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
116 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
119 if (mode->GetNumParams(true))
124 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, par, true);
131 virtual Version GetVersion()
133 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
136 virtual int OnChannelPreDelete(Channel *c)
138 if (c->IsModeSet('P'))
145 MODULE_INIT(ModulePermanentChannels)