From 4481eabcc5b3ae5b4afef82a3e977c703d27e44c Mon Sep 17 00:00:00 2001 From: Ravomavain Date: Wed, 25 Apr 2012 21:07:32 +0200 Subject: [PATCH] remove banmaster from sources --- .gitignore | 1 - bam.lua | 7 +- banmasters.cfg | 3 - bans.cfg | 2 - scripts/make_release.py | 3 - src/banmaster/banmaster.cpp | 261 ------------------------------------ src/banmaster/banmaster.h | 12 -- 7 files changed, 1 insertion(+), 288 deletions(-) delete mode 100644 banmasters.cfg delete mode 100644 bans.cfg delete mode 100644 src/banmaster/banmaster.cpp delete mode 100644 src/banmaster/banmaster.h diff --git a/.gitignore b/.gitignore index 010140976..e56142b1e 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,5 @@ bam.exe *.cmd .settings *.opensdf -banmaster* DDRace* diff --git a/bam.lua b/bam.lua index edaec32af..1001493bd 100644 --- a/bam.lua +++ b/bam.lua @@ -261,7 +261,6 @@ function build(settings) versionserver = Compile(settings, Collect("src/versionsrv/*.cpp")) masterserver = Compile(settings, Collect("src/mastersrv/*.cpp")) - banmaster = Compile(settings, Collect("src/banmaster/*.cpp")) game_shared = Compile(settings, Collect("src/game/*.cpp"), nethash, network_source) game_client = Compile(settings, CollectRecursive("src/game/client/*.cpp"), client_content_source) game_server = Compile(settings, CollectRecursive("src/game/server/*.cpp"), server_content_source) @@ -302,9 +301,6 @@ function build(settings) masterserver_exe = Link(server_settings, "mastersrv", masterserver, engine, zlib) - banmaster_exe = Link(server_settings, "banmaster", banmaster, - engine, zlib) - -- make targets c = PseudoTarget("client".."_"..settings.config_name, client_exe, client_depends) if string.find(settings.config_name, "sql") then @@ -316,10 +312,9 @@ function build(settings) v = PseudoTarget("versionserver".."_"..settings.config_name, versionserver_exe) m = PseudoTarget("masterserver".."_"..settings.config_name, masterserver_exe) - b = PseudoTarget("banmaster".."_"..settings.config_name, banmaster_exe) t = PseudoTarget("tools".."_"..settings.config_name, tools) - all = PseudoTarget(settings.config_name, c, s, v, m, b, t) + all = PseudoTarget(settings.config_name, c, s, v, m, t) return all end diff --git a/banmasters.cfg b/banmasters.cfg deleted file mode 100644 index 30f3075ce..000000000 --- a/banmasters.cfg +++ /dev/null @@ -1,3 +0,0 @@ -clear_banmasters -add_banmaster banmaster.kottnet.net - diff --git a/bans.cfg b/bans.cfg deleted file mode 100644 index bc3e1d656..000000000 --- a/bans.cfg +++ /dev/null @@ -1,2 +0,0 @@ -unban_all -bind 127.0.0.1:8302 diff --git a/scripts/make_release.py b/scripts/make_release.py index acebe680d..c521fd3e3 100644 --- a/scripts/make_release.py +++ b/scripts/make_release.py @@ -115,9 +115,6 @@ shutil.copy("storage.cfg", package_dir) 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) diff --git a/src/banmaster/banmaster.cpp b/src/banmaster/banmaster.cpp deleted file mode 100644 index 3fac59697..000000000 --- a/src/banmaster/banmaster.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ -/* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include -#include -#include -#include - -#include "banmaster.h" - -enum -{ - MAX_BANS=1024, - BAN_REREAD_TIME=300, - CFGFLAG_BANMASTER=32 -}; - -static const char BANMASTER_BANFILE[] = "bans.cfg"; - -struct CBan -{ - NETADDR m_Address; - char m_aReason[256]; - int64 m_Expire; -}; - -static CBan m_aBans[MAX_BANS]; -static int m_NumBans = 0; -static CNetClient m_Net; -static IConsole *m_pConsole; -static char m_aBindAddr[64] = ""; - -CBan* CheckBan(NETADDR *pCheck) -{ - for(int i = 0; i < m_NumBans; i++) - 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) + NETADDR_MAXSTRSIZE + 256] = { 0 }; - static char *pIpBanContent = aIpBan + sizeof(BANMASTER_IPBAN); - if (!aIpBan[0]) - mem_copy(aIpBan, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN)); - - static CNetChunk p; - - p.m_ClientID = -1; - p.m_Address = *pAddr; - p.m_Flags = NETSENDFLAG_CONNLESS; - - CBan* pBan = CheckBan(pCheck); - if(pBan) - { - net_addr_str(pCheck, pIpBanContent, NETADDR_MAXSTRSIZE, false); - char *pIpBanReason = pIpBanContent + (str_length(pIpBanContent) + 1); - str_copy(pIpBanReason, pBan->m_aReason, 256); - - p.m_pData = aIpBan; - p.m_DataSize = sizeof(BANMASTER_IPBAN) + str_length(pIpBanContent) + 1 + str_length(pIpBanReason) + 1; - m_Net.Send(&p); - return 1; - } - - 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), false); - - if(pBan) - { - char aAddressStr[NETADDR_MAXSTRSIZE]; - net_addr_str(pAddr, aAddressStr, sizeof(aAddressStr), false); - 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; - } - else - { - if(m_NumBans == MAX_BANS) - { - dbg_msg("banmaster", "error: banmaster is full"); - return; - } - - m_aBans[m_NumBans].m_Address = *pAddr; - 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, ip=%s reason='%s'", aAddressStr, m_aBans[m_NumBans].m_aReason); - - m_NumBans++; - } -} - -void ClearBans() -{ - m_NumBans = 0; -} - -void PurgeBans() -{ - int64 Now = time_get(); - int i = 0; - while(i < m_NumBans) - { - if(m_aBans[i].m_Expire != -1 && m_aBans[i].m_Expire < Now) - { - // remove ban - char aBuf[NETADDR_MAXSTRSIZE]; - net_addr_str(&m_aBans[i].m_Address, aBuf, sizeof(aBuf), false); - 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 - i++; - } -} - -void ConBan(IConsole::IResult *pResult, void *pUser) -{ - NETADDR Addr; - const char *pStr = pResult->GetString(0); - const char *pReason = ""; - - if(pResult->NumArguments() > 1) - pReason = pResult->GetString(1); - - if(!net_addr_from_str(&Addr, pStr)) - AddBan(&Addr, pReason); - else - dbg_msg("banmaster", "invalid network address to ban, str='%s'", pStr); -} - -void ConUnbanAll(IConsole::IResult *pResult, void *pUser) -{ - ClearBans(); -} - -void ConSetBindAddr(IConsole::IResult *pResult, void *pUser) -{ - if(m_aBindAddr[0]) - return; - str_copy(m_aBindAddr, pResult->GetString(0), sizeof(m_aBindAddr)); - dbg_msg("banmaster/network", "bound to %s", m_aBindAddr); -} - -void StandardOutput(const char *pLine, void *pUser) -{ -} - -int main(int argc, const char **argv) // ignore_convention -{ - int64 LastUpdate = time_get(); - - dbg_logger_stdout(); - net_init(); - - IKernel *pKernel = IKernel::Create(); - IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention - - m_pConsole = CreateConsole(CFGFLAG_BANMASTER); - m_pConsole->RegisterPrintCallback(2, StandardOutput, 0); - 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; - - RegisterFail = RegisterFail || !pKernel->RegisterInterface(m_pConsole); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage); - - if(RegisterFail) - return -1; - } - - m_pConsole->ExecuteFile(BANMASTER_BANFILE); - - NETADDR BindAddr; - if(m_aBindAddr[0] && net_host_lookup(m_aBindAddr, &BindAddr, NETTYPE_IPV4) == 0) - { - if(BindAddr.port == 0) - BindAddr.port = BANMASTER_PORT; - } - else - { - mem_zero(&BindAddr, sizeof(BindAddr)); - BindAddr.port = BANMASTER_PORT; - } - - m_Net.Open(BindAddr, 0); - // TODO: check socket for errors - - dbg_msg("banmaster", "started"); - - while(1) - { - m_Net.Update(); - - // process m_aPackets - CNetChunk Packet; - while(m_Net.Recv(&Packet)) - { - char aAddressStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Packet.m_Address, aAddressStr, sizeof(aAddressStr), false); - - if((unsigned)Packet.m_DataSize >= sizeof(BANMASTER_IPCHECK) && mem_comp(Packet.m_pData, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK)) == 0) - { - 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=%s checkaddr='%s'", aAddressStr, pAddr); - } - else - { - CheckAddr.port = 0; - - int Banned = SendResponse(&Packet.m_Address, &CheckAddr); - - char aBuf[NETADDR_MAXSTRSIZE]; - net_addr_str(&CheckAddr, aBuf, sizeof(aBuf), false); - 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); - } - - // be nice to the CPU - thread_sleep(1); - } - - return 0; -} - diff --git a/src/banmaster/banmaster.h b/src/banmaster/banmaster.h deleted file mode 100644 index f7c645f77..000000000 --- a/src/banmaster/banmaster.h +++ /dev/null @@ -1,12 +0,0 @@ -/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ -/* If you are missing that file, acquire a complete release at teeworlds.com. */ -#ifndef BANMASTER_BANMASTER_H -#define BANMASTER_BANMASTER_H - -static const int BANMASTER_PORT = 8302; - -//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'}; - -#endif