Skip to content

Commit

Permalink
Ban-system edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stitch626 committed Jan 2, 2017
1 parent 4d89f93 commit ed97ae9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer*
m_pServer = pServer;

// overwrites base command, todo: improve this
Console()->Register("ban", "s<username or uid> ?i<minutes> ?r<reason>", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason");
Console()->Register("ban", "s<username or clientid> ?i<minutes> ?r<reason>", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason");
}

template<class T>
Expand Down Expand Up @@ -239,12 +239,17 @@ int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seco
return Result;

// drop banned clients

// don't drop it like that. just kick the desired guy
typename T::CDataType Data = *pData;
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY)
continue;

if(m_BanID != i)
continue;

if(NetMatch(&Data, Server()->m_NetServer.ClientAddr(i)))
{
CNetHash NetHash(&Data);
Expand Down Expand Up @@ -278,6 +283,7 @@ bool CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
const char *pStr = pResult->GetString(0);
int Minutes = pResult->NumArguments()>1 ? clamp(pResult->GetInteger(1), 0, 44640) : 30;
const char *pReason = pResult->NumArguments()>2 ? pResult->GetString(2) : "No reason given";
pThis->m_BanID = -1;

if(StrAllnum(pStr))
{
Expand All @@ -286,6 +292,7 @@ bool CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid client id)");
else
{
pThis->m_BanID = ClientID;//to ban the right guy, not his brother or so :P
pThis->BanAddr(pThis->Server()->m_NetServer.ClientAddr(ClientID), Minutes*60, pReason);
}
}
Expand All @@ -298,6 +305,7 @@ bool CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
{
NumPlayerFound++;
pThis->BanAddr(pThis->Server()->m_NetServer.ClientAddr(i), Minutes*60, pReason);
pThis->m_BanID = i;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class CServerBan : public CNetBan
virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason);

static bool ConBanExt(class IConsole::IResult *pResult, void *pUser);

int m_BanID;
};


Expand Down
16 changes: 14 additions & 2 deletions src/engine/shared/network_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,21 @@ int CNetServer::Recv(CNetChunk *pChunk)

// check if we just should drop the packet
char aBuf[128];
if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
/* if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
{
// banned, reply with a message
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1, NET_SECURITY_TOKEN_UNSUPPORTED);
continue;
}
}*/

if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0)
{
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
{
//refuse server info for banned clients (vanilla behavior)
if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
continue;

pChunk->m_Flags = NETSENDFLAG_CONNLESS;
pChunk->m_ClientID = -1;
pChunk->m_Address = Addr;
Expand Down Expand Up @@ -402,6 +406,14 @@ int CNetServer::Recv(CNetChunk *pChunk)
{
// not found, client that wants to connect

//refuse connect for banned clients
if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf)))
{
// banned, reply with a message
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1, NET_SECURITY_TOKEN_UNSUPPORTED);
continue;
}

if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL &&
m_RecvUnpacker.m_Data.m_DataSize > 1)
// got control msg with extra size (should support token)
Expand Down

0 comments on commit ed97ae9

Please sign in to comment.