diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-06-17 16:23:53 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-06-17 16:23:53 +0200 |
commit | 789f70b6f1a9067843dfc1ff73d86b645efe1da9 (patch) | |
tree | f3db085f2ac1ec5fd6ad0869a63e77a7f0fb1a17 /src/network/NetworkClient.hpp | |
parent | 2017-06-14 (diff) | |
download | AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.gz AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.bz2 AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.lz AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.xz AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.tar.zst AltCraft-789f70b6f1a9067843dfc1ff73d86b645efe1da9.zip |
Diffstat (limited to 'src/network/NetworkClient.hpp')
-rw-r--r-- | src/network/NetworkClient.hpp | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/src/network/NetworkClient.hpp b/src/network/NetworkClient.hpp index 14745a5..bf7aa4e 100644 --- a/src/network/NetworkClient.hpp +++ b/src/network/NetworkClient.hpp @@ -1,45 +1,25 @@ #pragma once -#include <queue> #include <thread> +#include <queue> #include <mutex> -#include <nlohmann/json.hpp> #include "Network.hpp" -#include "../packet/PacketParser.hpp" -#include "../packet/PacketBuilder.hpp" -struct ServerInfo{ - std::string version; - int protocol = 0; - int players_max = 0; - int players_online = 0; - std::vector<std::pair<std::string, std::string>> players; - std::string description; - double ping = 0; - std::string favicon; - std::string json; -}; class NetworkClient { + Network network; + std::thread networkThread; + std::mutex toSendMutex; + std::mutex toReceiveMutex; + std::queue <std::shared_ptr<Packet>> toSend; + std::queue <std::shared_ptr<Packet>> toReceive; + bool isActive=true; + bool &isRunning; + ConnectionState state; + void NetworkLoop(); public: - NetworkClient(std::string address, unsigned short port, std::string username); - ~NetworkClient(); - - void Update(); - - void MainLoop(); - - Packet * GetPacket(); - void AddPacketToQueue(Packet packet); - - static ServerInfo ServerPing(std::string address,unsigned short port); -private: - std::mutex m_updateMutex; - std::thread m_networkThread; - bool isContinue=true; - NetworkClient (const NetworkClient&); - NetworkClient&operator=(const NetworkClient&); - Network m_network; - std::queue <Packet> m_received; - std::queue <Packet> m_toSend; -}; + NetworkClient(std::string address, unsigned short port, std::string username, bool &quit); + ~NetworkClient(); + std::shared_ptr <Packet> ReceivePacket(); + void SendPacket(std::shared_ptr<Packet> packet); +};
\ No newline at end of file |