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.");
53 newtopic.assign(parameters[3], 0, ServerInstance->Config->Limits.MaxTopic);
54 bool topics_differ = (chan->topic != newtopic);
55 if ((topics_differ) || (chan->topicset != topicts) || (chan->setby != parameters[2]))
57 // Update when any parameter differs
58 chan->topicset = topicts;
59 chan->setby.assign(parameters[2], 0, 127);
60 chan->topic = newtopic;
61 // Send TOPIC to clients only if the actual topic has changed, be silent otherwise
63 chan->WriteChannel(user, "TOPIC %s :%s", chan->name.c_str(), chan->topic.c_str());
68 // 1 parameter version, nuke the topic
69 bool topic_empty = chan->topic.empty();
70 if (!topic_empty || !chan->setby.empty())
76 chan->WriteChannel(user, "TOPIC %s :", chan->name.c_str());
83 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
85 return ROUTE_BROADCAST;
89 class FlagExtItem : public ExtensionItem
92 FlagExtItem(const std::string& key, Module* owner)
93 : ExtensionItem(key, ExtensionItem::EXT_CHANNEL, owner)
97 bool get(const Extensible* container) const
99 return (get_raw(container) != NULL);
102 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const
104 if (format == FORMAT_USER)
110 void unserialize(SerializeFormat format, Extensible* container, const std::string& value)
113 set_raw(container, this);
115 unset_raw(container);
118 void set(Extensible* container, bool value)
121 set_raw(container, this);
123 unset_raw(container);
126 void unset(Extensible* container)
128 unset_raw(container);
131 void free(void* item)
137 class ModuleTopicLock : public Module
140 FlagExtItem topiclock;
144 : cmd(this), topiclock("topiclock", this)
148 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE
150 // Only fired for local users currently, but added a check anyway
151 if ((IS_LOCAL(user)) && (topiclock.get(chan)))
153 user->WriteNumeric(744, "%s :TOPIC cannot be changed due to topic lock being active on the channel", chan->name.c_str());
157 return MOD_RES_PASSTHRU;
160 Version GetVersion() CXX11_OVERRIDE
162 return Version("Implements server-side topic locks and the server-to-server command SVSTOPIC", VF_COMMON | VF_VENDOR);
166 MODULE_INIT(ModuleTopicLock)