mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
feat(Scripts/Commands): Parse money string and validate sendmoney com… (#25702)
This commit is contained in:
@@ -189,17 +189,31 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleSendMoneyCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString subject, QuotedString text, uint32 money)
|
static bool HandleSendMoneyCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString subject, QuotedString text, Tail money)
|
||||||
{
|
{
|
||||||
if (!target)
|
if (!target)
|
||||||
{
|
|
||||||
target = PlayerIdentifier::FromTargetOrSelf(handler);
|
target = PlayerIdentifier::FromTargetOrSelf(handler);
|
||||||
}
|
|
||||||
|
|
||||||
if (!target)
|
if (!target)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
auto IsExistWord = [](std::string_view line, std::initializer_list<std::string_view> words)
|
||||||
|
{
|
||||||
|
for (auto const& word : words)
|
||||||
|
{
|
||||||
|
if (line.find(word) != std::string_view::npos)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
Optional<int32> moneyToAddO = IsExistWord(money, { "g", "s", "c" }) ? MoneyStringToMoney(money) : Acore::StringTo<int32>(money);
|
||||||
|
|
||||||
|
if (!moneyToAddO)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int32 moneyToAdd = *moneyToAddO;
|
||||||
|
|
||||||
// from console show not existed sender
|
// from console show not existed sender
|
||||||
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : 0, MAIL_STATIONERY_GM);
|
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : 0, MAIL_STATIONERY_GM);
|
||||||
@@ -207,7 +221,7 @@ public:
|
|||||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||||
|
|
||||||
MailDraft(subject, text)
|
MailDraft(subject, text)
|
||||||
.AddMoney(money)
|
.AddMoney(moneyToAdd)
|
||||||
.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
|
.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
|
||||||
|
|
||||||
CharacterDatabase.CommitTransaction(trans);
|
CharacterDatabase.CommitTransaction(trans);
|
||||||
|
|||||||
Reference in New Issue
Block a user