fix(Scripts/Command): prevent crash on set motd (#18203)

* prevent crash on set motd

* updated version

* another version

* Update cs_server.cpp

---------

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
MellianStudios
2024-01-21 00:04:46 +01:00
committed by GitHub
parent 7f7f18e489
commit a89fa73b72
2 changed files with 7 additions and 13 deletions

View File

@@ -0,0 +1,2 @@
--
UPDATE `command` SET `help`='Syntax: .server set motd Optional($realmId) $MOTD\r\n\r\nSet server Message of the day for the specified $realmId.\r\nIf $realmId is not provided it will update for the current realm.' WHERE `name`='server set motd';

View File

@@ -514,40 +514,32 @@ public:
}
// Define the 'Message of the day' for the realm
static bool HandleServerSetMotdCommand(ChatHandler* handler, std::string realmId, Tail motd)
static bool HandleServerSetMotdCommand(ChatHandler* handler, Optional<int32> realmId, Tail motd)
{
std::wstring wMotd = std::wstring();
std::string strMotd = std::string();
if (realmId.empty())
{
return false;
}
if (!realmId)
realmId = static_cast<int32>(realm.Id.Realm);
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(0, realmId.value());
stmt->SetData(1, strMotd);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
sMotdMgr->LoadMotd();
handler->PSendSysMessage(LANG_MOTD_NEW, Acore::StringTo<int32>(realmId).value(), strMotd);
handler->PSendSysMessage(LANG_MOTD_NEW, realmId.value(), strMotd);
return true;
}