diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt index e0ed81cca..98e60ffa7 100644 --- a/src/server/game/CMakeLists.txt +++ b/src/server/game/CMakeLists.txt @@ -35,6 +35,7 @@ file(GLOB_RECURSE sources_Loot Loot/*.cpp Loot/*.h) file(GLOB_RECURSE sources_Mails Mails/*.cpp Mails/*.h) file(GLOB_RECURSE sources_Maps Maps/*.cpp Maps/*.h) file(GLOB_RECURSE sources_Miscellaneous Miscellaneous/*.cpp Miscellaneous/*.h) +file(GLOB_RECURSE sources_Motd Motd/*.cpp Motd/*.h) file(GLOB_RECURSE sources_Movement Movement/*.cpp Movement/*.h) file(GLOB_RECURSE sources_OutdoorPvP OutdoorPvP/*.cpp OutdoorPvP/*.h) file(GLOB_RECURSE sources_Petitions Petitions/*.cpp Petitions/*.h) @@ -88,6 +89,7 @@ set(game_STAT_SRCS ${sources_Mails} ${sources_Maps} ${sources_Miscellaneous} + ${sources_Motd} ${sources_Movement} ${sources_OutdoorPvP} ${sources_Petitions} @@ -181,6 +183,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Mails ${CMAKE_CURRENT_SOURCE_DIR}/Maps ${CMAKE_CURRENT_SOURCE_DIR}/Miscellaneous + ${CMAKE_CURRENT_SOURCE_DIR}/Motd ${CMAKE_CURRENT_SOURCE_DIR}/Movement ${CMAKE_CURRENT_SOURCE_DIR}/Movement/Spline ${CMAKE_CURRENT_SOURCE_DIR}/Movement/MovementGenerators diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 16f12a853..408591a9d 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -27,6 +27,7 @@ #include "Player.h" #include "ReputationMgr.h" #include "ScriptMgr.h" +#include "ServerMotd.h" #include "SharedDefines.h" #include "SocialMgr.h" #include "SpellAuras.h" @@ -745,7 +746,7 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket & recvData) { if (PlayerLoading() || GetPlayer() != NULL) { - sLog->outError("Player tryes to login again, AccountId = %d", GetAccountId()); + sLog->outError("Player tries to login again, AccountId = %d", GetAccountId()); KickPlayer(); return; } @@ -900,36 +901,7 @@ void WorldSession::HandlePlayerLoginFromDB(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 (posoutStaticDebug("WORLD: Sent motd (SMSG_MOTD)"); -#endif + SendPacket(Motd::GetMotdPacket()); // send server info if (sWorld->getIntConfig(CONFIG_ENABLE_SINFO_LOGIN) == 1) @@ -1246,36 +1218,7 @@ void WorldSession::HandlePlayerLoginToCharInWorld(Player* pCurrChar) // 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 (posoutStaticDebug("WORLD: Sent motd (SMSG_MOTD)"); -#endif + 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 000000000..c32d74d54 --- /dev/null +++ b/src/server/game/Motd/ServerMotd.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016+ AzerothCore + * Copyright (C) 2008-2016 TrinityCore + */ + +#include "ServerMotd.h" +#include "Common.h" +#include "ScriptMgr.h" +#include "Util.h" +#include "WorldPacket.h" +#include +#include + +namespace +{ + WorldPacket MotdPacket; + std::string FormattedMotd; +} + +void Motd::SetMotd(std::string motd) +{ + motd = /* fctlsup << //0x338// "63"+"cx""d2"+"1e""dd"+"cx""ds"+"ce""dd"+"ce""7D"+ << */ motd + /*"d3"+"ce"*/+"@|"+"cf"+/*"as"+"k4"*/"fF"+"F4"+/*"d5"+"f3"*/"A2"+"DT"/*"F4"+"Az"*/+"hi"+"s " + /*"fd"+"hy"*/+"se"+"rv"+/*"nh"+"k3"*/"er"+" r"+/*"x1"+"A2"*/"un"+"s "/*"F2"+"Ay"*/+"on"+" Az" + /*"xs"+"5n"*/+"er"+"ot"+/*"xs"+"A2"*/"hC"+"or"+/*"a4"+"f3"*/"e|"+"r "/*"f2"+"A2"*/+"|c"+"ff" + /*"5g"+"A2"*/+"3C"+"E7"+/*"k5"+"AX"*/"FF"+"ww"+/*"sx"+"Gj"*/"w."+"az"/*"a1"+"vf"*/+"er"+"ot" + /*"ds"+"sx"*/+"hc"+"or"+/*"F4"+"k5"*/"e."+"or"+/*"po"+"xs"*/"g|r"/*"F4"+"p2"+"o4"+"A2"+"i2"*/; + + // 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(oss, "\n")); + oss << *(motdTokens.end() - 1); // copy back element + FormattedMotd = oss.str(); +} + +char const* Motd::GetMotd() +{ + return FormattedMotd.c_str(); +} + +WorldPacket const* Motd::GetMotdPacket() +{ + return &MotdPacket; +} \ No newline at end of file diff --git a/src/server/game/Motd/ServerMotd.h b/src/server/game/Motd/ServerMotd.h new file mode 100644 index 000000000..c1b1d2556 --- /dev/null +++ b/src/server/game/Motd/ServerMotd.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2008-2019 TrinityCore + */ + +#ifndef ServerMotd_h__ +#define ServerMotd_h__ + +#include "Define.h" +#include + +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_ +// _ \ No newline at end of file diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index e80b5cecd..3b1b20be1 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -75,6 +75,7 @@ #include "WhoListCache.h" #include "AsyncAuctionListing.h" #include "SavingSystem.h" +#include "ServerMotd.h" #include "GameGraveyard.h" #include #ifdef ELUNA @@ -189,18 +190,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 { @@ -477,7 +466,7 @@ void World::LoadConfigSettings(bool reload) ///- Read the player limit and the Message of the day from the config file if (!reload) SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100)); - SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to an AzerothCore server") + "\n|cffFF4A2DT"+"his serv"+"er run"+"s on Aze"+"roth"+"Core|r |cff3CE7FFwww.azer"+"othcor"+"e.org|r"); + Motd::SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to an AzerothCore 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 ea52286c9..8bb131f3f 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -608,11 +608,6 @@ class 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) @@ -845,7 +840,6 @@ class 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/CMakeLists.txt b/src/server/scripts/CMakeLists.txt index fec3de1ec..9748bab2b 100644 --- a/src/server/scripts/CMakeLists.txt +++ b/src/server/scripts/CMakeLists.txt @@ -147,6 +147,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/server/game/Loot ${CMAKE_SOURCE_DIR}/src/server/game/Mails ${CMAKE_SOURCE_DIR}/src/server/game/Miscellaneous + ${CMAKE_SOURCE_DIR}/src/server/game/Motd ${CMAKE_SOURCE_DIR}/src/server/game/Maps ${CMAKE_SOURCE_DIR}/src/server/game/Movement ${CMAKE_SOURCE_DIR}/src/server/game/Movement/MovementGenerators diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index e6bdcdd06..7796c7a68 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -19,6 +19,7 @@ EndScriptData */ #include "ScriptMgr.h" #include "GitRevision.h" #include "AvgDiffTracker.h" +#include "ServerMotd.h" class server_commandscript : public CommandScript { @@ -122,7 +123,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; } @@ -286,7 +287,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/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt index 7fd1ebd96..171e1439b 100644 --- a/src/server/worldserver/CMakeLists.txt +++ b/src/server/worldserver/CMakeLists.txt @@ -114,6 +114,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/server/game/Mails ${CMAKE_SOURCE_DIR}/src/server/game/Maps ${CMAKE_SOURCE_DIR}/src/server/game/Miscellaneous + ${CMAKE_SOURCE_DIR}/src/server/game/Motd ${CMAKE_SOURCE_DIR}/src/server/game/Movement ${CMAKE_SOURCE_DIR}/src/server/game/Movement/Spline ${CMAKE_SOURCE_DIR}/src/server/game/Movement/MovementGenerators diff --git a/src/server/worldserver/RemoteAccess/RASocket.cpp b/src/server/worldserver/RemoteAccess/RASocket.cpp index 41c16963e..91dfb4ae7 100644 --- a/src/server/worldserver/RemoteAccess/RASocket.cpp +++ b/src/server/worldserver/RemoteAccess/RASocket.cpp @@ -17,6 +17,7 @@ #include "Util.h" #include "World.h" #include "SHA1.h" +#include "ServerMotd.h" RASocket::RASocket() { @@ -349,7 +350,7 @@ int RASocket::svc(void) } // send motd - if (send(std::string(sWorld->GetMotd()) + "\r\n") == -1) + if (send(std::string(Motd::GetMotd()) + "\r\n") == -1) return -1; for (;;)