From 5031352fe319c765ec7103a49df4900cee6ff4f3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 29 Apr 2014 01:34:52 +1000 Subject: [PATCH] Fixed the bug (read more) The bug was being caused by a lack of a new player object being sent to some clients. Fixed this by adding in the sending code, and preventing the new entries being "registered" until the end of the HandleJoinRequest() method. Hopefully I can simply abstract away some of this code soon. --- server/server_connections.cpp | 17 ++++++++++++----- todo.txt | 3 --- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 35f54a9..2f35566 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -42,19 +42,17 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) { } void ServerApplication::HandleJoinRequest(SerialPacket packet) { - //register the new client + //create the new client ClientEntry newClient; newClient.address = packet.meta.srcAddress; - clientMap[ClientEntry::uidCounter] = newClient; //TODO: move this into the player management code - //register the new player + //create the new player PlayerEntry newPlayer; newPlayer.clientIndex = ClientEntry::uidCounter; newPlayer.player = packet.clientInfo.player; newPlayer.handle = packet.clientInfo.handle; newPlayer.avatar = packet.clientInfo.avatar; - playerMap[PlayerEntry::uidCounter] = newPlayer; //send the client their info packet.meta.type = SerialPacket::Type::JOIN_RESPONSE; @@ -66,9 +64,18 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { serialize(&packet, buffer); network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE); - //BUG: the new player object is not being sent to existing clients + //send the new player to all clients + packet.meta.type = SerialPacket::Type::PLAYER_NEW; + packet.playerInfo.playerIndex = PlayerEntry::uidCounter; + strncpy(packet.playerInfo.handle, newPlayer.handle.c_str(), PACKET_STRING_SIZE); + strncpy(packet.playerInfo.avatar, newPlayer.avatar.c_str(), PACKET_STRING_SIZE); + packet.playerInfo.position = newPlayer.position; + packet.playerInfo.motion = newPlayer.motion; + PumpPacket(packet); //finished this routine + clientMap[ClientEntry::uidCounter] = newClient; + playerMap[PlayerEntry::uidCounter] = newPlayer; ClientEntry::uidCounter++; PlayerEntry::uidCounter++; std::cout << "Connect, total: " << clientMap.size() << std::endl; diff --git a/todo.txt b/todo.txt index 0ad57c6..8f42fcd 100644 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,5 @@ Please note that due to modificatons, the indicated line may be incorrect. -## BUG -1. server_connections.cpp:68 the new player object is not being sent to existing clients - ## TODO server_application.hpp:74 a function that only sends to players in a certain proximity server_application.hpp:94 I need to handle multiple map objects