refactor(Core/Motd): Move motd from conf to db (#15111)

This commit is contained in:
Kitzunu
2023-02-20 22:07:26 +01:00
committed by GitHub
parent bd7f139bb8
commit 0c4feb6744
13 changed files with 126 additions and 36 deletions

View File

@@ -0,0 +1,11 @@
--
DROP TABLE IF EXISTS `motd`;
CREATE TABLE `motd` (
`realmid` INT NOT NULL,
`text` LONGTEXT NULL DEFAULT NULL,
PRIMARY KEY (`realmid`)
) ENGINE=InnoDB;
DELETE FROM `motd` WHERE `realmid`=1;
INSERT INTO `motd` (`realmid`, `text`) VALUES
(-1, 'Welcome to an AzerothCore server.');

View File

@@ -0,0 +1,9 @@
--
DELETE FROM `command` WHERE `name` = 'reload motd';
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('reload motd', 3, 'Syntax: .reload motd
Reload motd table.');
UPDATE `command` SET `help`='Syntax: .server set motd $realmId $MOTD\r\n\r\nSet server Message of the day for the specified realm.' WHERE `name`='server set motd';
UPDATE `acore_string` SET `content_default`='Message of the day in realm %i changed to:\r\n%s', `locale_deDE`='Nachricht des Tages in Realm %i wurde geändert zu:\r\n%s', `locale_zhCN`='每日消息更改为 in realm %i:\r\n%s' WHERE `entry`=1101;

View File

@@ -0,0 +1,17 @@
### How to upgrade
Motd is removed from config file
Motd is can now be found in auth database table `motd`
`realmid` = Realm ID or -1 for all realms.
`text` = Text for Motd
Specified realmId is prioritized over -1 (All Realms)
For example:
You have realm 1, 2, 3
(-1, "This Motd will show for 2, 3")
(1, "This Motd will show for 1")

View File

@@ -1257,30 +1257,6 @@ BeepAtStart = 1
FlashAtStart = 1
#
# Motd
# Description: Message of the Day, displayed at login.
# Use '@' for a newline and be sure to escape special characters.
# Example: "Welcome to John\'s Server@"
# Default: "Welcome to an AzerothCore server."
Motd = "Welcome to an AzerothCore server."
# PLEASE NOTE: another (hardcoded) text will appear below the MOTD:
#
# "This server runs on AzerothCore www.azerothcore.org"
#
# All the AzerothCore contributors, as well as its father projects (MaNGOS, TrinityCore, etc..),
# have worked for free to provide you this software. Please do not remove the credits.
#
# Changing or removing such hardcoded text is considered a violation of our license
# and it's not allowed. We reserve the right to take legal action in case of violations.
# Furthermore, any kind of support will be always denied.
#
# All AzerothCore contributors and its father projects are publicly listed in
# our official repository. Credits to open source contributions should always be shown.
#
#
# Server.LoginInfo
# Description: Display core version (.server info) on login.

View File

@@ -114,6 +114,8 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_REALMLIST_SECURITY_LEVEL, "SELECT allowedSecurityLevel from realmlist WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_DEL_ACCOUNT, "DELETE FROM account WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_AUTOBROADCAST, "SELECT id, weight, text FROM autobroadcast WHERE realmid = ? OR realmid = -1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_MOTD, "SELECT text FROM motd WHERE realmid = ? OR realmid = -1 ORDER BY realmid DESC", CONNECTION_SYNCH);
PrepareStatement(LOGIN_REP_MOTD, "REPLACE INTO motd (realmid, text) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_INS_ACCOUNT_MUTE, "INSERT INTO account_muted VALUES (?, UNIX_TIMESTAMP(), ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_ACCOUNT_MUTE_INFO, "SELECT mutedate, mutetime, mutereason, mutedby FROM account_muted WHERE guid = ? ORDER BY mutedate ASC", CONNECTION_SYNCH);
PrepareStatement(LOGIN_DEL_ACCOUNT_MUTED, "DELETE FROM account_muted WHERE guid = ?", CONNECTION_ASYNC);

View File

@@ -96,6 +96,8 @@ enum LoginDatabaseStatements : uint32
LOGIN_SEL_REALMLIST_SECURITY_LEVEL,
LOGIN_DEL_ACCOUNT,
LOGIN_SEL_AUTOBROADCAST,
LOGIN_SEL_MOTD,
LOGIN_REP_MOTD,
LOGIN_SEL_LAST_ATTEMPT_IP,
LOGIN_SEL_LAST_IP,
LOGIN_INS_ALDL_IP_LOGGING,

View File

@@ -31,13 +31,6 @@ namespace
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);

View File

@@ -597,6 +597,7 @@ public:
virtual void LoadDBVersion() = 0;
[[nodiscard]] virtual char const* GetDBVersion() const = 0;
virtual void LoadAutobroadcasts() = 0;
virtual void LoadMotd() = 0;
virtual void UpdateAreaDependentAuras() = 0;
[[nodiscard]] virtual uint32 GetCleaningFlags() const = 0;
virtual void SetCleaningFlags(uint32 flags) = 0;

View File

@@ -442,8 +442,6 @@ void World::LoadConfigSettings(bool reload)
SetPlayerAmountLimit(sConfigMgr->GetOption<int32>("PlayerLimit", 1000));
}
Motd::SetMotd(sConfigMgr->GetOption<std::string>("Motd", "Welcome to an AzerothCore server"));
///- Read ticket system setting from the config file
_bool_configs[CONFIG_ALLOW_TICKETS] = sConfigMgr->GetOption<bool>("AllowTickets", true);
_bool_configs[CONFIG_DELETE_CHARACTER_TICKET_TRACE] = sConfigMgr->GetOption<bool>("DeletedCharacterTicketTrace", false);
@@ -1993,6 +1991,10 @@ void World::SetInitialWorldSettings()
LOG_INFO("server.loading", "Loading Autobroadcasts...");
LoadAutobroadcasts();
///- Load Motd
LOG_INFO("server.loading", "Loading MotD...");
LoadMotd();
///- Load and initialize scripts
sObjectMgr->LoadSpellScripts(); // must be after load Creature/Gameobject(Template/Data)
sObjectMgr->LoadEventScripts(); // must be after load Creature/Gameobject(Template/Data)
@@ -2257,6 +2259,39 @@ void World::LoadAutobroadcasts()
LOG_INFO("server.loading", " ");
}
void World::LoadMotd()
{
uint32 oldMSTime = getMSTime();
uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_MOTD);
stmt->SetData(0, realmId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
std::string motd;
if (result)
{
Field* fields = result->Fetch();
motd = fields[0].Get<std::string>();
}
else
{
LOG_WARN("server.loading", ">> Loaded 0 motd definitions. DB table `motd` is empty for this realm!");
LOG_INFO("server.loading", " ");
}
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"*/;;
Motd::SetMotd(motd);
LOG_INFO("server.loading", ">> Loaded Motd Definitions in {} ms", GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
/// Update the World !
void World::Update(uint32 diff)
{

View File

@@ -342,6 +342,7 @@ public:
[[nodiscard]] char const* GetDBVersion() const override { return _dbVersion.c_str(); }
void LoadAutobroadcasts() override;
void LoadMotd() override;
void UpdateAreaDependentAuras() override;

View File

@@ -32,6 +32,7 @@ EndScriptData */
#include "LFGMgr.h"
#include "Language.h"
#include "MapMgr.h"
#include "ServerMotd.h"
#include "ObjectMgr.h"
#include "ScriptMgr.h"
#include "SkillDiscovery.h"
@@ -80,6 +81,7 @@ public:
{ "areatrigger_tavern", HandleReloadAreaTriggerTavernCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "areatrigger_teleport", HandleReloadAreaTriggerTeleportCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "autobroadcast", HandleReloadAutobroadcastCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "motd", HandleReloadMotdCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "broadcast_text", HandleReloadBroadcastTextCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "battleground_template", HandleReloadBattlegroundTemplate, SEC_ADMINISTRATOR, Console::Yes },
{ "command", HandleReloadCommandCommand, SEC_ADMINISTRATOR, Console::Yes },
@@ -209,6 +211,7 @@ public:
HandleReloadVehicleTemplateAccessoryCommand(handler);
HandleReloadAutobroadcastCommand(handler);
HandleReloadMotdCommand(handler);
HandleReloadBroadcastTextCommand(handler);
HandleReloadBattlegroundTemplate(handler);
return true;
@@ -403,6 +406,15 @@ public:
return true;
}
static bool HandleReloadMotdCommand(ChatHandler* handler)
{
LOG_INFO("server.loading", "Re-Loading Motd...");
sWorld->LoadMotd();
handler->SendGlobalGMSysMessage("DB table `motd` reloaded.");
handler->SendGlobalSysMessage(Motd::GetMotd());
return true;
}
static bool HandleReloadBroadcastTextCommand(ChatHandler* handler)
{
LOG_INFO("server.loading", "Re-Loading Broadcast texts...");

View File

@@ -498,10 +498,40 @@ public:
}
// Define the 'Message of the day' for the realm
static bool HandleServerSetMotdCommand(ChatHandler* handler, std::string motd)
static bool HandleServerSetMotdCommand(ChatHandler* handler, std::string realmId, Tail motd)
{
Motd::SetMotd(motd);
handler->PSendSysMessage(LANG_MOTD_NEW, motd);
std::wstring wMotd = std::wstring();
std::string strMotd = std::string();
if (realmId.empty())
{
return false;
}
if (motd.empty())
{
return false;
}
if (!Utf8toWStr(motd, wMotd))
{
return false;
}
if (!WStrToUtf8(wMotd, strMotd))
{
return false;
}
LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_REP_MOTD);
stmt->SetData(0, Acore::StringTo<int32>(realmId).value());
stmt->SetData(1, strMotd);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
sWorld->LoadMotd();
handler->PSendSysMessage(LANG_MOTD_NEW, Acore::StringTo<int32>(realmId).value(), strMotd);
return true;
}

View File

@@ -113,6 +113,7 @@ public:
MOCK_METHOD(void, LoadDBVersion, ());
MOCK_METHOD(char const *, GetDBVersion, (), (const));
MOCK_METHOD(void, LoadAutobroadcasts, ());
MOCK_METHOD(void, LoadMotd, ());
MOCK_METHOD(void, UpdateAreaDependentAuras, ());
MOCK_METHOD(uint32, GetCleaningFlags, (), (const));
MOCK_METHOD(void, SetCleaningFlags, (uint32 flags), ());