Skip to content

Commit

Permalink
Merge pull request dolphin-emu#2856 from mathieui/netplay-free
Browse files Browse the repository at this point in the history
[netplay] Fix a crash
  • Loading branch information
degasus committed Aug 15, 2015
2 parents cd1071c + 2420004 commit b8a35f6
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions Source/Core/Core/NetPlayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void NetPlayServer::ThreadFunc()
case ENET_EVENT_TYPE_DISCONNECT:
{
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
if (!netEvent.peer->data)
break;
auto it = m_players.find(*(PlayerId *)netEvent.peer->data);
if (it != m_players.end())
{
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down

0 comments on commit b8a35f6

Please sign in to comment.