From c9d70ed81bf952254ca69b82c82de00a5d187844 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 18 Aug 2014 23:50:24 +0200 Subject: [PATCH] Try to fix crash related to bad connection and reconnecting --- src/engine/shared/network_conn.cpp | 3 +-- src/engine/shared/network_server.cpp | 4 ++++ src/game/server/gamecontext.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index 74a37936e..d3e71caed 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -239,9 +239,8 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr) } else { - if(State() == NET_CONNSTATE_OFFLINE || State() == NET_CONNSTATE_ERROR) + if(State() == NET_CONNSTATE_OFFLINE) { - m_State = NET_CONNSTATE_OFFLINE; if(CtrlMsg == NET_CTRLMSG_CONNECT) { // send response and init connection diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index cd4968f09..5f0d5bb8c 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -140,6 +140,7 @@ int CNetServer::Recv(CNetChunk *pChunk) for(int i = 0; i < MaxClients(); i++) { if(m_aSlots[i].m_Connection.State() != NET_CONNSTATE_OFFLINE && + m_aSlots[i].m_Connection.State() != NET_CONNSTATE_ERROR && net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0) { Found = true; // silent ignore.. we got this client already @@ -205,6 +206,9 @@ int CNetServer::Recv(CNetChunk *pChunk) { if(net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0) { + if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE || + m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR) + continue; if(m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr)) { if(m_RecvUnpacker.m_Data.m_DataSize) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 7cd2e67fb..6b2568fff 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -844,16 +844,16 @@ void CGameContext::OnClientConnected(int ClientID) // Check which team the player should be on const int StartTeam = g_Config.m_SvTournamentMode ? TEAM_SPECTATORS : m_pController->GetAutoTeam(ClientID); - //if (!m_apPlayers[ClientID]) - m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); - //else - //{ - // //delete m_apPlayers[ClientID]; - // //m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); + if (!m_apPlayers[ClientID]) + m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); + else + { + delete m_apPlayers[ClientID]; + m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); // //m_apPlayers[ClientID]->Reset(); // //((CServer*)Server())->m_aClients[ClientID].Reset(); // ((CServer*)Server())->m_aClients[ClientID].m_State = 4; - //} + } //players[client_id].init(client_id); //players[client_id].client_id = client_id;