Fixed Ban --->All<--- System Issues

Also it's not possible do hide the Ban message by setting the reason trying to connect too soon from rcon

Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
GreYFoXGTi 2010-08-22 18:06:20 +02:00
parent f2a94d37ea
commit 999e8590e7
4 changed files with 271 additions and 280 deletions

View file

@ -232,7 +232,7 @@ function build(settings)
engine, client, game_editor, zlib, pnglite, wavpack,
client_link_other, client_osxlaunch)
server_exe = Link(server_settings, "DDRace_Trunk-Server-Server", engine, server,
server_exe = Link(server_settings, "DDRace_Trunk-Server", engine, server,
game_shared, game_server, zlib)
serverlaunch = {}

View file

@ -884,7 +884,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
m_aClients[ClientId].m_Addr.ip[1],
m_aClients[ClientId].m_Addr.ip[2],
m_aClients[ClientId].m_Addr.ip[3]);
//BanAdd(m_aClients[ClientId].m_Addr, g_Config.m_SvRconTriesBantime); // bye
BanAdd(m_aClients[ClientId].m_Addr, g_Config.m_SvRconTriesBantime,"Trying Rcon commands withou permission"); // bye
}
@ -1371,11 +1371,11 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
NETADDR Addr;
char aAddrStr[128], Bufz[100];
const char *pStr = pResult->GetString(0);
int Minutes = 30, jkl;//????
int Seconds = 30, jkl;//????
str_format(Bufz, sizeof(Bufz), "");
if(pResult->NumArguments() > 1)
Minutes = pResult->GetInteger(1);
Seconds = pResult->GetInteger(1);
if(pResult->NumArguments() > 2)
{
@ -1390,7 +1390,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
if(net_addr_from_str(&Addr, pStr) == 0)
((CServer *)pUser)->BanAdd(Addr, Minutes*60, Bufz);
((CServer *)pUser)->BanAdd(Addr, Seconds, Bufz);
else if(StrAllnum(pStr))
{
int ClientId = str_toint(pStr);
@ -1404,14 +1404,14 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
}
Addr = ((CServer *)pUser)->m_NetServer.ClientAddr(ClientId);
((CServer *)pUser)->BanAdd(Addr, Minutes*60, Bufz);
((CServer *)pUser)->BanAdd(Addr, Seconds, Bufz);
}
Addr.port = 0;
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
if(Minutes)
dbg_msg("server", "banned %s for %d Minutes", aAddrStr, Minutes);
if(Seconds)
dbg_msg("server", "banned %s for %d Second(s)", aAddrStr, Seconds);
else
dbg_msg("server", "banned %s for life", aAddrStr);
}
@ -1534,7 +1534,7 @@ void CServer::RegisterCommands()
m_pConsole = Kernel()->RequestInterface<IConsole>();
Console()->Register("kick", "i", CFGFLAG_SERVER, ConKick, this, "", 2);
Console()->Register("ban", "s?i?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s?s", CFGFLAG_SERVER, ConBan, this, "Ban player",2); //horrible long string
Console()->Register("ban", "s?i?r", CFGFLAG_SERVER, ConBan, this, "Ban player",2); //horrible long string
Console()->Register("unban", "s", CFGFLAG_SERVER, ConUnban, this, "", 3);
Console()->Register("bans", "", CFGFLAG_SERVER, ConBans, this, "", 2);
Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "", 1);

View file

@ -218,6 +218,7 @@ public:
NETADDR m_Addr;
int m_Expires;
char m_Reason[100];
bool m_Soon;
};
private:
@ -277,7 +278,7 @@ public:
// banning
int BanAdd(NETADDR Addr, int Seconds, const char *Reason);
int BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason);
int BanAddNoDrop(NETADDR Addr, int Seconds);
int BanRemove(NETADDR Addr);
int BanNum(); // caution, slow
int BanGet(int Index, CBanInfo *pInfo); // caution, slow

View file

