iw4x-client/src/Components/Modules/Session.hpp

57 lines
1.3 KiB
C++
Raw Normal View History

2018-10-09 04:53:15 -04:00
#pragma once
#define SESSION_TIMEOUT (10 * 1000) //10s
#define SESSION_MAX_RETRIES 3
#define SESSION_REQUEST_LIMIT 10
#define DISABLE_SESSION
namespace Components
{
class Session : public Component
{
public:
class Packet
{
public:
std::string command;
std::string data;
unsigned int tries;
std::optional<Utils::Time::Point> lastTry;
};
class Frame
{
public:
std::string challenge;
Utils::Time::Point creationPoint;
};
Session();
~Session();
bool unitTest() override;
void preDestroy() override;
2022-06-16 10:15:26 -04:00
static void Send(const Network::Address& target, const std::string& command, const std::string& data = "");
2022-05-20 18:12:46 -04:00
static void Handle(const std::string& packet, const Network::NetworkCallback& callback);
2018-10-09 04:53:15 -04:00
private:
static volatile bool Terminate;
2018-10-09 04:53:15 -04:00
static std::thread Thread;
static std::recursive_mutex Mutex;
static std::unordered_map<Network::Address, Frame> Sessions;
static std::unordered_map<Network::Address, std::queue<std::shared_ptr<Packet>>> PacketQueue;
static Utils::Cryptography::ECC::Key SignatureKey;
2022-05-20 18:12:46 -04:00
static std::unordered_map<std::string, Network::NetworkCallback> PacketHandlers;
2018-10-09 04:53:15 -04:00
static std::queue<std::pair<Network::Address, std::string>> SignatureQueue;
static void RunFrame();
static void HandleSignatures();
};
}