Merge remote-tracking branch 'origin/master' into Dirtybit
# Conflicts: # src/Engine/Collision/CollisionSystem.cpp # src/Engine/Core/Transform.cpp # src/Engine/Editor/EditorSystem.cpp # src/Engine/Rendering/AnimationSystem.cpp # src/Engine/Rendering/BoneAttachmentSystem.cpp # src/Game/Systems/CapturePointSystem.cpp # src/Game/Systems/ExplosionEffectSystem.cpp # src/Game/Systems/PlayerMovementSystem.cpp
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Network/Client.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
Client::Client(World* world, EventBroker* eventBroker)
|
||||
@@ -35,6 +36,7 @@ void Client::Connect(std::string address, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &Client::OnDashAbility);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EConnectRequest, &Client::OnConnectRequest);
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_Address = address;
|
||||
if (address.empty()) {
|
||||
@@ -49,16 +51,19 @@ void Client::Connect(std::string address, int port)
|
||||
void Client::Update()
|
||||
{
|
||||
m_EventBroker->Process<Client>();
|
||||
//while (m_Unreliable.IsSocketAvailable()) {
|
||||
// // Packet will get real data in receive
|
||||
// Packet packet(MessageType::Invalid);
|
||||
// m_Unreliable.Receive(packet);
|
||||
// if (packet.GetMessageType() == MessageType::Connect) {
|
||||
// parseUDPConnect(packet);
|
||||
// } else {
|
||||
// parseMessageType(packet);
|
||||
// }
|
||||
//}
|
||||
while (m_Unreliable.IsSocketAvailable()) {
|
||||
m_Unreliable.ReceivePackets();
|
||||
}
|
||||
// Packet will get real data in GetNextPacket()
|
||||
Packet parsedPacket(MessageType::Invalid);
|
||||
while (m_Unreliable.GetNextPacket(parsedPacket)) {
|
||||
if (parsedPacket.GetMessageType() == MessageType::Connect) {
|
||||
parseUDPConnect(parsedPacket);
|
||||
} else {
|
||||
parseMessageType(parsedPacket);
|
||||
}
|
||||
}
|
||||
|
||||
while (m_Reliable.IsSocketAvailable()) {
|
||||
// Packet will get real data in receive
|
||||
Packet packet(MessageType::Invalid);
|
||||
@@ -82,7 +87,10 @@ void Client::Update()
|
||||
if (m_SearchingForServers) {
|
||||
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
|
||||
m_SearchingForServers = false;
|
||||
displayServerlist();
|
||||
//displayServerlist();
|
||||
Events::DisplayServerlist e;
|
||||
e.Serverlist = m_Serverlist;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +110,9 @@ void Client::Update()
|
||||
|
||||
void Client::parseMessageType(Packet& packet)
|
||||
{
|
||||
// Pop packetSize
|
||||
packet.ReadPrimitive<int>();
|
||||
// Pop packetSize, sequenceNumber and packetsInSequence.
|
||||
popNetworkSegmentOfHeader(packet);
|
||||
|
||||
int messageType = packet.ReadPrimitive<int>();
|
||||
if (messageType == -1)
|
||||
return;
|
||||
@@ -158,27 +167,30 @@ void Client::parseMessageType(Packet& packet)
|
||||
void Client::parseUDPConnect(Packet& packet)
|
||||
{
|
||||
// Map ServerEntityID and your PlayerID
|
||||
// TODO: If this is not received send a new connect message.
|
||||
LOG_INFO("I be connected PogChamp");
|
||||
}
|
||||
|
||||
void Client::parseTCPConnect(Packet& packet)
|
||||
{
|
||||
LOG_INFO("Received TCP connect from server");
|
||||
// Pop size of message int
|
||||
packet.ReadPrimitive<int>();
|
||||
// Pop packetSize, group, groupIndex and groupSize.
|
||||
popNetworkSegmentOfHeader(packet);
|
||||
|
||||
int messageType = packet.ReadPrimitive<int>();
|
||||
// Read packet ID
|
||||
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
||||
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
||||
// parse player id and other stuff
|
||||
m_PlayerID = packet.ReadPrimitive<int>();
|
||||
m_PlayerID = packet.ReadPrimitive<int>();
|
||||
LOG_INFO("A Player connected");
|
||||
// TODO: If this is not received send a new connect message.
|
||||
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)
|
||||
@@ -204,10 +216,11 @@ void Client::parsePing()
|
||||
|
||||
void Client::parseServerlist(Packet& packet)
|
||||
{
|
||||
// Pop size, message type, and ID
|
||||
packet.ReadPrimitive<int>();
|
||||
// Pop packetSize, group, groupIndex and groupSize.
|
||||
popNetworkSegmentOfHeader(packet);
|
||||
packet.ReadPrimitive<int>();
|
||||
packet.ReadPrimitive<int>();
|
||||
|
||||
std::string address = packet.ReadString();
|
||||
int port = packet.ReadPrimitive<int>();
|
||||
std::string serverName = packet.ReadString();
|
||||
@@ -220,7 +233,7 @@ void Client::parseServerlist(Packet& packet)
|
||||
void Client::parseKick()
|
||||
{
|
||||
LOG_WARNING("You have been kicked from the server.");
|
||||
m_IsConnected = false;
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void Client::parseSpawnEvents()
|
||||
@@ -453,22 +466,23 @@ 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_Unreliable.Disconnect();
|
||||
m_Reliable.Disconnect();
|
||||
Events::PlayerDisconnected e;
|
||||
e.Entity = m_LocalPlayer.ID;
|
||||
e.PlayerID = -1;
|
||||
m_EventBroker->Publish(e);
|
||||
createMainMenu();
|
||||
}
|
||||
|
||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||
{
|
||||
// TEMP
|
||||
if (e.Command == "SearchForServers" && e.Value > 0) {
|
||||
Events::SearchForServers e;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
if (e.PlayerID != -1) {
|
||||
return false;
|
||||
}
|
||||
@@ -476,7 +490,7 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||
if (e.Command == "ConnectToServer") { // Connect for now
|
||||
if (e.Value > 0) {
|
||||
m_Reliable.Connect(m_PlayerName, m_Address, m_Port);
|
||||
// m_Unreliable.Connect(m_PlayerName, m_Address, m_Port);
|
||||
m_Unreliable.Connect(m_PlayerName, m_Address, m_Port);
|
||||
}
|
||||
//LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||
return true;
|
||||
@@ -548,12 +562,29 @@ bool Client::OnDashAbility(const Events::DashAbility& e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Client::OnConnectRequest(const Events::ConnectRequest& e)
|
||||
{
|
||||
removeWorld();
|
||||
if (m_Reliable.Connect(m_PlayerName, e.IP, e.Port)) {
|
||||
m_Unreliable.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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
||||
{
|
||||
m_SearchingForServers = true;
|
||||
m_StartSearchTime = std::clock();
|
||||
m_Serverlist.clear();
|
||||
LOG_INFO("Searching for LAN servers...\n");
|
||||
Packet packet(MessageType::ServerlistRequest);
|
||||
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
|
||||
return true;
|
||||
@@ -613,7 +644,7 @@ void Client::sendLocalPlayerTransform()
|
||||
packet.WritePrimitive((int)cAssaultWeapon["Ammo"]);
|
||||
}
|
||||
|
||||
m_Reliable.Send(packet);
|
||||
m_Unreliable.Send(packet);
|
||||
}
|
||||
|
||||
void Client::identifyPacketLoss()
|
||||
@@ -675,6 +706,25 @@ 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");
|
||||
entityFile->MergeInto(m_World);
|
||||
}
|
||||
|
||||
bool Client::clientServerMapsHasEntity(EntityID clientEntityID)
|
||||
{
|
||||
if (m_ClientIDToServerID.find(clientEntityID) != m_ClientIDToServerID.end()) {
|
||||
|
||||
Reference in New Issue
Block a user