diff options
author | Treeston <treeston.mmoc@gmail.com> | 2020-08-20 17:56:10 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-02-04 00:27:11 +0100 |
commit | 15d75dea10c058364a2577b73a627b4701d4ce01 (patch) | |
tree | 65f7202eeb793b019c090dd157800c0ed2e4fa92 /src/server/game/Warden/WardenWin.cpp | |
parent | 317bb198b1152aafe8a48137e3748423eca02448 (diff) |
Core/Warden: More refactors lifted from #25286.
(cherry picked from commit a3971ca4b05e2913850b6d4fe7d40884fa645fa0)
Diffstat (limited to 'src/server/game/Warden/WardenWin.cpp')
-rw-r--r-- | src/server/game/Warden/WardenWin.cpp | 101 |
1 files changed, 47 insertions, 54 deletions
diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp index d23e24a63e0..63bf304e6e2 100644 --- a/src/server/game/Warden/WardenWin.cpp +++ b/src/server/game/Warden/WardenWin.cpp @@ -39,13 +39,13 @@ WardenWin::WardenWin() : Warden(), _serverTicks(0) { - _memChecks = sWardenCheckMgr->GetAvailableMemoryChecks(); - Trinity::Containers::RandomShuffle(_memChecks); - _memChecksIt = _memChecks.begin(); - - _otherChecks = sWardenCheckMgr->GetAvailableOtherChecks(); - Trinity::Containers::RandomShuffle(_otherChecks); - _otherChecksIt = _otherChecks.begin(); + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) + { + auto& [checks, checksIt] = _checks[category]; + checks = sWardenCheckMgr->GetAvailableChecks(category); + Trinity::Containers::RandomShuffle(checks); + checksIt = checks.begin(); + } } void WardenWin::Init(WorldSession* session, SessionKey const& K) @@ -184,52 +184,43 @@ void WardenWin::RequestChecks() TC_LOG_DEBUG("warden", "Request data"); // If all checks were done, fill the todo list again - if (_memChecksIt == _memChecks.end()) - { - TC_LOG_DEBUG("warden", "Finished all mem checks, re-shuffling"); - Trinity::Containers::RandomShuffle(_memChecks); - _memChecksIt = _memChecks.begin(); - } - - if (_otherChecksIt == _otherChecks.end()) + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) { - TC_LOG_DEBUG("warden", "Finished all other checks, re-shuffling"); - Trinity::Containers::RandomShuffle(_otherChecks); - _otherChecksIt = _otherChecks.begin(); + auto& [checks, checksIt] = _checks[category]; + if (checksIt == checks.end()) + { + TC_LOG_DEBUG("warden", "Finished all %s checks, re-shuffling", EnumUtils::ToConstant(category)); + Trinity::Containers::RandomShuffle(checks); + checksIt = checks.begin(); + } } _serverTicks = GameTime::GetGameTimeMS(); - _currentChecks.clear(); // Build check request ByteBuffer buff; buff << uint8(WARDEN_SMSG_CHEAT_CHECKS_REQUEST); - for (uint32 i = 0; i < sWorld->getIntConfig(CONFIG_WARDEN_NUM_MEM_CHECKS); ++i) + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) { - // If todo list is done break loop (will be filled on next Update() run) - if (_memChecksIt == _memChecks.end()) - break; - - _currentChecks.push_back(*(_memChecksIt++)); - } + auto& [checks, checksIt] = _checks[category]; + for (uint32 i = 0, n = sWorld->getIntConfig(GetWardenCategoryCountConfig(category)); i < n; ++i) + { + if (checksIt == checks.end()) // all checks were already sent, list will be re-filled on next Update() run + break; - for (uint32 i = 0; i < sWorld->getIntConfig(CONFIG_WARDEN_NUM_OTHER_CHECKS); ++i) - { - // If todo list is done break loop (will be filled on next Update() run) - if (_otherChecksIt == _otherChecks.end()) - break; + uint16 const id = *(checksIt++); - uint16 const id = *(_otherChecksIt++); + WardenCheck const& check = sWardenCheckMgr->GetCheckData(id); + if (!check.Str.empty()) + { + buff << uint8(check.Str.size()); + buff.append(check.Str.data(), check.Str.size()); + } - WardenCheck const& check = sWardenCheckMgr->GetCheckData(id); - if (!check.Str.empty()) - { - buff << uint8(check.Str.size()); - buff.append(check.Str.data(), check.Str.size()); + _currentChecks.push_back(id); } - _currentChecks.push_back(id); } uint8 xorByte = _inputKey[0]; @@ -389,6 +380,7 @@ void WardenWin::HandleCheckResult(ByteBuffer &buff) std::vector<uint8> response; response.resize(check.Length); buff.read(response.data(), response.size()); + WardenCheckResult const& expected = sWardenCheckMgr->GetCheckResult(id); if (response != expected) { @@ -422,10 +414,10 @@ void WardenWin::HandleCheckResult(ByteBuffer &buff) uint8 Lua_Result; buff >> Lua_Result; - if (Lua_Result != 0) + if (Lua_Result == 0) { uint8 luaStrLen = buff.read<uint8>(); - if (luaStrLen == 0) + if (luaStrLen != 0) { std::string str; str.resize(luaStrLen); @@ -483,28 +475,29 @@ void WardenWin::HandleCheckResult(ByteBuffer &buff) size_t WardenWin::DEBUG_ForceSpecificChecks(std::vector<uint16> const& checks) { - std::vector<uint16>::iterator memChecksIt = _memChecks.begin(); - std::vector<uint16>::iterator otherChecksIt = _otherChecks.begin(); + std::array<std::vector<uint16>::iterator, NUM_CHECK_CATEGORIES> swapPositions; + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) + swapPositions[category] = _checks[category].first.begin(); size_t n = 0; for (uint16 check : checks) { - if (auto it = std::find(memChecksIt, _memChecks.end(), check); it != _memChecks.end()) - { - std::iter_swap(it, memChecksIt); - ++memChecksIt; - ++n; - } - else if (auto it = std::find(otherChecksIt, _otherChecks.end(), check); it != _otherChecks.end()) + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) { - std::iter_swap(it, otherChecksIt); - ++otherChecksIt; - ++n; + std::vector<uint16>& checks = _checks[category].first; + std::vector<uint16>::iterator& swapPos = swapPositions[category]; + if (auto it = std::find(swapPos, checks.end(), check); it != checks.end()) + { + std::iter_swap(swapPos, it); + ++swapPos; + ++n; + break; + } } } - _memChecksIt = _memChecks.begin(); - _otherChecksIt = _otherChecks.begin(); + for (WardenCheckCategory category : EnumUtils::Iterate<WardenCheckCategory>()) + _checks[category].second = _checks[category].first.begin(); return n; } |