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/>.
27 class CommandSVSTOPIC : public Command
30 CommandSVSTOPIC(Module* Creator)
31 : Command(Creator, "SVSTOPIC", 1, 4)
33 flags_needed = FLAG_SERVERONLY;
36 CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
38 if (!user->server->IsULine())
44 Channel* chan = ServerInstance->FindChan(parameters[0]);
48 if (parameters.size() == 4)
50 // 4 parameter version, set all topic data on the channel to the ones given in the parameters
51 time_t topicts = ConvToInt(parameters[1]);
54 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received SVSTOPIC with a 0 topicts, dropped.");
58 chan->SetTopic(user, parameters[3], topicts, ¶meters[2]);
62 // 1 parameter version, nuke the topic
63 chan->SetTopic(user, std::string(), 0);
70 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE
72 return ROUTE_BROADCAST;
76 class FlagExtItem : public ExtensionItem
79 FlagExtItem(const std::string& key, Module* owner)
80 : ExtensionItem(key, ExtensionItem::EXT_CHANNEL, owner)
84 bool get(const Extensible* container) const
86 return (get_raw(container) != NULL);
89 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
91 if (format == FORMAT_USER)
97 void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
100 set_raw(container, this);
102 unset_raw(container);
105 void set(Extensible* container, bool value)
108 set_raw(container, this);
110 unset_raw(container);
113 void unset(Extensible* container)
115 unset_raw(container);
118 void free(void* item) CXX11_OVERRIDE
124 class ModuleTopicLock : public Module
127 FlagExtItem topiclock;
131 : cmd(this), topiclock("topiclock", this)
135 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
137 // Only fired for local users currently, but added a check anyway
138 if ((IS_LOCAL(user)) && (topiclock.get(chan)))
140 user->WriteNumeric(ERR_TOPICLOCK, chan->name, "TOPIC cannot be changed due to topic lock being active on the channel");
144 return MOD_RES_PASSTHRU;
147 Version GetVersion() CXX11_OVERRIDE
149 return Version("Implements server-side topic locks and the server-to-server command SVSTOPIC", VF_COMMON | VF_VENDOR);
153 MODULE_INIT(ModuleTopicLock)