summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-04-11 15:53:01 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-04-11 15:53:01 +0200
commit2706a993b3f8ee52e2728047fad6a56f7e3cf405 (patch)
tree30d99f78630372bbe630fcf47f2f32fc8891fbe9 /src
parentb25070bf5e9447533bf1a0555c6954740ca12340 (diff)
Refactor topic setting logic to go through Channel::SetTopic() in all cases
- Pass topic set time and optionally the setter to SetTopic() - Don't do anything if the topic is changed by a local user to what it is currently
Diffstat (limited to 'src')
-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
7 files changed, 40 insertions, 56 deletions
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;