2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2014-2016 Attila Molnar <attilamolnar@hush.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class CommandSVSTOPIC : public Command
31 CommandSVSTOPIC(Module* Creator)
32 : Command(Creator, "SVSTOPIC", 1, 4)
34 flags_needed = FLAG_SERVERONLY;
37 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
39 if (!user->server->IsULine())
45 Channel* chan = ServerInstance->FindChan(parameters[0]);
49 if (parameters.size() == 4)
51 // 4 parameter version, set all topic data on the channel to the ones given in the parameters
52 time_t topicts = ConvToNum<time_t>(parameters[1]);
55 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped.");
59 chan->SetTopic(user, parameters[3], topicts, ¶meters[2]);
63 // 1 parameter version, nuke the topic
64 chan->SetTopic(user, std::string(), 0);
71 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
73 return ROUTE_BROADCAST;
77 // TODO: add a BoolExtItem to replace this.
78 class FlagExtItem : public ExtensionItem
81 FlagExtItem(const std::string& key, Module* owner)
82 : ExtensionItem(key, ExtensionItem::EXT_CHANNEL, owner)
86 bool get(const Extensible* container) const
88 return (get_raw(container) != NULL);
91 std::string ToHuman(const Extensible* container, void* item) const CXX11_OVERRIDE
93 // Make the human version more readable.
97 std::string ToNetwork(const Extensible* container, void* item) const CXX11_OVERRIDE
102 void FromNetwork(Extensible* container, const std::string& value) CXX11_OVERRIDE
105 set_raw(container, this);
107 unset_raw(container);
110 void set(Extensible* container, bool value)
113 set_raw(container, this);
115 unset_raw(container);
118 void unset(Extensible* container)
120 unset_raw(container);
123 void free(Extensible* container, void* item) CXX11_OVERRIDE
129 class ModuleTopicLock : public Module
132 FlagExtItem topiclock;
136 : cmd(this), topiclock("topiclock", this)
140 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
142 // Only fired for local users currently, but added a check anyway
143 if ((IS_LOCAL(user)) && (topiclock.get(chan)))
145 user->WriteNumeric(ERR_TOPICLOCK, chan->name, "TOPIC cannot be changed due to topic lock being active on the channel");
149 return MOD_RES_PASSTHRU;
152 Version GetVersion() CXX11_OVERRIDE
154 return Version("Allows services to lock the channel topic so that it can not be changed.", VF_COMMON | VF_VENDOR);
158 MODULE_INIT(ModuleTopicLock)