about summary refs log tree commit diff
path: root/src/engine/server
diff options
context:
space:
mode:
authorTeetime <TeetimeTW@yahoo.de>2012-03-10 22:58:38 +0100
committerTeetime <TeetimeTW@yahoo.de>2012-03-10 22:58:38 +0100
commitb297f0995a8e097c60e67d6372128e65c22f908b (patch)
treee52e59632841995e94724a9c7ad123b78afdf640 /src/engine/server
parent66c44fc229bf8f2f029985a3d712c2518e4e38a9 (diff)
downloadzcatch-b297f0995a8e097c60e67d6372128e65c22f908b.tar.gz
zcatch-b297f0995a8e097c60e67d6372128e65c22f908b.zip
Extended banmaster, now its easier and more comfortable to ban"
Diffstat (limited to 'src/engine/server')
-rw-r--r--src/engine/server/server.cpp59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 2cb33f36..cd73c5a7 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -266,6 +266,45 @@ void CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
 	int Minutes = pResult->NumArguments()>1 ? clamp(pResult->GetInteger(1), 0, 44640) : 30;
 	const char *pReason = pResult->NumArguments()>2 ? pResult->GetString(2) : "No reason given";
 
+	int CID = -1;
+	if(StrAllnum(pStr))
+		CID = str_toint(pStr);
+	else
+	{
+		NETADDR Addr;
+		if(net_addr_from_str(&Addr, pStr) == 0)
+			for(int i = 0; i < MAX_CLIENTS; i++)
+				if(pThis->NetMatch(&Addr, pThis->Server()->m_NetServer.ClientAddr(i)))
+				{
+					CID = i;
+					break;
+				}
+	}
+
+	if(g_Config.m_SvGlobalBantime && CID >= 0 && CID < MAX_CLIENTS && pThis->Server()->m_aClients[CID].m_State == CServer::CClient::STATE_INGAME)
+	{
+		char aIP[NETADDR_MAXSTRSIZE];
+		net_addr_str(pThis->Server()->m_NetServer.ClientAddr(CID), aIP, sizeof(aIP), 0);
+
+		CPacker P;
+		P.Reset();
+		P.AddRaw(BANMASTER_IPREPORT, sizeof(BANMASTER_IPREPORT));
+		P.AddString(pThis->Server()->ClientName(CID), -1);
+		P.AddString(aIP, -1);
+		P.AddString(pReason, -1);
+
+		if(!P.Error())
+		{
+			CNetChunk Packet;
+			Packet.m_ClientID = -1;
+			Packet.m_Flags = NETSENDFLAG_CONNLESS;
+			Packet.m_pData = P.Data();
+			Packet.m_DataSize = P.Size();
+			pThis->Server()->m_NetServer.SendToBanmasters(&Packet);
+			pThis->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "banmaster", "Reported ban to banmasters");
+		}
+	}
+
 	if(StrAllnum(pStr))
 	{
 		int ClientID = str_toint(pStr);
@@ -1207,12 +1246,14 @@ void CServer::PumpNetwork()
 					str_copy(aReason, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(aReason));
 					if(net_addr_from_str(&Addr, aIp))
 					{
-						dbg_msg("globalbans", "dropped weird message from banmaster");
+						Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "globalbans", "dropped weird message from banmaster");
 						return;
 					}
 
 					m_ServerBan.BanAddr(&Addr, g_Config.m_SvGlobalBantime * 60, aReason);
-					dbg_msg("globalbans", "added ban, ip=%s, reason='%s'", aIp, aReason);
+					char aBuf[256];
+					str_format(aBuf, sizeof(aBuf), "added ban, ip=%s, reason='%s'", aIp, aReason);
+					Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "globalbans", aBuf);
 				}
 			}
 		}
@@ -1578,10 +1619,12 @@ void CServer::ConAddBanmaster(IConsole::IResult *pResult, void *pUser)
 	
 	if(Result == 0)
 		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "succesfully added banmaster");
-	else if (Result == 1)
+	else if(Result == 1)
 		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "invalid address for banmaster / net lookup failed");
-	else
+	else if(Result == 2)
 		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "too many banmasters");
+	else
+		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server/banmaster", "banmaster already exists");
 }
 
 void CServer::ConBanmasters(IConsole::IResult *pResult, void *pUser)
@@ -1789,6 +1832,14 @@ int main(int argc, const char **argv) // ignore_convention
 	pServer->RegisterCommands();
 	pGameServer->OnConsoleInit();
 
+	/* This banmaster is added into the source of the server that i'm able to ban players even if no banmaster.cfg is used.
+	 * Often serverhoster doesn't add this file because they don't know what it is for and remove it, not
+	 * because they don't want it. If so, set sv_global_bantime to 0 or use a custom banmasters.cfg with "clear_banmasters"
+	 * in first line or in normal config.
+	 * ## For a Teeworlds without bots \o/ ##
+	 */
+	pConsole->ExecuteLine("add_banmaster banmaster.teetw.de");
+
 	// execute autoexec file
 	pConsole->ExecuteFile("autoexec.cfg");