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