Make bans command better

Update src/engine/shared/netban.cpp

Remove the word "currently" for the empty ban list message.

Co-authored-by: Dennis Felsing <dennis@felsing.org>

Update src/engine/shared/netban.cpp

Text format refactor, adding "currently"

Co-authored-by: Dennis Felsing <dennis@felsing.org>
This commit is contained in:
Rei-Tw 2024-08-13 20:47:38 +02:00 committed by Loic Kassel
parent 5a2891933c
commit 035b4a1447

View file

@ -285,7 +285,7 @@ void CNetBan::Init(IConsole *pConsole, IStorage *pStorage)
Console()->Register("unban", "s[ip|entry]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnban, this, "Unban ip/banlist entry"); Console()->Register("unban", "s[ip|entry]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnban, this, "Unban ip/banlist entry");
Console()->Register("unban_range", "s[first ip] s[last ip]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnbanRange, this, "Unban ip range"); Console()->Register("unban_range", "s[first ip] s[last ip]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnbanRange, this, "Unban ip range");
Console()->Register("unban_all", "", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnbanAll, this, "Unban all entries"); Console()->Register("unban_all", "", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConUnbanAll, this, "Unban all entries");
Console()->Register("bans", "?i[page]", CFGFLAG_SERVER | CFGFLAG_MASTER, ConBans, this, "Show banlist (page 0 by default, 20 entries per page)"); Console()->Register("bans", "?i[page]", CFGFLAG_SERVER | CFGFLAG_MASTER, ConBans, this, "Show banlist (page 1 by default, 20 entries per page)");
Console()->Register("bans_save", "s[file]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConBansSave, this, "Save banlist in a file"); Console()->Register("bans_save", "s[file]", CFGFLAG_SERVER | CFGFLAG_MASTER | CFGFLAG_STORE, ConBansSave, this, "Save banlist in a file");
} }
@ -479,13 +479,32 @@ void CNetBan::ConBans(IConsole::IResult *pResult, void *pUser)
{ {
CNetBan *pThis = static_cast<CNetBan *>(pUser); CNetBan *pThis = static_cast<CNetBan *>(pUser);
int Page = pResult->NumArguments() > 0 ? pResult->GetInteger(0) : 0; int Page = pResult->NumArguments() > 0 ? pResult->GetInteger(0) : 1;
static const int s_EntriesPerPage = 20; static const int s_EntriesPerPage = 20;
const int Start = Page * s_EntriesPerPage; const int Start = (Page - 1) * s_EntriesPerPage;
const int End = (Page + 1) * s_EntriesPerPage; const int End = Page * s_EntriesPerPage;
const int NumBans = pThis->m_BanAddrPool.Num() + pThis->m_BanRangePool.Num();
const int NumPages = NumBans / s_EntriesPerPage + 1;
char aBuf[256], aMsg[256];
if(NumBans == 0)
{
str_format(aMsg, sizeof(aMsg), "The ban list is empty.");
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
return;
}
if(Page <= 0 || Page > NumPages)
{
str_format(aMsg, sizeof(aMsg), "Invalid page number. There %s %d %s available.", NumPages == 1 ? "is" : "are", NumPages, NumPages == 1 ? "page" : "pages");
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
return;
}
int Count = 0; int Count = 0;
char aBuf[256], aMsg[256];
for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext, Count++) for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext, Count++)
{ {
if(Count < Start || Count >= End) if(Count < Start || Count >= End)
@ -506,7 +525,7 @@ void CNetBan::ConBans(IConsole::IResult *pResult, void *pUser)
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); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
} }
str_format(aMsg, sizeof(aMsg), "%d %s, showing entries %d - %d", Count, Count == 1 ? "ban" : "bans", Start, End - 1); str_format(aMsg, sizeof(aMsg), "%d %s, showing entries %d - %d (page %d/%d)", Count, Count == 1 ? "ban" : "bans", Start, End > Count ? Count - 1 : End - 1, Page, NumPages);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg);
} }