summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/channels.h5
-rw-r--r--src/channels.cpp18
-rw-r--r--src/coremods/core_channel/cmd_topic.cpp8
-rw-r--r--src/modules/m_permchannels.cpp12
-rw-r--r--src/modules/m_satopic.cpp10
-rw-r--r--src/modules/m_spanningtree/fjoin.cpp9
-rw-r--r--src/modules/m_spanningtree/ftopic.cpp14
-rw-r--r--src/modules/m_topiclock.cpp25
8 files changed, 44 insertions, 57 deletions
diff --git a/include/channels.h b/include/channels.h
index 0a131ddb3..be872b7fe 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -138,8 +138,11 @@ class CoreExport Channel : public Extensible
/** Sets the channel topic.
* @param user The user setting the topic.
* @param topic The topic to set it to.
+ * @param topicts Timestamp of the new topic.
+ * @param setter Setter string, may be used when the original setter is no longer online.
+ * If omitted or NULL, the setter string is obtained from the user.
*/
- void SetTopic(User* user, const std::string& topic);
+ void SetTopic(User* user, const std::string& topic, time_t topicts, const std::string* setter = NULL);
/** Obtain the channel "user counter"
* This returns the number of users on this channel
diff --git a/src/channels.cpp b/src/channels.cpp
index 14b1ea545..30bddec5c 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -46,12 +46,20 @@ void Channel::SetMode(ModeHandler* mh, bool on)
modes[mh->GetId()] = on;
}
-void Channel::SetTopic(User* u, const std::string& ntopic)
+void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const std::string* setter)
{
- this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
- this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
- this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
- this->topicset = ServerInstance->Time();
+ // Send a TOPIC message to the channel only if the new topic text differs
+ if (this->topic != ntopic)
+ {
+ this->topic = ntopic;
+ this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
+ }
+
+ // Always update setter and set time
+ if (!setter)
+ setter = ServerInstance->Config->FullHostInTopic ? &u->GetFullHost() : &u->nick;
+ this->setby.assign(*setter, 0, 128);
+ this->topicset = topicts;
FOREACH_MOD(OnPostTopicChange, (u, this, this->topic));
}
diff --git a/src/coremods/core_channel/cmd_topic.cpp b/src/coremods/core_channel/cmd_topic.cpp
index b42148939..6d99edcc6 100644
--- a/src/coremods/core_channel/cmd_topic.cpp
+++ b/src/coremods/core_channel/cmd_topic.cpp
@@ -80,7 +80,13 @@ CmdResult CommandTopic::HandleLocal(const std::vector<std::string>& parameters,
}
}
- c->SetTopic(user, t);
+ // Make sure the topic is not longer than the limit in the config
+ if (t.length() > ServerInstance->Config->Limits.MaxTopic)
+ t.erase(ServerInstance->Config->Limits.MaxTopic);
+
+ // Only change if the new topic is different than the current one
+ if (c->topic != t)
+ c->SetTopic(user, t, ServerInstance->Time());
return CMD_SUCCESS;
}
diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp
index 22513abea..9a5da5ce4 100644
--- a/src/modules/m_permchannels.cpp
+++ b/src/modules/m_permchannels.cpp
@@ -207,16 +207,16 @@ public:
c = new Channel(channel, TS);
unsigned int topicset = tag->getInt("topicts");
- c->topic = tag->getString("topic");
+ std::string topic = tag->getString("topic");
- if ((topicset != 0) || (!c->topic.empty()))
+ if ((topicset != 0) || (!topic.empty()))
{
if (topicset == 0)
topicset = ServerInstance->Time();
- c->topicset = topicset;
- c->setby = tag->getString("topicsetby");
- if (c->setby.empty())
- c->setby = ServerInstance->Config->ServerName;
+ std::string topicsetby = tag->getString("topicsetby");
+ if (topicsetby.empty())
+ topicsetby = ServerInstance->Config->ServerName;
+ c->SetTopic(ServerInstance->FakeClient, topic, topicset, &topicsetby);
}
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Added %s with topic %s", channel.c_str(), c->topic.c_str());
diff --git a/src/modules/m_satopic.cpp b/src/modules/m_satopic.cpp
index 040d86b9a..f966d6a5a 100644
--- a/src/modules/m_satopic.cpp
+++ b/src/modules/m_satopic.cpp
@@ -38,8 +38,14 @@ class CommandSATopic : public Command
if(target)
{
- const std::string& newTopic = parameters[1];
- target->SetTopic(user, newTopic);
+ const std::string newTopic(parameters[1], 0, ServerInstance->Config->Limits.MaxTopic);
+ if (target->topic == newTopic)
+ {
+ user->WriteNotice(InspIRCd::Format("The topic on %s is already what you are trying to change it to.", target->name.c_str()));
+ return CMD_SUCCESS;
+ }
+
+ target->SetTopic(user, newTopic, ServerInstance->Time(), NULL);
ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SATOPIC on " + target->name + ", new topic: " + newTopic);
return CMD_SUCCESS;
diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp
index 74590adf8..40ba5e893 100644
--- a/src/modules/m_spanningtree/fjoin.cpp
+++ b/src/modules/m_spanningtree/fjoin.cpp
@@ -278,14 +278,9 @@ void CommandFJoin::LowerTS(Channel* chan, time_t TS, const std::string& newname)
// Unset all extensions
chan->FreeAllExtItems();
- // Clear the topic, if it isn't empty then send a topic change message to local users
- if (!chan->topic.empty())
- {
- chan->topic.clear();
- chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :", chan->name.c_str());
- }
+ // Clear the topic
+ chan->SetTopic(ServerInstance->FakeClient, std::string(), 0);
chan->setby.clear();
- chan->topicset = 0;
}
CommandFJoin::Builder::Builder(Channel* chan, TreeServer* source)
diff --git a/src/modules/m_spanningtree/ftopic.cpp b/src/modules/m_spanningtree/ftopic.cpp
index 3c76c928a..de72d162a 100644
--- a/src/modules/m_spanningtree/ftopic.cpp
+++ b/src/modules/m_spanningtree/ftopic.cpp
@@ -63,19 +63,7 @@ CmdResult CommandFTopic::Handle(User* user, std::vector<std::string>& params)
return CMD_FAILURE;
}
- if (c->topic != newtopic)
- {
- // Update topic only when it differs from current topic
- c->topic.assign(newtopic, 0, ServerInstance->Config->Limits.MaxTopic);
- c->WriteChannel(user, "TOPIC %s :%s", c->name.c_str(), c->topic.c_str());
- }
-
- // Update setter and settime
- c->setby.assign(setter, 0, 128);
- c->topicset = ts;
-
- FOREACH_MOD(OnPostTopicChange, (user, c, c->topic));
-
+ c->SetTopic(user, newtopic, ts, &setter);
return CMD_SUCCESS;
}
diff --git a/src/modules/m_topiclock.cpp b/src/modules/m_topiclock.cpp
index eba2b33f0..340fbfdec 100644
--- a/src/modules/m_topiclock.cpp
+++ b/src/modules/m_topiclock.cpp
@@ -49,32 +49,13 @@ class CommandSVSTOPIC : public Command
return CMD_INVALID;
}
- std::string newtopic;
- newtopic.assign(parameters[3], 0, ServerInstance->Config->Limits.MaxTopic);
- bool topics_differ = (chan->topic != newtopic);
- if ((topics_differ) || (chan->topicset != topicts) || (chan->setby != parameters[2]))
- {
- // Update when any parameter differs
- chan->topicset = topicts;
- chan->setby.assign(parameters[2], 0, 127);
- chan->topic = newtopic;
- // Send TOPIC to clients only if the actual topic has changed, be silent otherwise
- if (topics_differ)
- chan->WriteChannel(user, "TOPIC %s :%s", chan->name.c_str(), chan->topic.c_str());
- }
+ chan->SetTopic(user, parameters[3], topicts, &parameters[2]);
}
else
{
// 1 parameter version, nuke the topic
- bool topic_empty = chan->topic.empty();
- if (!topic_empty || !chan->setby.empty())
- {
- chan->topicset = 0;
- chan->setby.clear();
- chan->topic.clear();
- if (!topic_empty)
- chan->WriteChannel(user, "TOPIC %s :", chan->name.c_str());
- }
+ chan->SetTopic(user, std::string(), 0);
+ chan->setby.clear();
}
return CMD_SUCCESS;