WIP
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "Network/Client.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
Client::Client(World* world, EventBroker* eventBroker)
|
||||
@@ -159,6 +159,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::AmmoPickup:
|
||||
parseAmmoPickup(packet);
|
||||
break;
|
||||
case MessageType::RemoveWorld:
|
||||
parseRemoveWorld(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -336,6 +339,12 @@ void Client::parseAmmoPickup(Packet & packet)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::parseRemoveWorld(Packet & packet)
|
||||
{
|
||||
removeWorld();
|
||||
|
||||
}
|
||||
|
||||
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
|
||||
{
|
||||
for (auto field : componentInfo.FieldsInOrder) {
|
||||
@@ -706,19 +715,6 @@ void Client::displayServerlist()
|
||||
}
|
||||
}
|
||||
|
||||
void Client::removeWorld()
|
||||
{
|
||||
std::vector<EntityID> childrenToBeDeleted;
|
||||
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
|
||||
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
|
||||
childrenToBeDeleted.push_back(it->second);
|
||||
}
|
||||
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
|
||||
m_World->DeleteEntity(childrenToBeDeleted[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Client::createMainMenu()
|
||||
{
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/StartMenu.xml");
|
||||
|
||||
@@ -92,3 +92,15 @@ void Network::popNetworkSegmentOfHeader(Packet & packet)
|
||||
packet.ReadPrimitive<int>();
|
||||
packet.ReadPrimitive<int>();
|
||||
}
|
||||
|
||||
void Network::removeWorld()
|
||||
{
|
||||
std::vector<EntityID> childrenToBeDeleted;
|
||||
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
|
||||
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
|
||||
childrenToBeDeleted.push_back(it->second);
|
||||
}
|
||||
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
|
||||
m_World->DeleteEntity(childrenToBeDeleted[i]);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EWin, &Server::OnWin);
|
||||
// BindWW
|
||||
if (port == 0) {
|
||||
port = config->Get<float>("Networking.Port", 27666);
|
||||
@@ -542,6 +543,18 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Server::OnWin(const Events::Win & e)
|
||||
{
|
||||
Packet removeMap(MessageType::RemoveWorld);
|
||||
reliableBroadcast(removeMap);
|
||||
removeWorld();
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/CP_Rocky2.xml");
|
||||
entityFile->MergeInto(m_World);
|
||||
Packet newWorld(MessageType::Snapshot);
|
||||
reliableBroadcast(newWorld);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::parseClientPing()
|
||||
{
|
||||
LOG_INFO("%i: Parsing ping", m_PacketID);
|
||||
|
||||
Reference in New Issue
Block a user