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

70 lines
2.0 KiB
C++
Raw Normal View History

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) {}
2016-01-24 15:08:14 -05:00
Address(const Address& obj) : address(obj.address) {};
2015-12-24 10:55:38 -05:00
bool operator!=(const Address &obj) { return !(*this == obj); };
bool operator==(const Address &obj);
void SetPort(unsigned short port);
unsigned short GetPort();
2015-12-27 22:02:30 -05:00
void SetIP(DWORD ip);
2016-01-03 18:00:07 -05:00
void SetIP(Game::netIP_t ip);
Game::netIP_t GetIP();
2015-12-27 22:02:30 -05:00
2016-01-03 13:28:47 -05:00
void SetType(Game::netadrtype_t type);
Game::netadrtype_t GetType();
2015-12-24 10:55:38 -05:00
Game::netadr_t* Get();
const char* GetString();
2016-01-03 18:00:07 -05:00
bool IsLocal();
bool IsSelf();
2015-12-24 10:55:38 -05:00
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);
2016-02-10 11:18:45 -05:00
// Send quake-styled binary data
2015-12-27 22:02:30 -05:00
static void Send(Address target, std::string data);
2015-12-24 10:55:38 -05:00
static void Send(Game::netsrc_t type, Address target, std::string data);
2016-02-10 11:18:45 -05:00
// Allows sending raw data without quake header
static void SendRaw(Address target, std::string data);
static void SendRaw(Game::netsrc_t type, Address target, std::string data);
2016-02-10 11:18:45 -05:00
// Send quake-style command using binary data
static void SendCommand(Address target, std::string command, std::string data = "");
static void SendCommand(Game::netsrc_t type, Address target, std::string command, std::string data = "");
2016-01-03 13:28:47 -05:00
static void Broadcast(unsigned short port, std::string data);
static void BroadcastRange(unsigned int min, unsigned int max, std::string data);
static void BroadcastAll(std::string data);
2015-12-24 10:55:38 -05:00
private:
2016-01-09 09:30:13 -05:00
static SOCKET TcpSocket;
2015-12-24 10:55:38 -05:00
static std::string SelectedPacket;
static std::map<std::string, Callback> PacketHandlers;
static int PacketInterceptionHandler(const char* packet);
2016-02-10 14:11:34 -05:00
static void DeployPacket(Game::netadr_t* from, Game::msg_t* msg);
2015-12-24 10:55:38 -05:00
static void DeployPacketStub();
};
}