class PermChannel : public ModeHandler
{
public:
- PermChannel(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
+ PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool sm)
+ ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
if (!source->HasPrivPermission("channels/set-permanent"))
{
{
if (channel->IsModeSet('P'))
{
- if (channel->GetUserCounter() == 0 && !sm)
+ if (channel->GetUserCounter() == 0 && !IS_FAKE(source))
{
/*
* ugh, ugh, UGH!
class ModulePermanentChannels : public Module
{
- PermChannel *p;
+ PermChannel p;
public:
- ModulePermanentChannels(InspIRCd* Me) : Module(Me)
+ ModulePermanentChannels(InspIRCd* Me) : Module(Me), p(Me, this)
{
- p = new PermChannel(ServerInstance);
- if (!ServerInstance->Modes->AddMode(p))
- {
- delete p;
+ if (!ServerInstance->Modes->AddMode(&p))
throw ModuleException("Could not add new modes!");
- }
Implementation eventlist[] = { I_OnChannelPreDelete };
ServerInstance->Modules->Attach(eventlist, this, 1);
- OnRehash(NULL, "");
+ OnRehash(NULL);
}
virtual ~ModulePermanentChannels()
{
- ServerInstance->Modes->DelMode(p);
- delete p;
+ ServerInstance->Modes->DelMode(&p);
+ /*
+ * DelMode can't remove the +P mode on empty channels, or it will break
+ * merging modes with remote servers. Remove the empty channels now as
+ * we know this is not the case.
+ */
+ chan_hash::iterator iter = ServerInstance->chanlist->begin();
+ while (iter != ServerInstance->chanlist->end())
+ {
+ Channel* c = iter->second;
+ if (c->GetUserCounter() == 0)
+ {
+ chan_hash::iterator at = iter;
+ iter++;
+ ServerInstance->chanlist->erase(at);
+ delete c;
+ }
+ else
+ iter++;
+ }
}
- virtual void OnRehash(User *user, const std::string ¶meter)
+ virtual void OnRehash(User *user)
{
/*
* Process config-defined list of permanent channels.
{
c = new Channel(ServerInstance, channel, ServerInstance->Time());
if (!topic.empty())
+ {
c->SetTopic(NULL, topic, true);
+
+ /*
+ * Due to the way protocol works in 1.2, we need to hack the topic TS in such a way that this
+ * topic will always win over others.
+ *
+ * This is scheduled for (proper) fixing in a later release, and can be removed at a later date.
+ */
+ c->topicset = 42;
+ }
ServerInstance->Logs->Log("blah", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
if (modes.empty())
return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
}
- virtual int OnChannelPreDelete(Channel *c)
+ virtual ModResult OnChannelPreDelete(Channel *c)
{
if (c->IsModeSet('P'))
- return 1;
+ return MOD_RES_DENY;
- return 0;
+ return MOD_RES_PASSTHRU;
}
};