about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2010-09-12 13:52:25 +0200
committeroy <Tom_Adams@web.de>2010-09-12 13:52:25 +0200
commit0c1261620f9554974239b57ce52ff9c39b087bf0 (patch)
tree3e8847f3b7feb5851087468c7cb55a881b86c80d /src/engine
parent5437513a0d0101fe45137f2ad6d7086a94766cfe (diff)
downloadzcatch-0c1261620f9554974239b57ce52ff9c39b087bf0.tar.gz
zcatch-0c1261620f9554974239b57ce52ff9c39b087bf0.zip
prevent self kick/ban in the console. Closes #50
and fixed line endings
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/server/server.cpp40
-rw-r--r--src/engine/server/server.h1
2 files changed, 34 insertions, 7 deletions
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 4859b499..40ad9e23 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -181,6 +181,8 @@ CServer::CServer() : m_DemoRecorder(&m_SnapshotDelta)
 	
 	m_MapReload = 0;
 
+	m_RconClientId = -1;
+
 	Init();
 }
 
@@ -259,9 +261,14 @@ void CServer::SetBrowseInfo(const char *pGameType, int Progression)
 void CServer::Kick(int ClientID, const char *pReason)
 {
 	if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State == CClient::STATE_EMPTY)
-	{

-		Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id to kick");

-		return;

+	{
+		Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id to kick");
+		return;
+	}
+	else if(m_RconClientId == ClientID)
+	{
+		Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't kick yourself");
+ 		return;
 	}
 		
 	m_NetServer.Drop(ClientID, pReason);
@@ -770,7 +777,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
 					char aBuf[256];
 					str_format(aBuf, sizeof(aBuf), "ClientId=%d rcon='%s'", ClientId, pCmd);
 					Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
+					m_RconClientId = ClientId;
 					Console()->ExecuteLine(pCmd);
+					m_RconClientId = -1;
 				}
 			}
 			else if(Msg == NETMSG_RCON_AUTH)
@@ -1228,7 +1237,19 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser)
 		Minutes = pResult->GetInteger(1);
 	
 	if(net_addr_from_str(&Addr, pStr) == 0)
+	{
+		if(pServer->m_RconClientId >= 0 && pServer->m_RconClientId < MAX_CLIENTS && pServer->m_aClients[pServer->m_RconClientId].m_State != CClient::STATE_EMPTY)
+		{
+			NETADDR AddrCheck = pServer->m_NetServer.ClientAddr(pServer->m_RconClientId);
+			Addr.port = AddrCheck.port = 0;
+			if(net_addr_comp(&Addr, &AddrCheck) == 0)
+			{
+				pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
+				return;
+			}
+		}
 		pServer->BanAdd(Addr, Minutes*60);
+	}
 	else if(StrAllnum(pStr))
 	{
 		int ClientId = str_toint(pStr);
@@ -1238,14 +1259,19 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser)
 			pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id");
 			return;
 		}
+		else if(pServer->m_RconClientId == ClientId)
+		{
+			pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
+			return;
+		}
 
 		Addr = pServer->m_NetServer.ClientAddr(ClientId);
 		pServer->BanAdd(Addr, Minutes*60);
 	}
-	else

-	{

-		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address to ban");

-		return;

+	else
+	{
+		pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address to ban");
+		return;
  	}
 	
 	Addr.port = 0;
diff --git a/src/engine/server/server.h b/src/engine/server/server.h
index 12333898..d5b872f0 100644
--- a/src/engine/server/server.h
+++ b/src/engine/server/server.h
@@ -106,6 +106,7 @@ public:
 	//int m_CurrentGameTick;
 	int m_RunServer;
 	int m_MapReload;
+	int m_RconClientId;
 
 	char m_aBrowseinfoGametype[16];
 	int m_BrowseinfoProgression;