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(User* user, const Params& parameters) 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 = ConvToNum<time_t>(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 Params& parameters) CXX11_OVERRIDE
72 return ROUTE_BROADCAST;
76 // TODO: add a BoolExtItem to replace this.
77 class FlagExtItem : public ExtensionItem
80 FlagExtItem(const std::string& key, Module* owner)
81 : ExtensionItem(key, ExtensionItem::EXT_CHANNEL, owner)
85 bool get(const Extensible* container) const
87 return (get_raw(container) != NULL);
90 std::string ToHuman(const Extensible* container, void* item) const CXX11_OVERRIDE
92 // Make the human version more readable.
96 std::string ToNetwork(const Extensible* container, void* item) const CXX11_OVERRIDE
101 void FromNetwork(Extensible* container, const std::string& value) CXX11_OVERRIDE
104 set_raw(container, this);
106 unset_raw(container);
109 void set(Extensible* container, bool value)
112 set_raw(container, this);
114 unset_raw(container);
117 void unset(Extensible* container)
119 unset_raw(container);
122 void free(Extensible* container, void* item) CXX11_OVERRIDE
128 class ModuleTopicLock : public Module
131 FlagExtItem topiclock;
135 : cmd(this), topiclock("topiclock", this)
139 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
141 // Only fired for local users currently, but added a check anyway
142 if ((IS_LOCAL(user)) && (topiclock.get(chan)))
144 user->WriteNumeric(ERR_TOPICLOCK, chan->name, "TOPIC cannot be changed due to topic lock being active on the channel");
148 return MOD_RES_PASSTHRU;
151 Version GetVersion() CXX11_OVERRIDE
153 return Version("Implements server-side topic locks and the server-to-server command SVSTOPIC", VF_COMMON | VF_VENDOR);
157 MODULE_INIT(ModuleTopicLock)