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/TCPClient.h"
|
||||||
#include "Network/SnapshotDefinitions.h"
|
#include "Network/SnapshotDefinitions.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include "Core/ConfigFile.h"
|
#include "Core/ConfigFile.h"
|
||||||
#include "Core/EPlayerDeath.h"
|
#include "Core/EPlayerDeath.h"
|
||||||
@@ -31,7 +32,6 @@
|
|||||||
#include "../Game/Events/EDashAbility.h"
|
#include "../Game/Events/EDashAbility.h"
|
||||||
#include "Network/EDisplayServerlist.h"
|
#include "Network/EDisplayServerlist.h"
|
||||||
#include "Network/EConnectRequest.h"
|
#include "Network/EConnectRequest.h"
|
||||||
|
|
||||||
class Client : public Network
|
class Client : public Network
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -109,6 +109,8 @@ private:
|
|||||||
void sendLocalPlayerTransform();
|
void sendLocalPlayerTransform();
|
||||||
void becomePlayer();
|
void becomePlayer();
|
||||||
void displayServerlist();
|
void displayServerlist();
|
||||||
|
void removeWorld();
|
||||||
|
void createMainMenu();
|
||||||
// Mapping Logic
|
// Mapping Logic
|
||||||
// Returns if local EntityID exist in map
|
// Returns if local EntityID exist in map
|
||||||
bool clientServerMapsHasEntity(EntityID clientEntityID);
|
bool clientServerMapsHasEntity(EntityID clientEntityID);
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ void Client::parseTCPConnect(Packet& packet)
|
|||||||
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
|
Packet UnreliablePacket(MessageType::Connect, m_SendPacketID);
|
||||||
// Add player id and other stuff
|
// Add player id and other stuff
|
||||||
packet.WritePrimitive(m_PlayerID);
|
packet.WritePrimitive(m_PlayerID);
|
||||||
// m_Unreliable.Send(packet);
|
// m_Unreliable.Send(packet);
|
||||||
// LOG_INFO("Sent UDP Connect Server");
|
// LOG_INFO("Sent UDP Connect Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::parsePlayerConnected(Packet & packet)
|
void Client::parsePlayerConnected(Packet & packet)
|
||||||
@@ -457,12 +457,14 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
|
|
||||||
void Client::disconnect()
|
void Client::disconnect()
|
||||||
{
|
{
|
||||||
|
removeWorld();
|
||||||
m_IsConnected = false;
|
m_IsConnected = false;
|
||||||
m_PreviousPacketID = 0;
|
m_PreviousPacketID = 0;
|
||||||
m_PacketID = 0;
|
m_PacketID = 0;
|
||||||
Packet packet(MessageType::Disconnect, m_SendPacketID);
|
Packet packet(MessageType::Disconnect, m_SendPacketID);
|
||||||
m_Reliable.Send(packet);
|
m_Reliable.Send(packet);
|
||||||
m_Reliable.Disconnect();
|
m_Reliable.Disconnect();
|
||||||
|
createMainMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
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)
|
bool Client::OnConnectRequest(const Events::ConnectRequest& e)
|
||||||
{
|
{
|
||||||
std::vector<EntityID> childrenToBeDeleted;
|
removeWorld();
|
||||||
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
|
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
||||||
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
|
// The client sent a successful connect message
|
||||||
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
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// The client could not send a successful connect message
|
// The client could not send a successful connect message
|
||||||
|
createMainMenu();
|
||||||
|
// Load the main menu again ?
|
||||||
return false;
|
return false;
|
||||||
// Load the main menu again ?
|
|
||||||
}
|
}
|
||||||
return false;
|
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)
|
bool Client::clientServerMapsHasEntity(EntityID clientEntityID)
|
||||||
{
|
{
|
||||||
if (m_ClientIDToServerID.find(clientEntityID) != m_ClientIDToServerID.end()) {
|
if (m_ClientIDToServerID.find(clientEntityID) != m_ClientIDToServerID.end()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user