diff --git a/Flakkari/Server/Client/Client.cpp b/Flakkari/Server/Client/Client.cpp index 00d0b958..af05631a 100644 --- a/Flakkari/Server/Client/Client.cpp +++ b/Flakkari/Server/Client/Client.cpp @@ -19,6 +19,7 @@ Client::Client(std::shared_ptr address) Client::~Client() { _isConnected = false; + _address->setId(-1); } bool Client::isConnected(float timeout) @@ -32,4 +33,16 @@ void Client::keepAlive() { _lastActivity = std::chrono::steady_clock::now(); } +void Client::addPacketToHistory(Network::Buffer packet) +{ + if (_packetHistory.size() >= _maxPacketHistory) + _packetHistory.erase(_packetHistory.begin()); + _packetHistory.push_back(packet); +} + +bool Client::incrementWarningCount() { + _warningCount++; + return _warningCount >= _maxWarningCount; +} + } /* namespace Flakkari */ diff --git a/Flakkari/Server/Client/Client.hpp b/Flakkari/Server/Client/Client.hpp index 79a3321f..da7c39bf 100644 --- a/Flakkari/Server/Client/Client.hpp +++ b/Flakkari/Server/Client/Client.hpp @@ -15,11 +15,14 @@ #ifndef CLIENT_HPP_ -#define CLIENT_HPP_ + #define CLIENT_HPP_ #include -#include "Network/Address.hpp" +#include "Network/Socket.hpp" +#include "Network/PacketQueue.hpp" +#include "Protocol/Packet.hpp" +#include "Engine/EntityComponentSystem/Entity.hpp" #include "../Game/GameManager.hpp" namespace Flakkari { @@ -61,6 +64,21 @@ class Client { */ void keepAlive(); + /** + * @brief Add a packet to the client's packet history + * + * @param packet The packet to add + */ + void addPacketToHistory(Network::Buffer packet); + + /** + * @brief Increment the warning count of the client + * + * @return true If the client has been disconnected + * @return false If the client has not been disconnected + */ + bool incrementWarningCount(); + /** * @brief Get the client's address * @@ -68,13 +86,39 @@ class Client { */ [[nodiscard]] std::shared_ptr getAddress() const { return _address; } - [[nodiscard]] unsigned int getId() const { return _address->getId(); } + /** + * @brief Get the Entity object + * + * @return Entity The entity of the client + */ + [[nodiscard]] Engine::ECS::Entity getEntity() const { return _entity; } + void setEntity(Engine::ECS::Entity entity) { _entity = entity; } + + [[nodiscard]] short getId() const { return _address->getId(); } + + [[nodiscard]] std::string getSceneName() const { return _sceneName; } + void setSceneName(std::string sceneName) { _sceneName = sceneName; } + + [[nodiscard]] unsigned short getWarningCount() const { return _warningCount; } + + [[nodiscard]] unsigned short getMaxWarningCount() const { return _maxWarningCount; } + + [[nodiscard]] unsigned short getMaxPacketHistory() const { return _maxPacketHistory; } protected: private: std::chrono::steady_clock::time_point _lastActivity; std::shared_ptr _address; + Engine::ECS::Entity _entity; + std::string _sceneName; bool _isConnected = true; + unsigned short _warningCount = 0; + unsigned short _maxWarningCount = 5; + unsigned short _maxPacketHistory = 10; + public: + std::vector _packetHistory; + Network::PacketQueue> _sendQueue; + Network::PacketQueue> _receiveQueue; }; } /* namespace Flakkari */