prevent self kick/ban in the console. Closes #50

and fixed line endings
This commit is contained in:
oy 2010-09-12 13:52:25 +02:00
parent 5437513a0d
commit 0c1261620f
2 changed files with 34 additions and 7 deletions

View file

@ -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;

View file

@ -106,6 +106,7 @@ public:
//int m_CurrentGameTick;
int m_RunServer;
int m_MapReload;
int m_RconClientId;
char m_aBrowseinfoGametype[16];
int m_BrowseinfoProgression;