2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 CmdResult CommandFTopic::Handle(User* user, Params& params)
31 Channel* c = ServerInstance->FindChan(params[0]);
35 if (c->age < ServerCommand::ExtractTS(params[1]))
36 // Our channel TS is older, nothing to do
39 // Channel::topicset is initialized to 0 on channel creation, so their ts will always win if we never had a topic
40 time_t ts = ServerCommand::ExtractTS(params[2]);
44 // The topic text is always the last parameter
45 const std::string& newtopic = params.back();
47 // If there is a setter in the message use that, otherwise use the message source
48 const std::string& setter = ((params.size() > 4) ? params[3] : (ServerInstance->Config->FullHostInTopic ? user->GetFullHost() : user->nick));
51 * If the topics were updated at the exact same second, accept
52 * the remote only when it's "bigger" than ours as defined by
53 * string comparision, so non-empty topics always overridde
54 * empty topics if their timestamps are equal
56 * Similarly, if the topic texts are equal too, keep one topic
57 * setter and discard the other
59 if (ts == c->topicset)
61 // Discard if their topic text is "smaller"
62 if (c->topic > newtopic)
65 // If the texts are equal in addition to the timestamps, decide which setter to keep
66 if ((c->topic == newtopic) && (c->setby >= setter))
70 c->SetTopic(user, newtopic, ts, &setter);
74 // Used when bursting and in reply to RESYNC, contains topic setter as the 4th parameter
75 CommandFTopic::Builder::Builder(Channel* chan)
76 : CmdBuilder("FTOPIC")
80 push_int(chan->topicset);
82 push_last(chan->topic);
85 // Used when changing the topic, the setter is the message source
86 CommandFTopic::Builder::Builder(User* user, Channel* chan)
87 : CmdBuilder(user, "FTOPIC")
91 push_int(chan->topicset);
92 push_last(chan->topic);