aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp29
-rw-r--r--src/server/game/Motd/ServerMotd.cpp69
-rw-r--r--src/server/game/Motd/ServerMotd.h37
-rw-r--r--src/server/game/World/World.cpp15
-rw-r--r--src/server/game/World/World.h6
-rw-r--r--src/server/scripts/Commands/cs_server.cpp5
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.cpp3
7 files changed, 115 insertions, 49 deletions
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index 52af8e1d6cc..db482b05b5d 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -41,6 +41,7 @@
#include "ReputationMgr.h"
#include "GitRevision.h"
#include "ScriptMgr.h"
+#include "ServerMotd.h"
#include "SharedDefines.h"
#include "SocialMgr.h"
#include "UpdateMask.h"
@@ -750,33 +751,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
// Send MOTD
{
- data.Initialize(SMSG_MOTD, 50); // new in 2.0.1
- data << (uint32)0;
-
- uint32 linecount=0;
- std::string str_motd = sWorld->GetMotd();
- std::string::size_type pos, nextpos;
-
- pos = 0;
- while ((nextpos= str_motd.find('@', pos)) != std::string::npos)
- {
- if (nextpos != pos)
- {
- data << str_motd.substr(pos, nextpos-pos);
- ++linecount;
- }
- pos = nextpos+1;
- }
-
- if (pos<str_motd.length())
- {
- data << str_motd.substr(pos);
- ++linecount;
- }
-
- data.put(0, linecount);
-
- SendPacket(&data);
+ SendPacket(Motd::GetMotdPacket());
// send server info
if (sWorld->getIntConfig(CONFIG_ENABLE_SINFO_LOGIN) == 1)
diff --git a/src/server/game/Motd/ServerMotd.cpp b/src/server/game/Motd/ServerMotd.cpp
new file mode 100644
index 00000000000..dc7746a5210
--- /dev/null
+++ b/src/server/game/Motd/ServerMotd.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Common.h"
+#include "WorldPacket.h"
+#include "ServerMotd.h"
+
+#include "ScriptMgr.h"
+
+namespace
+{
+ WorldPacket MotdPacket;
+ std::string FormattedMotd;
+
+ std::string const EndLine = []() -> std::string
+ {
+ std::ostringstream oss;
+ oss << std::endl;
+ return oss.str();
+ }();
+}
+
+void Motd::SetMotd(std::string motd)
+{
+ // scripts may change motd
+ sScriptMgr->OnMotdChange(motd);
+
+ WorldPacket data(SMSG_MOTD); // new in 2.0.1
+
+ Tokenizer motdTokens(motd, '@');
+ data << uint32(motdTokens.size()); // line count
+
+ for (Tokenizer::const_reference token : motdTokens)
+ data << token;
+
+ MotdPacket = data;
+
+ if (!motdTokens.size())
+ return;
+
+ std::ostringstream oss;
+ std::copy(motdTokens.begin(), motdTokens.end() - 1, std::ostream_iterator<char const*>(oss, EndLine.c_str()));
+ oss << *(motdTokens.end() - 1); // copy back element
+ FormattedMotd = oss.str();
+}
+
+char const* Motd::GetMotd()
+{
+ return FormattedMotd.c_str();
+}
+
+WorldPacket const* Motd::GetMotdPacket()
+{
+ return &MotdPacket;
+}
diff --git a/src/server/game/Motd/ServerMotd.h b/src/server/game/Motd/ServerMotd.h
new file mode 100644
index 00000000000..158ce693b8d
--- /dev/null
+++ b/src/server/game/Motd/ServerMotd.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ServerMotd_h__
+#define ServerMotd_h__
+
+#include <string>
+
+class WorldPacket;
+
+namespace Motd
+{
+ /// Set a new Message of the Day
+ void SetMotd(std::string motd);
+
+ /// Get the current Message of the Day
+ char const* GetMotd();
+
+ /// Get the motd packet to send at login
+ WorldPacket const* GetMotdPacket();
+}
+
+#endif //ServerMotd_h__
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 68c3b882981..38015c6bdab 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -57,6 +57,7 @@
#include "QueryCallback.h"
#include "ScriptMgr.h"
#include "ScriptReloadMgr.h"
+#include "ServerMotd.h"
#include "SkillDiscovery.h"
#include "SkillExtraItems.h"
#include "SmartAI.h"
@@ -182,18 +183,6 @@ void World::SetClosed(bool val)
sScriptMgr->OnOpenStateChange(!val);
}
-void World::SetMotd(const std::string& motd)
-{
- m_motd = motd;
-
- sScriptMgr->OnMotdChange(m_motd);
-}
-
-const char* World::GetMotd() const
-{
- return m_motd.c_str();
-}
-
/// Find a session by its id
WorldSession* World::FindSession(uint32 id) const
{
@@ -405,7 +394,7 @@ void World::LoadConfigSettings(bool reload)
///- Read the player limit and the Message of the day from the config file
SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100));
- SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to a Trinity Core Server."));
+ Motd::SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to a Trinity Core Server."));
///- Read ticket system setting from the config file
m_bool_configs[CONFIG_ALLOW_TICKETS] = sConfigMgr->GetBoolDefault("AllowTickets", true);
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 4776762a147..1eec3d45f53 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -615,11 +615,6 @@ class TC_GAME_API World
/// Allow/Disallow object movements
void SetAllowMovement(bool allow) { m_allowMovement = allow; }
- /// Set a new Message of the Day
- void SetMotd(std::string const& motd);
- /// Get the current Message of the Day
- const char* GetMotd() const;
-
/// Set the string for new characters (first login)
void SetNewCharString(std::string const& str) { m_newCharString = str; }
/// Get the string for new characters (first login)
@@ -816,7 +811,6 @@ class TC_GAME_API World
uint32 m_availableDbcLocaleMask; // by loaded DBC
void DetectDBCLang();
bool m_allowMovement;
- std::string m_motd;
std::string m_dataPath;
// for max speed access
diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp
index 50b9b37031f..620c70599e5 100644
--- a/src/server/scripts/Commands/cs_server.cpp
+++ b/src/server/scripts/Commands/cs_server.cpp
@@ -30,6 +30,7 @@ EndScriptData */
#include "ScriptMgr.h"
#include "GitRevision.h"
#include "Util.h"
+#include "ServerMotd.h"
#include "GameTime.h"
#include "UpdateTime.h"
@@ -127,7 +128,7 @@ public:
// Display the 'Message of the day' for the realm
static bool HandleServerMotdCommand(ChatHandler* handler, char const* /*args*/)
{
- handler->PSendSysMessage(LANG_MOTD_CURRENT, sWorld->GetMotd());
+ handler->PSendSysMessage(LANG_MOTD_CURRENT, Motd::GetMotd());
return true;
}
@@ -249,7 +250,7 @@ public:
// Define the 'Message of the day' for the realm
static bool HandleServerSetMotdCommand(ChatHandler* handler, char const* args)
{
- sWorld->SetMotd(args);
+ Motd::SetMotd(args);
handler->PSendSysMessage(LANG_MOTD_NEW, args);
return true;
}
diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp
index b44ff858f53..3df9556c73d 100644
--- a/src/server/worldserver/RemoteAccess/RASession.cpp
+++ b/src/server/worldserver/RemoteAccess/RASession.cpp
@@ -26,6 +26,7 @@
#include "DatabaseEnv.h"
#include "World.h"
#include "Config.h"
+#include "ServerMotd.h"
using boost::asio::ip::tcp;
@@ -73,7 +74,7 @@ void RASession::Start()
TC_LOG_INFO("commands.ra", "User %s (IP: %s) authenticated correctly to RA", username.c_str(), GetRemoteIpAddress().c_str());
// Authentication successful, send the motd
- Send(std::string(std::string(sWorld->GetMotd()) + "\r\n").c_str());
+ Send(std::string(std::string(Motd::GetMotd()) + "\r\n").c_str());
// Read commands
for (;;)