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:
@@ -42,19 +42,17 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
||||||
//register the new client
|
//create the new client
|
||||||
ClientEntry newClient;
|
ClientEntry newClient;
|
||||||
newClient.address = packet.meta.srcAddress;
|
newClient.address = packet.meta.srcAddress;
|
||||||
clientMap[ClientEntry::uidCounter] = newClient;
|
|
||||||
|
|
||||||
//TODO: move this into the player management code
|
//TODO: move this into the player management code
|
||||||
//register the new player
|
//create the new player
|
||||||
PlayerEntry newPlayer;
|
PlayerEntry newPlayer;
|
||||||
newPlayer.clientIndex = ClientEntry::uidCounter;
|
newPlayer.clientIndex = ClientEntry::uidCounter;
|
||||||
newPlayer.player = packet.clientInfo.player;
|
newPlayer.player = packet.clientInfo.player;
|
||||||
newPlayer.handle = packet.clientInfo.handle;
|
newPlayer.handle = packet.clientInfo.handle;
|
||||||
newPlayer.avatar = packet.clientInfo.avatar;
|
newPlayer.avatar = packet.clientInfo.avatar;
|
||||||
playerMap[PlayerEntry::uidCounter] = newPlayer;
|
|
||||||
|
|
||||||
//send the client their info
|
//send the client their info
|
||||||
packet.meta.type = SerialPacket::Type::JOIN_RESPONSE;
|
packet.meta.type = SerialPacket::Type::JOIN_RESPONSE;
|
||||||
@@ -66,9 +64,18 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
|||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE);
|
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
|
//finished this routine
|
||||||
|
clientMap[ClientEntry::uidCounter] = newClient;
|
||||||
|
playerMap[PlayerEntry::uidCounter] = newPlayer;
|
||||||
ClientEntry::uidCounter++;
|
ClientEntry::uidCounter++;
|
||||||
PlayerEntry::uidCounter++;
|
PlayerEntry::uidCounter++;
|
||||||
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
Please note that due to modificatons, the indicated line may be incorrect.
|
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
|
## TODO
|
||||||
server_application.hpp:74 a function that only sends to players in a certain proximity
|
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
|
server_application.hpp:94 I need to handle multiple map objects
|
||||||
|
|||||||
Reference in New Issue
Block a user