2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2018 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/>.
22 #include "modules/ircv3.h"
23 #include "modules/ircv3_servertime.h"
24 #include "modules/server.h"
27 : public IRCv3::ServerTime::Manager
28 , public IRCv3::CapTag<ServerTimeTag>
29 , public ServerProtocol::MessageEventListener
33 std::string lasttimestring;
35 void RefreshTimeString()
37 const time_t currtime = ServerInstance->Time();
38 const long currtimens = ServerInstance->Time_ns();
39 if (currtime != lasttime || currtimens != lasttimens)
42 lasttimens = currtimens;
44 // Cache the string so it's not recreated every time a message is sent.
45 lasttimestring = IRCv3::ServerTime::FormatTime(currtime, (currtimens ? currtimens / 1000000 : 0));
50 using ServerProtocol::MessageEventListener::OnBuildMessage;
52 ServerTimeTag(Module* mod)
53 : IRCv3::ServerTime::Manager(mod)
54 , IRCv3::CapTag<ServerTimeTag>(mod, "server-time", "time")
55 , ServerProtocol::MessageEventListener(mod)
62 const std::string* GetValue(const ClientProtocol::Message& msg)
66 return &lasttimestring;
69 void OnBuildMessage(User* source, const char* command, ClientProtocol::TagMap& tags) CXX11_OVERRIDE
73 tags.insert(std::make_pair(tagname, ClientProtocol::MessageTagData(this, lasttimestring)));
78 class ModuleIRCv3ServerTime : public Module
83 ModuleIRCv3ServerTime()
88 Version GetVersion() CXX11_OVERRIDE
90 return Version("Provides the server-time IRCv3 extension", VF_VENDOR);
94 MODULE_INIT(ModuleIRCv3ServerTime)