Skip to content

Commit

Permalink
fix: forge history
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Nov 16, 2024
1 parent 4ee11d6 commit 726db1b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5745,14 +5745,21 @@ void ProtocolGame::sendForgeHistory(uint8_t page) {
page = page + 1;
auto historyVector = player->getForgeHistory();
auto historyVectorLen = historyVector.size();
uint16_t lastPage = (1 < std::floor((historyVectorLen - 1) / 9) + 1) ? static_cast<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1) : 1;
uint16_t currentPage = (lastPage < page) ? lastPage : page;

uint16_t currentPage, lastPage = 1;
uint16_t pageFirstEntry, pageLastEntry = 0;

Check warning on line 5750 in src/server/network/protocol/protocolgame.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/server/network/protocol/protocolgame.cpp#L5750

The scope of the variable 'pageFirstEntry' can be reduced.
Raw output
src/server/network/protocol/protocolgame.cpp:5750:The scope of the variable 'pageFirstEntry' can be reduced.

Check warning on line 5750 in src/server/network/protocol/protocolgame.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/server/network/protocol/protocolgame.cpp#L5750

The scope of the variable 'pageLastEntry' can be reduced.
Raw output
src/server/network/protocol/protocolgame.cpp:5750:The scope of the variable 'pageLastEntry' can be reduced.

Check warning on line 5750 in src/server/network/protocol/protocolgame.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/server/network/protocol/protocolgame.cpp#L5750

Variable 'pageLastEntry' is assigned a value that is never used.
Raw output
src/server/network/protocol/protocolgame.cpp:5750:Variable 'pageLastEntry' is assigned a value that is never used.

std::vector<ForgeHistory> historyPerPage;
uint16_t pageFirstEntry = (0 < historyVectorLen - (currentPage - 1) * 9) ? historyVectorLen - (currentPage - 1) * 9 : 0;
uint16_t pageLastEntry = (0 < historyVectorLen - currentPage * 9) ? historyVectorLen - currentPage * 9 : 0;
for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) {
historyPerPage.emplace_back(historyVector[entry - 1]);
if (historyVectorLen > 0) {
lastPage = std::clamp<uint16_t>(std::floor((historyVectorLen - 1) / 9) + 1, 0, std::numeric_limits<uint16_t>::max());
currentPage = (lastPage < page) ? lastPage : page;

pageFirstEntry = std::clamp<uint16_t>(historyVectorLen - (currentPage - 1) * 9, 0, std::numeric_limits<uint16_t>::max());
pageLastEntry = historyVectorLen > currentPage * 9 ? std::clamp<uint16_t>(historyVectorLen - currentPage * 9, 0, std::numeric_limits<uint16_t>::max()) : 0;

for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) {
historyPerPage.emplace_back(historyVector[entry - 1]);
}
}

auto historyPageToSend = historyPerPage.size();
Expand Down

0 comments on commit 726db1b

Please sign in to comment.