From 2420004af8b3a1365782ef1b2ed9c8530220886b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 15 Aug 2015 15:10:58 +0200 Subject: [PATCH] [Netplay] Always set a playerid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And don’t blindly dereference a pointer. --- Source/Core/Core/NetPlayServer.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index bb110f250f..ada7b3d8f9 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -192,6 +192,8 @@ void NetPlayServer::ThreadFunc() case ENET_EVENT_TYPE_DISCONNECT: { std::lock_guard lkg(m_crit.game); + if (!netEvent.peer->data) + break; auto it = m_players.find(*(PlayerId *)netEvent.peer->data); if (it != m_players.end()) { @@ -232,6 +234,18 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket) } while (epack == nullptr); rpac.append(epack->data, epack->dataLength); + // give new client first available id + PlayerId pid = 1; + for (auto i = m_players.begin(); i != m_players.end(); ++i) + { + if (i->second.pid == pid) + { + pid++; + i = m_players.begin(); + } + } + socket->data = new PlayerId(pid); + std::string npver; rpac >> npver; // Dolphin netplay version @@ -250,25 +264,12 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket) m_update_pings = true; Client player; + player.pid = pid; player.socket = socket; rpac >> player.revision; rpac >> player.name; enet_packet_destroy(epack); - - // give new client first available id - PlayerId pid = 1; - for (auto i = m_players.begin(); i != m_players.end(); ++i) - { - if (i->second.pid == pid) - { - pid++; - i = m_players.begin(); - } - } - player.pid = pid; - socket->data = new PlayerId(pid); - // try to automatically assign new user a pad for (PadMapping& mapping : m_pad_map) {