We are now sending EPlayerDamage events.
Client now listens to EPlayerDamage events and send them to Server. Server publishes EPlayerDamage events received from Client.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include "Core/ConfigFile.h"
|
#include "Core/ConfigFile.h"
|
||||||
#include "Input/EInputCommand.h"
|
#include "Input/EInputCommand.h"
|
||||||
|
#include "Core/EPlayerDamage.h"
|
||||||
|
|
||||||
class Client : public Network
|
class Client : public Network
|
||||||
{
|
{
|
||||||
@@ -79,11 +80,13 @@ private:
|
|||||||
bool isConnected();
|
bool isConnected();
|
||||||
EntityID createPlayer();
|
EntityID createPlayer();
|
||||||
bool hasMappedEntity(EntityID entityID);
|
bool hasMappedEntity(EntityID entityID);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
|
|
||||||
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
EventRelay<Client, Events::PlayerDamage> m_EPlayeDamage;
|
||||||
|
bool OnPlayerDamage(const Events::PlayerDamage& e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ enum class MessageType
|
|||||||
Message,
|
Message,
|
||||||
Snapshot,
|
Snapshot,
|
||||||
Event,
|
Event,
|
||||||
OnInputCommand
|
OnInputCommand,
|
||||||
|
OnPlayerDamage
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include "Network/Network.h"
|
#include "Network/Network.h"
|
||||||
#include "Input/EInputCommand.h"
|
#include "Input/EInputCommand.h"
|
||||||
|
#include "Core/EPlayerDamage.h"
|
||||||
|
|
||||||
class Server : public Network
|
class Server : public Network
|
||||||
{
|
{
|
||||||
@@ -69,6 +70,7 @@ private:
|
|||||||
void disconnect(int i);
|
void disconnect(int i);
|
||||||
void parseMessageType(Packet& packet);
|
void parseMessageType(Packet& packet);
|
||||||
void parseOnInputCommand(Packet& packet);
|
void parseOnInputCommand(Packet& packet);
|
||||||
|
void parseOnPlayerDamage(Packet& packet);
|
||||||
void parseConnect(Packet& packet);
|
void parseConnect(Packet& packet);
|
||||||
void parseDisconnect();
|
void parseDisconnect();
|
||||||
void parseClientPing();
|
void parseClientPing();
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
|
|||||||
{
|
{
|
||||||
if (e.Command == "ConnectToServer") { // Connect for now
|
if (e.Command == "ConnectToServer") { // Connect for now
|
||||||
connect();
|
connect();
|
||||||
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Packet packet(MessageType::OnInputCommand, m_SendPacketID);
|
Packet packet(MessageType::OnInputCommand, m_SendPacketID);
|
||||||
@@ -306,12 +306,22 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
|
|||||||
packet.WritePrimitive(e.PlayerID);
|
packet.WritePrimitive(e.PlayerID);
|
||||||
packet.WritePrimitive(e.Value);
|
packet.WritePrimitive(e.Value);
|
||||||
send(packet);
|
send(packet);
|
||||||
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
LOG_DEBUG("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Client::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||||
|
{
|
||||||
|
Packet packet(MessageType::OnInputCommand, m_SendPacketID);
|
||||||
|
packet.WritePrimitive(e.DamageAmount);
|
||||||
|
packet.WritePrimitive(e.PlayerDamagedID);
|
||||||
|
packet.WriteString(e.TypeOfDamage);
|
||||||
|
send(packet);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Client::identifyPacketLoss()
|
void Client::identifyPacketLoss()
|
||||||
{
|
{
|
||||||
// if no packets lost, difference should be equal to 1
|
// if no packets lost, difference should be equal to 1
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ void Server::parseMessageType(Packet& packet)
|
|||||||
break;
|
break;
|
||||||
case MessageType::OnInputCommand:
|
case MessageType::OnInputCommand:
|
||||||
parseOnInputCommand(packet);
|
parseOnInputCommand(packet);
|
||||||
break;;
|
break;
|
||||||
|
case MessageType::OnPlayerDamage:
|
||||||
|
parseOnPlayerDamage(packet);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -222,21 +225,22 @@ void Server::disconnect(int i)
|
|||||||
|
|
||||||
void Server::parseOnInputCommand(Packet& packet)
|
void Server::parseOnInputCommand(Packet& packet)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < MAXCONNECTIONS; i++) {
|
|
||||||
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If no player matches the address return.
|
|
||||||
if (i >= 8)
|
|
||||||
return;
|
|
||||||
Events::InputCommand e;
|
Events::InputCommand e;
|
||||||
e.Command = packet.ReadString();
|
e.Command = packet.ReadString();
|
||||||
e.PlayerID = packet.ReadPrimitive<int>();
|
e.PlayerID = packet.ReadPrimitive<int>();
|
||||||
e.Value = packet.ReadPrimitive<float>();
|
e.Value = packet.ReadPrimitive<float>();
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
LOG_DEBUG("Server::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::parseOnPlayerDamage(Packet & packet)
|
||||||
|
{
|
||||||
|
Events::PlayerDamage e;
|
||||||
|
e.DamageAmount = packet.ReadPrimitive<double>();
|
||||||
|
e.PlayerDamagedID = packet.ReadPrimitive<EntityID>();
|
||||||
|
e.TypeOfDamage = packet.ReadString();
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
LOG_DEBUG("Server::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.DamageAmount, e.PlayerDamagedID, e.TypeOfDamage.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::parseConnect(Packet& packet)
|
void Server::parseConnect(Packet& packet)
|
||||||
|
|||||||
Reference in New Issue
Block a user