mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Added 0.6.0 banmaster by @heinrich5991 #31
This commit is contained in:
parent
aba78d9e2e
commit
0d61c87fa1
|
@ -62,9 +62,14 @@ print("adding files")
|
|||
shutil.copy("readme.txt", package_dir)
|
||||
shutil.copy("license.txt", package_dir)
|
||||
shutil.copy("storage.cfg", package_dir)
|
||||
|
||||
# DDRace
|
||||
shutil.copy("announcement.txt", package_dir)
|
||||
shutil.copy("license_DDRace.txt", package_dir)
|
||||
|
||||
# banmaster
|
||||
shutil.copy("banmasters.cfg", package_dir)
|
||||
|
||||
if include_data and not use_bundle:
|
||||
os.mkdir(os.path.join(package_dir, "data"))
|
||||
copydir("data", package_dir)
|
||||
|
|
|
@ -11,7 +11,7 @@ enum
|
|||
{
|
||||
MAX_BANS=1024,
|
||||
BAN_REREAD_TIME=300,
|
||||
CFGFLAG_BANMASTER=1024,
|
||||
CFGFLAG_BANMASTER=32
|
||||
};
|
||||
|
||||
static const char BANMASTER_BANFILE[] = "bans.cfg";
|
||||
|
@ -32,17 +32,15 @@ static char m_aBindAddr[64] = "";
|
|||
CBan* CheckBan(NETADDR *pCheck)
|
||||
{
|
||||
for(int i = 0; i < m_NumBans; i++)
|
||||
{
|
||||
if(pCheck->ip[0] == m_aBans[i].m_Address.ip[0] && pCheck->ip[1] == m_aBans[i].m_Address.ip[1] &&
|
||||
pCheck->ip[2] == m_aBans[i].m_Address.ip[2] && pCheck->ip[3] == m_aBans[i].m_Address.ip[3])
|
||||
if(net_addr_comp(&m_aBans[i].m_Address, pCheck) == 0)
|
||||
return &m_aBans[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SendResponse(NETADDR *pAddr, NETADDR *pCheck)
|
||||
{
|
||||
static char aIpBan[sizeof(BANMASTER_IPBAN) + 32 + 256] = { 0 };
|
||||
static char aIpBan[sizeof(BANMASTER_IPBAN) + NETADDR_MAXSTRSIZE] = { 0 };
|
||||
static char *pIpBanContent = aIpBan + sizeof(BANMASTER_IPBAN);
|
||||
if (!aIpBan[0])
|
||||
mem_copy(aIpBan, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN));
|
||||
|
@ -56,7 +54,7 @@ int SendResponse(NETADDR *pAddr, NETADDR *pCheck)
|
|||
CBan* pBan = CheckBan(pCheck);
|
||||
if(pBan)
|
||||
{
|
||||
str_format(pIpBanContent, 32, "%d.%d.%d.%d", pCheck->ip[0], pCheck->ip[1], pCheck->ip[2], pCheck->ip[3]);
|
||||
net_addr_str(pCheck, pIpBanContent, NETADDR_MAXSTRSIZE);
|
||||
char *pIpBanReason = pIpBanContent + (str_length(pIpBanContent) + 1);
|
||||
str_copy(pIpBanReason, pBan->m_aReason, 256);
|
||||
|
||||
|
@ -65,22 +63,30 @@ int SendResponse(NETADDR *pAddr, NETADDR *pCheck)
|
|||
m_Net.Send(&p);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
return 0;
|
||||
/*else
|
||||
{
|
||||
p.m_DataSize = sizeof(BANMASTER_IPOK);
|
||||
p.m_pData = BANMASTER_IPOK;
|
||||
m_Net.Send(&p);
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void AddBan(NETADDR *pAddr, const char *pReason)
|
||||
{
|
||||
pAddr->port = 0;
|
||||
|
||||
CBan *pBan = CheckBan(pAddr);
|
||||
char aAddressStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(pAddr, aAddressStr, sizeof(aAddressStr));
|
||||
|
||||
if(pBan)
|
||||
{
|
||||
dbg_msg("banmaster", "updated ban: %d.%d.%d.%d \'%s\' -> \'%s\'",
|
||||
pAddr->ip[0], pAddr->ip[1], pAddr->ip[2], pAddr->ip[3], pBan->m_aReason, pReason);
|
||||
char aAddressStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(pAddr, aAddressStr, sizeof(aAddressStr));
|
||||
dbg_msg("banmaster", "updated ban, ip=%s oldreason='%s' reason='%s'", aAddressStr, pBan->m_aReason, pReason);
|
||||
|
||||
str_copy(pBan->m_aReason, pReason, sizeof(m_aBans[m_NumBans].m_aReason));
|
||||
pBan->m_Expire = -1;
|
||||
|
@ -97,8 +103,7 @@ void AddBan(NETADDR *pAddr, const char *pReason)
|
|||
str_copy(m_aBans[m_NumBans].m_aReason, pReason, sizeof(m_aBans[m_NumBans].m_aReason));
|
||||
m_aBans[m_NumBans].m_Expire = -1;
|
||||
|
||||
dbg_msg("banmaster", "added ban: %d.%d.%d.%d \'%s\'",
|
||||
pAddr->ip[0], pAddr->ip[1], pAddr->ip[2], pAddr->ip[3], m_aBans[m_NumBans].m_aReason);
|
||||
dbg_msg("banmaster", "added ban, ip=%s reason='%s'", aAddressStr, m_aBans[m_NumBans].m_aReason);
|
||||
|
||||
m_NumBans++;
|
||||
}
|
||||
|
@ -106,7 +111,6 @@ void AddBan(NETADDR *pAddr, const char *pReason)
|
|||
|
||||
void ClearBans()
|
||||
{
|
||||
dbg_msg("banmaster", "cleared bans");
|
||||
m_NumBans = 0;
|
||||
}
|
||||
|
||||
|
@ -119,10 +123,10 @@ void PurgeBans()
|
|||
if(m_aBans[i].m_Expire != -1 && m_aBans[i].m_Expire < Now)
|
||||
{
|
||||
// remove ban
|
||||
dbg_msg("banmaster", "expired: %d.%d.%d.%d \'%s\'",
|
||||
m_aBans[i].m_Address.ip[0], m_aBans[i].m_Address.ip[1],
|
||||
m_aBans[i].m_Address.ip[2], m_aBans[i].m_Address.ip[3], m_aBans[i].m_aReason);
|
||||
m_aBans[i] = m_aBans[m_NumBans-1];
|
||||
char aBuf[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&m_aBans[i].m_Address, aBuf, sizeof(aBuf));
|
||||
dbg_msg("banmaster", "ban expired, ip=%s reason='%s'", aBuf, m_aBans[i].m_aReason);
|
||||
m_aBans[i] = m_aBans[m_NumBans - 1];
|
||||
m_NumBans--;
|
||||
}
|
||||
else
|
||||
|
@ -130,7 +134,7 @@ void PurgeBans()
|
|||
}
|
||||
}
|
||||
|
||||
void ConBan(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
void ConBan(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
NETADDR Addr;
|
||||
const char *pStr = pResult->GetString(0);
|
||||
|
@ -142,15 +146,15 @@ void ConBan(IConsole::IResult *pResult, void *pUser, int ClientID)
|
|||
if(!net_addr_from_str(&Addr, pStr))
|
||||
AddBan(&Addr, pReason);
|
||||
else
|
||||
dbg_msg("banmaster", "invalid network address to ban");
|
||||
dbg_msg("banmaster", "invalid network address to ban, str='%s'", pStr);
|
||||
}
|
||||
|
||||
void ConUnbanAll(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
void ConUnbanAll(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
ClearBans();
|
||||
}
|
||||
|
||||
void ConSetBindAddr(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
void ConSetBindAddr(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
if(m_aBindAddr[0])
|
||||
return;
|
||||
|
@ -174,9 +178,9 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
|
||||
m_pConsole = CreateConsole(CFGFLAG_BANMASTER);
|
||||
m_pConsole->RegisterPrintCallback(StandardOutput, 0);
|
||||
m_pConsole->Register("ban", "s?r", CFGFLAG_BANMASTER, ConBan, 0, "Bans the specified ip", IConsole::CONSOLELEVEL_USER);
|
||||
m_pConsole->Register("unban_all", "", CFGFLAG_BANMASTER, ConUnbanAll, 0, "Unbans all ips", IConsole::CONSOLELEVEL_USER);
|
||||
m_pConsole->Register("bind", "s", CFGFLAG_BANMASTER, ConSetBindAddr, 0, "Binds to the specified address", IConsole::CONSOLELEVEL_USER);
|
||||
m_pConsole->Register("ban", "s?r", CFGFLAG_BANMASTER, ConBan, 0, "Bans the specified ip");
|
||||
m_pConsole->Register("unban_all", "", CFGFLAG_BANMASTER, ConUnbanAll, 0, "Unbans all ips");
|
||||
m_pConsole->Register("bind", "s", CFGFLAG_BANMASTER, ConSetBindAddr, 0, "Binds to the specified address");
|
||||
|
||||
{
|
||||
bool RegisterFail = false;
|
||||
|
@ -188,7 +192,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
return -1;
|
||||
}
|
||||
|
||||
m_pConsole->ExecuteFile(BANMASTER_BANFILE, -1, IConsole::CONSOLELEVEL_CONFIG, 0, 0);
|
||||
m_pConsole->ExecuteFile(BANMASTER_BANFILE);
|
||||
|
||||
NETADDR BindAddr;
|
||||
if(m_aBindAddr[0] && net_host_lookup(m_aBindAddr, &BindAddr, NETTYPE_IPV4) == 0)
|
||||
|
@ -212,34 +216,40 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
m_Net.Update();
|
||||
|
||||
// process m_aPackets
|
||||
CNetChunk p;
|
||||
while(m_Net.Recv(&p))
|
||||
CNetChunk Packet;
|
||||
while(m_Net.Recv(&Packet))
|
||||
{
|
||||
if(p.m_DataSize >= (int)sizeof(BANMASTER_IPCHECK) &&
|
||||
!mem_comp(p.m_pData, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK)))
|
||||
char aAddressStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Packet.m_Address, aAddressStr, sizeof(aAddressStr));
|
||||
|
||||
if(Packet.m_DataSize >= sizeof(BANMASTER_IPCHECK) && mem_comp(Packet.m_pData, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK)) == 0)
|
||||
{
|
||||
char *pAddr = (char*)p.m_pData + sizeof(BANMASTER_IPCHECK);
|
||||
char *pAddr = (char *)Packet.m_pData + sizeof(BANMASTER_IPCHECK);
|
||||
NETADDR CheckAddr;
|
||||
if(net_addr_from_str(&CheckAddr, pAddr))
|
||||
{
|
||||
dbg_msg("banmaster", "dropped weird message ip=%d.%d.%d.%d checkaddr='%s'",
|
||||
p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3], pAddr);
|
||||
dbg_msg("banmaster", "dropped weird message, ip=%s checkaddr='%s'", aAddressStr, pAddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
int Banned = SendResponse(&p.m_Address, &CheckAddr);
|
||||
dbg_msg("banmaster", "responded to checkmsg ip=%d.%d.%d.%d checkaddr=%d.%d.%d.%d result=%s",
|
||||
p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3],
|
||||
CheckAddr.ip[0], CheckAddr.ip[1], CheckAddr.ip[2], CheckAddr.ip[3], (Banned) ? "ban" : "ok");
|
||||
CheckAddr.port = 0;
|
||||
|
||||
int Banned = SendResponse(&Packet.m_Address, &CheckAddr);
|
||||
|
||||
char aBuf[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&CheckAddr, aBuf, sizeof(aBuf));
|
||||
dbg_msg("banmaster", "responded to checkmsg, ip=%s checkaddr=%s result=%s", aAddressStr, aBuf, (Banned) ? "ban" : "ok");
|
||||
}
|
||||
}
|
||||
else
|
||||
dbg_msg("banmaster", "dropped weird packet, ip=%s", aAddressStr, (char *)Packet.m_pData);
|
||||
}
|
||||
|
||||
if(time_get() - LastUpdate > time_freq() * BAN_REREAD_TIME)
|
||||
{
|
||||
ClearBans();
|
||||
LastUpdate = time_get();
|
||||
m_pConsole->ExecuteFile(BANMASTER_BANFILE, -1, IConsole::CONSOLELEVEL_CONFIG, 0, 0);
|
||||
m_pConsole->ExecuteFile(BANMASTER_BANFILE);
|
||||
}
|
||||
|
||||
// be nice to the CPU
|
||||
|
@ -248,3 +258,4 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
static const int BANMASTER_PORT = 8302;
|
||||
|
||||
static const char BANMASTER_IPOK[] = {255, 255, 255, 255, 'i', 'p', 'o', 'k'};
|
||||
//static const char BANMASTER_IPOK[] = {255, 255, 255, 255, 'i', 'p', 'o', 'k'};
|
||||
static const char BANMASTER_IPBAN[] = {255, 255, 255, 255, 'i', 'p', 'b', 'a'};
|
||||
static const char BANMASTER_IPCHECK[] = {255, 255, 255, 255, 'i', 'p', 'c', 'h'};
|
||||
|
||||
|
|
|
@ -23,6 +23,14 @@
|
|||
|
||||
#include <mastersrv/mastersrv.h>
|
||||
|
||||
// DDRace
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <engine/shared/linereader.h>
|
||||
|
||||
// banmaster
|
||||
#include <banmaster/banmaster.h>
|
||||
|
||||
#include "register.h"
|
||||
#include "server.h"
|
||||
|
||||
|
@ -32,11 +40,6 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <banmaster/banmaster.h>
|
||||
#include "../shared/linereader.h"
|
||||
#include <vector>
|
||||
|
||||
static const char SERVER_BANMASTERFILE[] = "banmasters.cfg";
|
||||
|
||||
static const char *StrLtrim(const char *pStr)
|
||||
|
@ -1064,35 +1067,37 @@ void CServer::PumpNetwork()
|
|||
SendServerInfo(&Packet.m_Address, ((unsigned char *)Packet.m_pData)[sizeof(SERVERBROWSE_GETINFO)]);
|
||||
}
|
||||
|
||||
// Ban Master
|
||||
|
||||
if(Packet.m_DataSize >= (int)sizeof(BANMASTER_IPOK) &&
|
||||
mem_comp(Packet.m_pData, BANMASTER_IPOK, sizeof(BANMASTER_IPOK)) == 0 &&
|
||||
m_NetServer.BanmasterCheck(&Packet.m_Address) != -1)
|
||||
/*if(Packet.m_DataSize >= sizeof(BANMASTER_IPOK) &&
|
||||
mem_comp(Packet.m_pData, BANMASTER_IPOK, sizeof(BANMASTER_IPOK)) == 0 &&
|
||||
m_NetServer.BanmasterCheck(&Packet.m_Address) != -1)
|
||||
{
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
if(Packet.m_DataSize >= (int)sizeof(BANMASTER_IPBAN) &&
|
||||
mem_comp(Packet.m_pData, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN)) == 0 &&
|
||||
g_Config.m_SvGlobalBantime && m_NetServer.BanmasterCheck(&Packet.m_Address) != -1)
|
||||
if(Packet.m_DataSize >= sizeof(BANMASTER_IPBAN) &&
|
||||
mem_comp(Packet.m_pData, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN)) == 0)
|
||||
{
|
||||
if(!g_Config.m_SvGlobalBantime)
|
||||
return;
|
||||
|
||||
if(m_NetServer.BanmasterCheck(&Packet.m_Address) == -1)
|
||||
return;
|
||||
|
||||
CUnpacker Up;
|
||||
char aIp[32];
|
||||
char aIp[NETADDR_MAXSTRSIZE];
|
||||
char aReason[256];
|
||||
NETADDR Addr;
|
||||
Up.Reset((unsigned char*)Packet.m_pData + sizeof(BANMASTER_IPBAN), Packet.m_DataSize - sizeof(BANMASTER_IPBAN));
|
||||
str_copy(aIp, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(aIp));
|
||||
str_copy(aReason, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(aReason));
|
||||
if (net_addr_from_str(&Addr, aIp))
|
||||
if(net_addr_from_str(&Addr, aIp))
|
||||
{
|
||||
dbg_msg("globalbans", "dropped weird message from banmaster");
|
||||
return;
|
||||
}
|
||||
m_NetServer.BanAdd(Addr, g_Config.m_SvGlobalBantime * 60, aReason);
|
||||
dbg_msg("globalbans", "added ban, ip=%d.%d.%d.%d, reason=\"%s\"", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], aReason);
|
||||
}
|
||||
|
||||
m_NetServer.BanAdd(Addr, g_Config.m_SvGlobalBantime * 60, aReason);
|
||||
dbg_msg("globalbans", "added ban, ip=%s, reason='%s'", aIp, aReason);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1209,6 +1214,7 @@ int CServer::Run()
|
|||
}
|
||||
|
||||
m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this);
|
||||
|
||||
Console()->ExecuteFile(SERVER_BANMASTERFILE, -1, IConsole::CONSOLELEVEL_CONFIG, 0, 0);
|
||||
|
||||
char aBuf[256];
|
||||
|
@ -1574,14 +1580,16 @@ void CServer::RegisterCommands()
|
|||
|
||||
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
|
||||
// banmaster
|
||||
Console()->Register("add_banmaster", "s", CFGFLAG_SERVER, ConAddBanmaster, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("banmasters", "", CFGFLAG_SERVER, ConBanmasters, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("clear_banmasters", "", CFGFLAG_SERVER, ConClearBanmasters, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
|
||||
Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
|
||||
Console()->Chain("password", ConchainSpecialInfoupdate, this);
|
||||
|
||||
Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this);
|
||||
|
||||
Console()->Register("add_banmaster", "s", CFGFLAG_SERVER, ConAddBanmaster, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("banmasters", "", CFGFLAG_SERVER, ConBanmasters, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("clear_banmasters", "", CFGFLAG_SERVER, ConClearBanmasters, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("login", "?s", CFGFLAG_SERVER, ConLogin, this, "Allows you access to rcon if no password is given, or changes your level if a password is given", IConsole::CONSOLELEVEL_USER);
|
||||
Console()->Register("auth", "?s", CFGFLAG_SERVER, ConLogin, this, "Allows you access to rcon if no password is given, or changes your level if a password is given", IConsole::CONSOLELEVEL_USER);
|
||||
Console()->Register("cmdlist", "?i", CFGFLAG_SERVER, ConCmdList, this, "Shows you the commands available for your remote console access. Specify the level if you want to see other level's commands", IConsole::CONSOLELEVEL_USER);
|
||||
|
@ -1860,44 +1868,6 @@ char *CServer::GetAnnouncementLine(char const *pFileName)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CServer::ConAddBanmaster(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
|
||||
int Result = pServer->m_NetServer.BanmasterAdd(pResult->GetString(0));
|
||||
|
||||
if(Result == 0)
|
||||
pResult->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "succesfully added banmaster");
|
||||
else if (Result == 1)
|
||||
pResult->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "invalid address for banmaster / net lookup failed");
|
||||
else
|
||||
pResult->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "too many banmasters");
|
||||
}
|
||||
|
||||
void CServer::ConBanmasters(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
int NumBanmasters = pServer->m_NetServer.BanmasterNum();
|
||||
|
||||
char aBuf[128];
|
||||
char aIpString[64];
|
||||
|
||||
for(int i = 0; i < NumBanmasters; i++)
|
||||
{
|
||||
NETADDR *pBanmaster = pServer->m_NetServer.BanmasterGet(i);
|
||||
net_addr_str(pBanmaster, aIpString, sizeof(aIpString));
|
||||
str_format(aBuf, sizeof(aBuf), "%d: %s", i, aIpString);
|
||||
pResult->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::ConClearBanmasters(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
|
||||
pServer->m_NetServer.BanmastersClear();
|
||||
}
|
||||
|
||||
void CServer::SendRconResponse(const char *pLine, void *pUser)
|
||||
{
|
||||
RconResponseInfo *pInfo = (RconResponseInfo *)pUser;
|
||||
|
@ -1969,3 +1939,48 @@ void CServer::GetClientIP(int ClientID, char *pIPString, int Size)
|
|||
str_format(pIPString, Size, "%d.%d.%d.%d", Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
NETADDR CServer::GetClientIP(int ClientID)//this may exist already but i couldn't find it cause i am tired :D
|
||||
{
|
||||
return m_NetServer.ClientAddr(ClientID);
|
||||
}
|
||||
|
||||
void CServer::ConAddBanmaster(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
|
||||
int Result = pServer->m_NetServer.BanmasterAdd(pResult->GetString(0));
|
||||
|
||||
if(Result == 0)
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "succesfully added banmaster");
|
||||
else if (Result == 1)
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "invalid address for banmaster / net lookup failed");
|
||||
else
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "too many banmasters");
|
||||
}
|
||||
|
||||
void CServer::ConBanmasters(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
int NumBanmasters = pServer->m_NetServer.BanmasterNum();
|
||||
|
||||
char aBuf[128];
|
||||
char aIpString[64];
|
||||
|
||||
for(int i = 0; i < NumBanmasters; i++)
|
||||
{
|
||||
NETADDR *pBanmaster = pServer->m_NetServer.BanmasterGet(i);
|
||||
net_addr_str(pBanmaster, aIpString, sizeof(aIpString));
|
||||
str_format(aBuf, sizeof(aBuf), "%d: %s", i, aIpString);
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::ConClearBanmasters(IConsole::IResult *pResult, void *pUser, int ClientID)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
|
||||
pServer->m_NetServer.BanmastersClear();
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "cleared banmaster list");
|
||||
}
|
||||
|
||||
|
|
|
@ -231,6 +231,7 @@ public:
|
|||
char *GetAnnouncementLine(char const *FileName);
|
||||
unsigned m_AnnouncementLastLine;
|
||||
void GetClientIP(int ClientID, char *pIPString, int Size);
|
||||
NETADDR GetClientIP(int ClientID);
|
||||
|
||||
static bool CompareClients(int ClientID, int Victim, void *pUser);
|
||||
static bool ClientOnline(int ClientID, void *pUser);
|
||||
|
|
|
@ -172,7 +172,6 @@ MACRO_CONFIG_INT(ClDemoName, cl_demo_name, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE,
|
|||
MACRO_CONFIG_INT(ClRaceGhost, cl_race_ghost, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Enable ghost", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(ClRaceShowGhost, cl_race_show_ghost, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ghost", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(ClRaceSaveGhost, cl_race_save_ghost, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Save ghost", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SvGlobalBantime, sv_global_ban_time, 60, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if the ban server reports it. 0 to disable", IConsole::CONSOLELEVEL_ADMIN)
|
||||
MACRO_CONFIG_INT(ClDDRaceScoreBoard, cl_ddrace_scoreboard, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Enable DDRace Scoreboard ", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SvResetPickus, sv_reset_pickups, 0, 0, 1, CFGFLAG_SERVER, "Whether the weapons are reset on passing the start tile or not", IConsole::CONSOLELEVEL_ADMIN)
|
||||
MACRO_CONFIG_INT(ClShowOthers, cl_show_others, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show players in other teams", IConsole::CONSOLELEVEL_USER)
|
||||
|
@ -188,4 +187,7 @@ MACRO_CONFIG_INT(SvChatPenalty, sv_chat_penalty, 250, 50, 1000, CFGFLAG_SERVER,
|
|||
MACRO_CONFIG_INT(SvChatThreshold, sv_chat_threshold, 1000, 50, 10000 , CFGFLAG_SERVER, "if chats core exceeds this, the player will be muted for sv_spam_mute_duration seconds", IConsole::CONSOLELEVEL_ADMIN)
|
||||
MACRO_CONFIG_INT(SvSpamMuteDuration, sv_spam_mute_duration, 60, 0, 3600 , CFGFLAG_SERVER, "how many seconds to mute, if player triggers mute on spam. 0 = off", IConsole::CONSOLELEVEL_ADMIN)
|
||||
|
||||
// banmaster
|
||||
MACRO_CONFIG_INT(SvGlobalBantime, sv_global_ban_time, 60, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if the ban server reports it. 0 to disable", IConsole::CONSOLELEVEL_ADMIN)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -292,7 +292,6 @@ public:
|
|||
|
||||
// Banmaster
|
||||
|
||||
|
||||
int BanmasterAdd(const char *pAddrStr);
|
||||
int BanmasterNum() const;
|
||||
NETADDR* BanmasterGet(int Index);
|
||||
|
@ -300,12 +299,12 @@ public:
|
|||
void BanmastersClear();
|
||||
enum
|
||||
{
|
||||
MAX_BANMASTERS=16,
|
||||
NETSERVER_DISABLEBANMASTER=1,
|
||||
MAX_BANMASTERS=16
|
||||
};
|
||||
int m_Flags;
|
||||
private:
|
||||
NETADDR m_aBanmasters[MAX_BANMASTERS];
|
||||
int m_NumBanmasters;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -355,23 +355,20 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
// client that wants to connect
|
||||
if(!Found)
|
||||
{
|
||||
if(!(m_Flags & NETSERVER_DISABLEBANMASTER))
|
||||
CNetChunk Packet;
|
||||
char aBuffer[sizeof(BANMASTER_IPCHECK) + NETADDR_MAXSTRSIZE];
|
||||
mem_copy(aBuffer, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK));
|
||||
net_addr_str(&Addr, aBuffer + sizeof(BANMASTER_IPCHECK), sizeof(aBuffer) - sizeof(BANMASTER_IPCHECK));
|
||||
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
Packet.m_DataSize = str_length(aBuffer) + 1;
|
||||
Packet.m_pData = aBuffer;
|
||||
|
||||
for(int i = 0; i < m_NumBanmasters; i++)
|
||||
{
|
||||
CNetChunk Packet;
|
||||
char aBuffer[64];
|
||||
mem_copy(aBuffer, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK));
|
||||
net_addr_str(&Addr, aBuffer + sizeof(BANMASTER_IPCHECK), sizeof(aBuffer) - sizeof(BANMASTER_IPCHECK));
|
||||
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
Packet.m_DataSize = str_length(aBuffer) + 1;
|
||||
Packet.m_pData = aBuffer;
|
||||
|
||||
for(int i = 0; i < m_NumBanmasters; i++)
|
||||
{
|
||||
Packet.m_Address = m_aBanmasters[i];
|
||||
Send(&Packet);
|
||||
}
|
||||
Packet.m_Address = m_aBanmasters[i];
|
||||
Send(&Packet);
|
||||
}
|
||||
|
||||
// only allow a specific number of players with the same ip
|
||||
|
@ -405,6 +402,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr);
|
||||
if(m_pfnNewClient)
|
||||
m_pfnNewClient(i, m_UserPtr);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -515,10 +513,8 @@ NETADDR* CNetServer::BanmasterGet(int Index)
|
|||
int CNetServer::BanmasterCheck(NETADDR *pAddr)
|
||||
{
|
||||
for(int i = 0; i < m_NumBanmasters; i++)
|
||||
{
|
||||
if(!net_addr_comp(&m_aBanmasters[i], pAddr))
|
||||
if(net_addr_comp(&m_aBanmasters[i], pAddr) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -527,3 +523,4 @@ void CNetServer::BanmastersClear()
|
|||
{
|
||||
m_NumBanmasters = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue