When you disconnect you will delete the world and return to the menu.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "Network/TCPClient.h"
|
||||
#include "Network/SnapshotDefinitions.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Core/EPlayerDeath.h"
|
||||
@@ -31,7 +32,6 @@
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
#include "Network/EDisplayServerlist.h"
|
||||
#include "Network/EConnectRequest.h"
|
||||
|
||||
class Client : public Network
|
||||
{
|
||||
public:
|
||||
@@ -109,6 +109,8 @@ private:
|
||||
void sendLocalPlayerTransform();
|
||||
void becomePlayer();
|
||||
void displayServerlist();
|
||||
void removeWorld();
|
||||
void createMainMenu();
|
||||
// Mapping Logic
|
||||
// Returns if local EntityID exist in map
|
||||
bool clientServerMapsHasEntity(EntityID clientEntityID);
|
||||
|
||||
@@ -181,8 +181,8 @@ void Client::parseTCPConnect(Packet& packet)
|
||||
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
|
||||
// Add player id and other stuff
|
||||
packet.WritePrimitive(m_PlayerID);
|
||||
// m_Unreliable.Send(packet);
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
// m_Unreliable.Send(packet);
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
}
|
||||
|
||||
void Client::parsePlayerConnected(Packet & packet)
|
||||
@@ -457,12 +457,14 @@ void Client::parseSnapshot(Packet& packet)
|
||||
|
||||
void Client::disconnect()
|
||||
{
|
||||
removeWorld();
|
||||
m_IsConnected = false;
|
||||
m_PreviousPacketID = 0;
|
||||
m_PacketID = 0;
|
||||
Packet packet(MessageType::Disconnect, m_SendPacketID);
|
||||
m_Reliable.Send(packet);
|
||||
m_Reliable.Disconnect();
|
||||
createMainMenu();
|
||||
}
|
||||
|
||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||
@@ -549,22 +551,16 @@ bool Client::OnDashAbility(const Events::DashAbility& e)
|
||||
|
||||
bool Client::OnConnectRequest(const Events::ConnectRequest& e)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
||||
// The client send a successful connect message
|
||||
removeWorld();
|
||||
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
||||
// The client sent a successful connect message
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// The client could not send a successful connect message
|
||||
createMainMenu();
|
||||
// Load the main menu again ?
|
||||
return false;
|
||||
// Load the main menu again ?
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -695,6 +691,26 @@ 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/MainMenu.xml");
|
||||
entityFile->MergeInto(m_World);
|
||||
}
|
||||
|
||||
bool Client::clientServerMapsHasEntity(EntityID clientEntityID)
|
||||
{
|
||||
if (m_ClientIDToServerID.find(clientEntityID) != m_ClientIDToServerID.end()) {
|
||||
|
||||
Reference in New Issue
Block a user