Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forge history #3124

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5745,14 +5745,23 @@
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 = 1;
uint16_t lastPage = 1;
uint16_t pageFirstEntry = 0;

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

Variable 'pageFirstEntry' is assigned a value that is never used.
Raw output
src/server/network/protocol/protocolgame.cpp:5751:Variable 'pageFirstEntry' is assigned a value that is never used.
uint16_t pageLastEntry = 0;

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

Variable 'pageLastEntry' is assigned a value that is never used.
Raw output
src/server/network/protocol/protocolgame.cpp:5752: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
Loading