Merge pull request #437 from lioncash/netplay

Minor netplay server cleanup
This commit is contained in:
Ryan Houdek 2014-06-07 01:08:52 -05:00
commit b591184e4b
1 changed files with 8 additions and 16 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <vector>
#include "Core/NetPlayServer.h"
NetPlayServer::~NetPlayServer()
@ -112,15 +114,8 @@ void NetPlayServer::ThreadFunc()
}
// close listening socket and client sockets
{
std::map<sf::SocketTCP, Client>::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<u8> 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<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac, player.pid);