diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index c7145079bf..85041efb24 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include "Core/NetPlayServer.h" NetPlayServer::~NetPlayServer() @@ -112,15 +114,8 @@ void NetPlayServer::ThreadFunc() } // close listening socket and client sockets - { - std::map::reverse_iterator - i = m_players.rbegin(), - e = m_players.rend(); - for ( ; i!=e; ++i) - i->second.socket.Close(); - } - - return; + for (auto& player_entry : m_players) + player_entry.second.socket.Close(); } // called from ---NETPLAY--- thread @@ -424,15 +419,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket) PadMapping map = 0; u8 size; packet >> map >> size; - u8* data = new u8[size]; - for (unsigned int i = 0; i < size; ++i) + std::vector data(size); + for (size_t i = 0; i < data.size(); ++i) packet >> data[i]; // If the data is not from the correct player, // then disconnect them. if (m_wiimote_map[map] != player.pid) { - delete[] data; return 1; } @@ -441,10 +435,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket) spac << (MessageId)NP_MSG_WIIMOTE_DATA; spac << map; spac << size; - for (unsigned int i = 0; i < size; ++i) - spac << data[i]; - - delete[] data; + for (const u8& byte : data) + spac << byte; std::lock_guard lks(m_crit.send); SendToClients(spac, player.pid);