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.
This commit is contained in:
Kayne Ruse
2014-04-29 01:34:52 +10:00
parent 624369f147
commit 5031352fe3
2 changed files with 12 additions and 8 deletions
+12 -5
View File
@@ -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;