#pragma once #include "game/game.hpp" namespace network { using callback = std::function; void on(const std::string& command, const callback& callback); void send(const game::netadr_s& address, const std::string& command, const std::string& data = {}, char separator = ' '); void send_data(const game::netadr_s& address, const std::string& data); bool are_addresses_equal(const game::netadr_s& a, const game::netadr_s& b); const char* net_adr_to_string(const game::netadr_s& a); } inline bool operator==(const game::netadr_s& a, const game::netadr_s& b) { return network::are_addresses_equal(a, b); // } inline bool operator!=(const game::netadr_s& a, const game::netadr_s& b) { return !(a == b); // } namespace std { template <> struct equal_to { using result_type = bool; bool operator()(const game::netadr_s& lhs, const game::netadr_s& rhs) const { return network::are_addresses_equal(lhs, rhs); } }; template <> struct hash { size_t operator()(const game::netadr_s& x) const noexcept { return hash()(*reinterpret_cast(&x.ip[0])) ^ hash()(x.port); } }; }