From ed97ae9cb902188de81dd34dc34657368beda41b Mon Sep 17 00:00:00 2001 From: Stitch626 Date: Mon, 2 Jan 2017 20:00:01 +0100 Subject: [PATCH] Ban-system edit --- src/engine/server/server.cpp | 10 +++++++++- src/engine/server/server.h | 2 ++ src/engine/shared/network_server.cpp | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index f673c2c51..bb5618b36 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -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 ?i ?r", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason"); + Console()->Register("ban", "s ?i ?r", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason"); } template @@ -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); @@ -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)) { @@ -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); } } @@ -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; } } diff --git a/src/engine/server/server.h b/src/engine/server/server.h index e9d8b7ed1..d67988eec 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -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; }; diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 6a147e21b..722857594 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -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; @@ -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)