prevent that the server uses close messages from clients. Closes #950

This commit is contained in:
oy 2012-04-20 21:39:49 +02:00
parent 635dc7cda1
commit ea876df455
4 changed files with 21 additions and 16 deletions

View file

@ -140,6 +140,7 @@ private:
int m_Token;
int m_RemoteClosed;
bool m_BlockCloseMsg;
TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> m_Buffer;
@ -167,7 +168,7 @@ private:
void Resend();
public:
void Init(NETSOCKET Socket);
void Init(NETSOCKET Socket, bool BlockCloseMsg);
int Connect(NETADDR *pAddr);
void Disconnect(const char *pReason);

View file

@ -16,7 +16,7 @@ bool CNetClient::Open(NETADDR BindAddr, int Flags)
// init
m_Socket = Socket;
m_Connection.Init(m_Socket);
m_Connection.Init(m_Socket, false);
return true;
}

View file

@ -37,12 +37,13 @@ void CNetConnection::SetError(const char *pString)
str_copy(m_ErrorString, pString, sizeof(m_ErrorString));
}
void CNetConnection::Init(NETSOCKET Socket)
void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg)
{
Reset();
ResetStats();
m_Socket = Socket;
m_BlockCloseMsg = BlockCloseMsg;
mem_zero(m_ErrorString, sizeof(m_ErrorString));
}
@ -213,21 +214,24 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
m_State = NET_CONNSTATE_ERROR;
m_RemoteClosed = 1;
if(pPacket->m_DataSize)
if(!m_BlockCloseMsg)
{
// make sure to sanitize the error string form the other party
char Str[128];
if(pPacket->m_DataSize < 128)
str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize);
else
str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str));
str_sanitize_strong(Str);
if(pPacket->m_DataSize)
{
// make sure to sanitize the error string form the other party
char Str[128];
if(pPacket->m_DataSize < 128)
str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize);
else
str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str));
str_sanitize_strong(Str);
// set the error string
SetError(Str);
// set the error string
SetError(Str);
}
else
SetError("No reason given");
}
else
SetError("No reason given");
if(g_Config.m_Debug)
dbg_msg("conn", "closed reason='%s'", ErrorString());

View file

@ -30,7 +30,7 @@ bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int Ma
m_MaxClientsPerIP = MaxClientsPerIP;
for(int i = 0; i < NET_MAX_CLIENTS; i++)
m_aSlots[i].m_Connection.Init(m_Socket);
m_aSlots[i].m_Connection.Init(m_Socket, true);
return true;
}