From 5a57888305a2d8b351b3aa1c3c3d2da5864a1e33 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 11 Mar 2014 18:54:06 +1100 Subject: [PATCH] Fixed the crash bug --- server/server_application.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/server_application.cpp b/server/server_application.cpp index 7c2e3d2..56d1e4f 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -218,7 +218,7 @@ void ServerApplication::HandleDisconnect(NetworkPacket packet) { erase_if(playerMap, [&](std::pair it) -> bool { //find the internal players to delete - if (it.first == packet.clientInfo.index) { + if (it.second.clientIndex == packet.clientInfo.index) { delPacket.playerInfo.playerIndex = it.first; //send the delete player command to all clients PumpPacket(delPacket); @@ -246,7 +246,7 @@ void ServerApplication::HandleSynchronize(NetworkPacket packet) { newPacket.playerInfo.position = it.second.position; newPacket.playerInfo.motion = it.second.motion; serialize(&newPacket, buffer); - network.Send(&clientMap[it.second.clientIndex].address, buffer, sizeof(NetworkPacket)); + network.Send(&clientMap[packet.clientInfo.index].address, buffer, sizeof(NetworkPacket)); } } @@ -256,9 +256,7 @@ void ServerApplication::HandleShutdown(NetworkPacket packet) { //disconnect all clients packet.meta.type = NetworkPacket::Type::DISCONNECT; - for (auto& it : clientMap) { - network.Send(&it.second.address, &packet, sizeof(NetworkPacket)); - } + PumpPacket(packet); //finished this routine cout << "shutting down" << endl;