EPlayerSpawned special logic added to server and client.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "Input/EInputCommand.h"
|
#include "Input/EInputCommand.h"
|
||||||
#include "Core/EPlayerDamage.h"
|
#include "Core/EPlayerDamage.h"
|
||||||
#include "Network/EInterpolate.h"
|
#include "Network/EInterpolate.h"
|
||||||
|
#include "Game/Events/EPlayerSpawned.h"
|
||||||
|
|
||||||
class Client : public Network
|
class Client : public Network
|
||||||
{
|
{
|
||||||
@@ -77,6 +78,7 @@ private:
|
|||||||
void parsePlayerConnected(Packet& packet);
|
void parsePlayerConnected(Packet& packet);
|
||||||
void parsePing();
|
void parsePing();
|
||||||
void parseKick();
|
void parseKick();
|
||||||
|
void parsePlayersSpawned(Packet& packet);
|
||||||
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||||
void parseSnapshot(Packet& packet);
|
void parseSnapshot(Packet& packet);
|
||||||
void identifyPacketLoss();
|
void identifyPacketLoss();
|
||||||
|
|||||||
@@ -5,16 +5,17 @@
|
|||||||
// Used to determine what type of message was sent.
|
// Used to determine what type of message was sent.
|
||||||
enum class MessageType
|
enum class MessageType
|
||||||
{
|
{
|
||||||
Connect,
|
Connect,
|
||||||
Disconnect,
|
Disconnect,
|
||||||
Ping,
|
Ping,
|
||||||
Message,
|
Message,
|
||||||
Snapshot,
|
Snapshot,
|
||||||
OnInputCommand,
|
OnInputCommand,
|
||||||
OnPlayerDamage,
|
OnPlayerDamage,
|
||||||
PlayerConnected,
|
PlayerConnected,
|
||||||
BecomePlayer,
|
BecomePlayer,
|
||||||
Kick
|
Kick,
|
||||||
|
OnPlayerSpawned
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include "Core/EPlayerDamage.h"
|
#include "Core/EPlayerDamage.h"
|
||||||
#include "Network/EPlayerDisconnected.h"
|
#include "Network/EPlayerDisconnected.h"
|
||||||
|
|
||||||
|
#include "Game/Events/EPlayerSpawned.h"
|
||||||
|
|
||||||
class Server : public Network
|
class Server : public Network
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -58,6 +60,7 @@ private:
|
|||||||
int receive(char* data);
|
int receive(char* data);
|
||||||
void readFromClients();
|
void readFromClients();
|
||||||
void send(Packet& packet, UserID user);
|
void send(Packet& packet, UserID user);
|
||||||
|
void send(Packet& packet, PlayerID player);
|
||||||
void send(Packet& packet);
|
void send(Packet& packet);
|
||||||
void broadcast(Packet& packet);
|
void broadcast(Packet& packet);
|
||||||
void sendSnapshot();
|
void sendSnapshot();
|
||||||
@@ -78,6 +81,8 @@ private:
|
|||||||
// Debug event
|
// Debug event
|
||||||
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
EventRelay<Server, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
|
bool OnPlayerSpawned(const Events::PlayerSpawned& e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ void Client::parseMessageType(Packet& packet)
|
|||||||
case MessageType::Kick:
|
case MessageType::Kick:
|
||||||
parseKick();
|
parseKick();
|
||||||
break;
|
break;
|
||||||
|
case MessageType::OnPlayerSpawned:
|
||||||
|
parsePlayersSpawned();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -129,6 +132,15 @@ void Client::parseKick()
|
|||||||
m_IsConnected = false;
|
m_IsConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::parsePlayersSpawned(Packet& packet)
|
||||||
|
{
|
||||||
|
Events::PlayerSpawned e;
|
||||||
|
e.Player = EntityWrapper(m_World, m_ServerIDToClientID[packet.ReadPrimitive<EntityID>()]);
|
||||||
|
e.Spawner = EntityWrapper(m_World, m_ServerIDToClientID[packet.ReadPrimitive<EntityID>()]);
|
||||||
|
e.PlayerID = -1;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
// Fields with strings will not work right now
|
// Fields with strings will not work right now
|
||||||
void Client::InterpolateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType)
|
void Client::InterpolateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,6 +132,20 @@ void Server::send(Packet& packet, UserID user)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::send(Packet& packet, PlayerID player)
|
||||||
|
{
|
||||||
|
int bytesSent = m_Socket.send_to(
|
||||||
|
boost::asio::buffer(packet.Data(), packet.Size()),
|
||||||
|
m_PlayerDefinitions[player].Endpoint,
|
||||||
|
0);
|
||||||
|
// Network Debug data
|
||||||
|
if (isReadingData) {
|
||||||
|
m_NetworkData.TotalDataSent += packet.Size();
|
||||||
|
m_NetworkData.DataSentThisInterval += packet.Size();
|
||||||
|
m_NetworkData.AmountOfMessagesSent++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Server::send(Packet & packet)
|
void Server::send(Packet & packet)
|
||||||
{
|
{
|
||||||
m_Socket.send_to(
|
m_Socket.send_to(
|
||||||
@@ -422,3 +436,12 @@ bool Server::OnInputCommand(const Events::InputCommand & e)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server::OnPlayerSpawned(const Events::PlayerSpawned & e)
|
||||||
|
{
|
||||||
|
Packet packet = Packet(MessageType::OnPlayerSpawned);
|
||||||
|
packet.WritePrimitive<EntityID>(e.Player.ID);
|
||||||
|
packet.WritePrimitive<EntityID>(e.Spawner.ID);
|
||||||
|
send(packet, e.PlayerID);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user