2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 class CommandSVSTOPIC : public Command
24 CommandSVSTOPIC(Module* Creator)
25 : Command(Creator, "SVSTOPIC", 1, 4)
27 flags_needed = FLAG_SERVERONLY;
30 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
32 if (!user->server->IsULine())
38 Channel* chan = ServerInstance->FindChan(parameters[0]);
42 if (parameters.size() == 4)
44 // 4 parameter version, set all topic data on the channel to the ones given in the parameters
45 time_t topicts = ConvToInt(parameters[1]);
48 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped.");
52 chan->SetTopic(user, parameters[3], topicts, ¶meters[2]);
56 // 1 parameter version, nuke the topic
57 chan->SetTopic(user, std::string(), 0);
64 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
66 return ROUTE_BROADCAST;
70 class FlagExtItem : public ExtensionItem
73 FlagExtItem(const std::string& key, Module* owner)
74 : ExtensionItem(key, ExtensionItem::EXT_CHANNEL, owner)
78 bool get(const Extensible* container) const
80 return (get_raw(container) != NULL);
83 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const
85 if (format == FORMAT_USER)
91 void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
94 set_raw(container, this);
99 void set(Extensible* container, bool value)
102 set_raw(container, this);
104 unset_raw(container);
107 void unset(Extensible* container)
109 unset_raw(container);
112 void free(void* item)
118 class ModuleTopicLock : public Module
121 FlagExtItem topiclock;
125 : cmd(this), topiclock("topiclock", this)
129 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
131 // Only fired for local users currently, but added a check anyway
132 if ((IS_LOCAL(user)) && (topiclock.get(chan)))
134 user->WriteNumeric(744, chan->name, "TOPIC cannot be changed due to topic lock being active on the channel");
138 return MOD_RES_PASSTHRU;
141 Version GetVersion() CXX11_OVERRIDE
143 return Version("Implements server-side topic locks and the server-to-server command SVSTOPIC", VF_COMMON | VF_VENDOR);
147 MODULE_INIT(ModuleTopicLock)