@ -80,8 +80,6 @@ int CNetServer::Drop(int ClientID, const char *pReason)
{
// TODO: insert lots of checks here
NETADDR Addr = ClientAddr(ClientID);
char Bufz[100];
str_format( Bufz, sizeof(Bufz),"trying to connect so soon");
dbg_msg("net_server", "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"",
ClientID,
Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3],
@ -92,7 +90,7 @@ int CNetServer::Drop(int ClientID, const char *pReason)
if(m_pfnDelClient)
m_pfnDelClient(ClientID, m_UserPtr);
m_aSlots[ClientID].m_Connection.Disconnect(pReason);
BanAddNoDrop(Addr, g_Config.m_SvReconnectTime, Bufz);
BanAddNoDrop(Addr, g_Config.m_SvReconnectTime);
return 0;
}
@ -151,7 +149,6 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
// remove the port
Addr.port = 0;
if(Seconds)
Stamp = time_timestamp() + Seconds;
@ -160,11 +157,11 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0);
if(pBan)
{
// adjust the ban
if (pBan->m_Info.m_Expires > Seconds || pBan->m_Info.m_Expires == 0xffffffff)
if(pBan->m_Info.m_Expires==-1 || pBan->m_Info.m_Expires>Stamp)
return 0;
// adjust the ban
pBan->m_Info.m_Expires = Stamp;
pBan->m_Info.m_Soon = false;
strcpy(pBan->m_Info.m_Reason, Reason);
return 0;
}
@ -179,6 +176,8 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
// setup the ban info
pBan->m_Info.m_Expires = Stamp;
pBan->m_Info.m_Addr = Addr;
pBan->m_Info.m_Soon = false;
strcpy(pBan->m_Info.m_Reason, Reason);
// add it to the ban hash
MACRO_LIST_LINK_FIRST(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext);
@ -214,20 +213,15 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
MACRO_LIST_LINK_FIRST(pBan, m_BanPool_FirstUsed, m_pPrev, m_pNext);
}
}
// drop banned clients
{
char Buf[128];
NETADDR BanAddr;
if(Seconds) {
str_format(Buf, sizeof(Buf), "you have been banned for %d minutes", Seconds/60);
strcat(Buf, Reason);
} else {
str_format(Buf, sizeof(Buf), "you have been banned for life");
strcat(Buf, Reason);
}
if(Seconds)
str_format(Buf, sizeof(Buf), "You have been banned for %d second(s) for %s", Seconds,Reason);
else
str_format(Buf, sizeof(Buf), "You have been banned for life for %s",Reason);
for(int i = 0; i < MaxClients(); i++)
{
BanAddr = m_aSlots[i].m_Connection.PeerAddress();
@ -240,9 +234,7 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
return 0;
}
int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds)
{
int IpHash = (Addr.ip[0]+Addr.ip[1]+Addr.ip[2]+Addr.ip[3])&0xff;
int Stamp = -1;
@ -250,7 +242,6 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
// remove the port
Addr.port = 0;
if(Seconds)
Stamp = time_timestamp() + Seconds;
@ -259,12 +250,11 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0);
if(pBan)
{
// adjust the ban
if (pBan->m_Info.m_Expires > Seconds || pBan->m_Info.m_Expires == 0xffffffff)
if(pBan->m_Info.m_Expires==-1 || pBan->m_Info.m_Expires>Stamp)
return 0;
// adjust the ban
pBan->m_Info.m_Expires = Stamp;
strcpy(pBan->m_Info.m_Reason, Reason);
pBan->m_Info.m_Soon = true;
return 0;
}
@ -278,7 +268,7 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
// setup the ban info
pBan->m_Info.m_Expires = Stamp;
pBan->m_Info.m_Addr = Addr;
strcpy(pBan->m_Info.m_Reason, Reason);
pBan->m_Info.m_Soon = true;
// add it to the ban hash
MACRO_LIST_LINK_FIRST(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext);
@ -316,7 +306,6 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
return 0;
}
int CNetServer::Update()
{
int Now = time_timestamp();
@ -328,7 +317,7 @@ int CNetServer::Update()
}
// remove expired bans
while(m_BanPool_FirstUsed && m_BanPool_FirstUsed->m_Info.m_Expires < Now)
while(m_BanPool_FirstUsed && m_BanPool_FirstUsed->m_Info.m_Expires < Now && m_BanPool_FirstUsed->m_Info.m_Expires != -1)
{
CBan *pBan = m_BanPool_FirstUsed;
BanRemoveByObject(pBan);
@ -379,16 +368,17 @@ int CNetServer::Recv(CNetChunk *pChunk)
{
// banned, reply with a message
char BanStr[128];
if(pBan->m_Info.m_Expires && (pBan->m_Info.m_Expires!=0xffffffff))
if(pBan->m_Info.m_Expires && (pBan->m_Info.m_Expires!=-1))
{
int Mins = ((pBan->m_Info.m_Expires - Now))/60;
if(Mins > 1)
str_format(BanStr, sizeof(BanStr), "Banned for %d minute(s) for %s", Mins, pBan->m_Info.m_Reason);
else
str_format(BanStr, sizeof(BanStr), "Banned for %d minute(s) for %s", (pBan->m_Info.m_Expires - Now), pBan->m_Info.m_Reason);
str_format(BanStr, sizeof(BanStr), "Banned for %d second(s) for %s", (pBan->m_Info.m_Expires - Now), pBan->m_Info.m_Reason);
}
else
str_format(BanStr, sizeof(BanStr), "Banned for life for %s", pBan->m_Info.m_Reason);
if(!pBan->m_Info.m_Soon)
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, BanStr, str_length(BanStr)+1);
continue;
}