Add ban_region

This commit is contained in:
Learath 2020-08-19 12:38:49 +03:00
parent c59ba2acd0
commit 6a936602aa
4 changed files with 22 additions and 0 deletions

View file

@ -48,6 +48,8 @@ public:
virtual const char *GetString(unsigned Index) = 0;
virtual ColorHSLA GetColor(unsigned Index, bool Light) = 0;
virtual void RemoveArgument(unsigned Index) = 0;
int NumArguments() const { return m_NumArgs; }
int m_ClientID;

View file

@ -146,6 +146,7 @@ void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer *
// overwrites base command, todo: improve this
Console()->Register("ban", "s[ip|id] ?i[minutes] r[reason]", CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason");
Console()->Register("ban_region", "s[region] s[ip|id] ?i[minutes] r[reason]", CFGFLAG_SERVER|CFGFLAG_STORE, ConBanRegion, this, "Ban player in a region");
}
template<class T>
@ -245,6 +246,15 @@ void CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
ConBan(pResult, pUser);
}
void CServerBan::ConBanRegion(IConsole::IResult *pResult, void *pUser)
{
const char *pRegion = pResult->GetString(0);
if(str_comp_nocase(pRegion, g_Config.m_SvSqlServerName))
return;
pResult->RemoveArgument(0);
ConBanExt(pResult, pUser);
}
void CServer::CClient::Reset()
{

View file

@ -83,6 +83,7 @@ public:
virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason);
static void ConBanExt(class IConsole::IResult *pResult, void *pUser);
static void ConBanRegion(class IConsole::IResult *pResult, void *pUser);
};

View file

@ -121,6 +121,15 @@ class CConsole : public IConsole
virtual float GetFloat(unsigned Index);
virtual ColorHSLA GetColor(unsigned Index, bool Light);
virtual void RemoveArgument(unsigned Index)
{
dbg_assert(Index < m_NumArgs, "invalid argument index");
for(unsigned i = Index; i < m_NumArgs - 1; i++)
m_apArgs[i] = m_apArgs[i + 1];
m_apArgs[m_NumArgs--] = 0;
}
// DDRace
enum