5376: Minor improvement for pagination r=heinrich5991 a=def-

I thought I had committed this for #5375, but forgot

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-06-09 09:27:19 +00:00 committed by GitHub
commit 52c78e9fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -505,31 +505,32 @@ void CNetBan::ConBans(IConsole::IResult *pResult, void *pUser)
int Page = pResult->NumArguments() > 0 ? pResult->GetInteger(0) : 0;
static const int EntriesPerPage = 20;
const int Start = Page * EntriesPerPage;
const int End = (Page + 1) * EntriesPerPage;
int Count = 0;
char aBuf[256], aMsg[256];
int i = 0;
for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext, i++)
for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext, Count++)
{
if(i < Page * EntriesPerPage || i >= (Page + 1) * EntriesPerPage)
if(Count < Start || Count >= End)
{
continue;
}
pThis->MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST);
str_format(aMsg, sizeof(aMsg), "#%i %s", Count++, aBuf);
str_format(aMsg, sizeof(aMsg), "#%i %s", Count, aBuf);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
}
for(CBanRange *pBan = pThis->m_BanRangePool.First(); pBan; pBan = pBan->m_pNext, i++)
for(CBanRange *pBan = pThis->m_BanRangePool.First(); pBan; pBan = pBan->m_pNext, Count++)
{
if(i < Page * EntriesPerPage || i >= (Page + 1) * EntriesPerPage)
if(Count < Start || Count >= End)
{
continue;
}
pThis->MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST);
str_format(aMsg, sizeof(aMsg), "#%i %s", Count++, aBuf);
str_format(aMsg, sizeof(aMsg), "#%i %s", Count, aBuf);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
}
str_format(aMsg, sizeof(aMsg), "%d %s", Count, Count == 1 ? "ban" : "bans");
str_format(aMsg, sizeof(aMsg), "%d %s, showing entries %d - %d", Count, Count == 1 ? "ban" : "bans", Start, End - 1);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
}