#pragma once #include "BoostAliases.h" #include "Compat.h" #include "TResourceManager.h" #include "TServer.h" #include #include struct TConnection; class TNetwork { public: TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager); [[nodiscard]] bool TCPSend(TClient& c, const std::vector& Data, bool IsSync = false); [[nodiscard]] bool SendLarge(TClient& c, std::vector Data, bool isSync = false); [[nodiscard]] bool Respond(TClient& c, const std::vector& MSG, bool Rel, bool isSync = false); std::shared_ptr CreateClient(ip::tcp::socket&& TCPSock); std::vector TCPRcv(TClient& c); void ClientKick(TClient& c, const std::string& R); [[nodiscard]] bool SyncClient(const std::weak_ptr& c); void Identify(TConnection&& client); std::shared_ptr Authentication(TConnection&& ClientConnection); void SyncResources(TClient& c); [[nodiscard]] bool UDPSend(TClient& Client, std::vector Data); void SendToAll(TClient* c, const std::vector& Data, bool Self, bool Rel); void UpdatePlayer(TClient& Client); private: void UDPServerMain(); void TCPServerMain(); TServer& mServer; TPPSMonitor& mPPSMonitor; ip::udp::socket mUDPSock; TResourceManager& mResourceManager; std::thread mUDPThread; std::thread mTCPThread; std::vector UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint); void HandleDownload(TConnection&& TCPSock); void OnConnect(const std::weak_ptr& c); void TCPClient(const std::weak_ptr& c); void Looper(const std::weak_ptr& c); int OpenID(); void OnDisconnect(const std::weak_ptr& ClientPtr); void Parse(TClient& c, const std::vector& Packet); void SendFile(TClient& c, const std::string& Name); static bool TCPSendRaw(TClient& C, ip::tcp::socket& socket, const uint8_t* Data, size_t Size); static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name); static const uint8_t* SendSplit(TClient& c, ip::tcp::socket& Socket, const uint8_t* DataPtr, size_t Size); }; std::string HashPassword(const std::string& str); std::vector StringToVector(const std::string& Str);