1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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 sm)
28 if (!source->HasPrivPermission("channels/set-permanent"))
30 source->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - You do not have the required operator privileges", source->nick.c_str());
31 return MODEACTION_DENY;
36 if (!channel->IsModeSet('P'))
38 channel->SetMode('P',true);
39 return MODEACTION_ALLOW;
44 if (channel->IsModeSet('P'))
46 if (channel->GetUserCounter() == 0 && !sm)
51 * We can't delete this channel the way things work at the moment,
52 * because of the following scenario:
55 * s1 has a user in #c, s2 does not. s2 has +P set. s2 has a losing TS.
57 * On netmerge, s2 loses, so s2 removes all modes (including +P) which
58 * would subsequently delete the channel here causing big fucking problems.
60 * I don't think there's really a way around this, so just deny -P on a 0 user chan.
65 return MODEACTION_DENY;
68 /* for servers, remove +P (to avoid desyncs) but don't bother trying to delete. */
69 channel->SetMode('P',false);
70 return MODEACTION_ALLOW;
74 return MODEACTION_DENY;
78 class ModulePermanentChannels : public Module
83 ModulePermanentChannels(InspIRCd* Me) : Module(Me)
85 p = new PermChannel(ServerInstance);
86 if (!ServerInstance->Modes->AddMode(p))
89 throw ModuleException("Could not add new modes!");
91 Implementation eventlist[] = { I_OnChannelPreDelete };
92 ServerInstance->Modules->Attach(eventlist, this, 1);
97 virtual ~ModulePermanentChannels()
99 ServerInstance->Modes->DelMode(p);
103 virtual void OnRehash(User *user, const std::string ¶meter)
106 * Process config-defined list of permanent channels.
109 ConfigReader MyConf(ServerInstance);
110 for (int i = 0; i < MyConf.Enumerate("permchannels"); i++)
112 std::string channel = MyConf.ReadValue("permchannels", "channel", i);
113 std::string topic = MyConf.ReadValue("permchannels", "topic", i);
114 std::string modes = MyConf.ReadValue("permchannels", "modes", i);
118 ServerInstance->Logs->Log("blah", DEBUG, "Malformed permchannels tag with empty channel name.");
122 Channel *c = ServerInstance->FindChan(channel);
126 c = new Channel(ServerInstance, channel, ServerInstance->Time());
128 c->SetTopic(NULL, topic, true);
129 ServerInstance->Logs->Log("blah", DEBUG, "Added %s with topic %s", channel.c_str(), topic.c_str());
134 irc::spacesepstream list(modes);
138 list.GetToken(modeseq);
140 // XXX bleh, should we pass this to the mode parser instead? ugly. --w00t
141 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
143 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
146 if (mode->GetNumParams(true))
151 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, par, true);
158 virtual Version GetVersion()
160 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
163 virtual int OnChannelPreDelete(Channel *c)
165 if (c->IsModeSet('P'))
172 MODULE_INIT(ModulePermanentChannels)