-/** FTOPIC command */
-bool TreeSocket::ForceTopic(const std::string &source, std::deque<std::string> ¶ms)
-{
- if (params.size() != 4)
- return true;
- time_t ts = atoi(params[1].c_str());
- Channel* c = this->ServerInstance->FindChan(params[0]);
- if (c)
- {
- if ((ts >= c->topicset) || (c->topic.empty()))
- {
- if (c->topic != params[3])
- {
- User* user = this->ServerInstance->FindNick(source);
- // Update topic only when it differs from current topic
- c->topic.assign(params[3], 0, ServerInstance->Config->Limits.MaxTopic);
- if (!user)
- {
- std::string sourceserv = Utils->FindServer(source)->GetName();
- c->WriteChannelWithServ(sourceserv.c_str(), "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
- }
- else
- {
- c->WriteChannel(user, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
- }
- }
-
- // Always update setter and settime.
- c->setby.assign(params[2], 0, 127);
- c->topicset = ts;
-
- /* all done, send it on its way */
- params[3] = ":" + params[3];
- Utils->DoOneToAllButSender(source,"FTOPIC",params,source);
- }
+ time_t ts = ConvToInt(params[2]);
+ if (!ts)
+ return CMD_INVALID;
+
+ // Channel::topicset is initialized to 0 on channel creation, so their ts will always win if we never had a topic
+ if (ts < c->topicset)
+ return CMD_FAILURE;
+
+ /*
+ * If the topics were updated at the exact same second, accept
+ * the remote only when it's "bigger" than ours as defined by
+ * string comparision, so non-empty topics always overridde
+ * empty topics if their timestamps are equal
+ */
+ if ((ts == c->topicset) && (c->topic > params[4]))
+ return CMD_FAILURE; // Topics were set at the exact same time, keep our topic and setter