Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #437 from lioncash/netplay
Minor netplay server cleanup
  • Loading branch information
Sonicadvance1 committed Jun 7, 2014
2 parents b7519fd + 7babc63 commit b591184
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions Source/Core/Core/NetPlayServer.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <vector>

#include "Core/NetPlayServer.h"

NetPlayServer::~NetPlayServer()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down

0 comments on commit b591184

Please sign in to comment.