#pragma once #include namespace network { using data_view = std::basic_string_view; using callback = std::function; void on(const std::string& command, const callback& callback); void send(const game::netadr_t& address, const std::string& command, const std::string& data = {}, char separator = ' '); void send_data(const game::netadr_t& address, const void* data, size_t length); void send_data(const game::netadr_t& address, const std::string& data); game::netadr_t address_from_string(const std::string& address); game::netadr_t address_from_ip(uint32_t ip, uint16_t port); bool are_addresses_equal(const game::netadr_t& a, const game::netadr_t& b); } inline bool operator==(const game::netadr_t& a, const game::netadr_t& b) { return network::are_addresses_equal(a, b); // } inline bool operator!=(const game::netadr_t& a, const game::netadr_t& b) { return !(a == b); // } namespace std { template <> struct equal_to { using result_type = bool; bool operator()(const game::netadr_t& lhs, const game::netadr_t& rhs) const { return network::are_addresses_equal(lhs, rhs); } }; template <> struct hash { size_t operator()(const game::netadr_t& x) const noexcept { const auto type_hash = hash()(x.type); if (x.type != game::NA_IP && x.type != game::NA_RAWIP) { return type_hash; } return type_hash ^ hash()(x.addr) ^ hash< uint16_t>()(x.port); } }; }