Added a player name to the PlayerSpawned event. When a player has spawned the server sends the name to the client which publishes the event.

This commit is contained in:
stiffly
2016-01-24 22:00:38 +01:00
parent 0c56a05144
commit 06f64f8fbf
3 changed files with 4 additions and 0 deletions
+1
View File
@@ -12,6 +12,7 @@ struct PlayerSpawned : Event
int PlayerID;
EntityWrapper Player;
EntityWrapper Spawner;
std::string PlayerName;
};
}
+1
View File
@@ -147,6 +147,7 @@ void Client::parsePlayersSpawned(Packet& packet)
e.Player = EntityWrapper(m_World, m_ServerIDToClientID[packet.ReadPrimitive<EntityID>()]);
e.Spawner = EntityWrapper(m_World, m_ServerIDToClientID[packet.ReadPrimitive<EntityID>()]);
e.PlayerID = -1;
e.PlayerName = packet.ReadString();
m_EventBroker->Publish(e);
}
+2
View File
@@ -405,6 +405,8 @@ bool Server::OnPlayerSpawned(const Events::PlayerSpawned & e)
Packet packet = Packet(MessageType::OnPlayerSpawned);
packet.WritePrimitive<EntityID>(e.Player.ID);
packet.WritePrimitive<EntityID>(e.Spawner.ID);
// We don't send PlayerID here because it will always be set to -1
packet.WriteString(m_ConnectedPlayers[e.PlayerID].Name);
send(e.PlayerID, packet);
return false;
}