2015-12-24 10:55:38 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Network : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Address
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Address() {};
|
|
|
|
Address(std::string addrString);
|
|
|
|
Address(Game::netadr_t addr) : address(addr) {}
|
|
|
|
Address(Game::netadr_t* addr) : Address(*addr) {}
|
|
|
|
Address(const Address& obj) { this->address = obj.address; };
|
|
|
|
bool operator!=(const Address &obj) { return !(*this == obj); };
|
|
|
|
bool operator==(const Address &obj);
|
|
|
|
|
|
|
|
void SetPort(unsigned short port);
|
|
|
|
unsigned short GetPort();
|
|
|
|
Game::netadr_t* Get();
|
|
|
|
const char* GetString();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
Game::netadr_t address;
|
|
|
|
};
|
|
|
|
|
2015-12-25 15:42:35 -05:00
|
|
|
typedef void(*Callback)(Address address, std::string data);
|
2015-12-24 10:55:38 -05:00
|
|
|
|
|
|
|
Network();
|
|
|
|
~Network();
|
|
|
|
const char* GetName() { return "Network"; };
|
|
|
|
|
|
|
|
static void Handle(std::string packet, Callback callback);
|
|
|
|
static void Send(Game::netsrc_t type, Address target, std::string data);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::string SelectedPacket;
|
|
|
|
static std::map<std::string, Callback> PacketHandlers;
|
|
|
|
static int PacketInterceptionHandler(const char* packet);
|
|
|
|
static void DeployPacket(Game::netadr_t from, Game::msg_t* msg);
|
|
|
|
static void DeployPacketStub();
|
|
|
|
};
|
|
|
|
}
|