diff --git a/sources.cmake b/sources.cmake index d4f28ae4d..ba4868d71 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,5 +1,5 @@ # Modify this file to change the last-modified date when you add/remove a file. -# This will then trigger a new cmake run automatically. +# This will then trigger a new cmake run automatically. file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") diff --git a/src/items/item_event_info.cpp b/src/items/item_event_info.cpp index 761574cf5..5ed7b7c36 100644 --- a/src/items/item_event_info.cpp +++ b/src/items/item_event_info.cpp @@ -19,6 +19,7 @@ #include "items/item_event_info.hpp" #include "network/network_config.hpp" +#include "network/network_string.hpp" #include "network/protocols/game_protocol.hpp" #include "network/rewind_manager.hpp" #include "network/stk_host.hpp" diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index 35f2609b7..585f37aa1 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -21,6 +21,7 @@ #include "karts/abstract_kart.hpp" #include "modes/world.hpp" #include "network/network_config.hpp" +#include "network/network_string.hpp" #include "network/protocols/game_protocol.hpp" #include "network/rewind_manager.hpp" #include "network/stk_host.hpp" diff --git a/src/main.cpp b/src/main.cpp index 0d66da6d0..ad90b032b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,6 +220,7 @@ #include "network/protocols/connect_to_server.hpp" #include "network/protocols/client_lobby.hpp" #include "network/protocols/server_lobby.hpp" +#include "network/network.hpp" #include "network/network_config.hpp" #include "network/network_string.hpp" #include "network/rewind_manager.hpp" diff --git a/src/network/network.cpp b/src/network/network.cpp index 18577aa7a..402aa9141 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -25,7 +25,6 @@ #include "network/network_string.hpp" #include "network/socket_address.hpp" #include "network/stk_ipv6.hpp" -#include "network/transport_address.hpp" #include "utils/file_utils.hpp" #include "utils/log.hpp" #include "utils/time.hpp" @@ -122,87 +121,6 @@ ENetPeer* Network::connectTo(const ENetAddress &address) return enet_host_connect(m_host, &address, EVENT_CHANNEL_COUNT, 0); } // connectTo -// ---------------------------------------------------------------------------- -/** \brief Sends a packet whithout ENet adding its headers. - * This function is used in particular to achieve the STUN protocol. - * \param data : Data to send. - * \param dst : Destination of the packet. - */ -void Network::sendRawPacket(const BareNetworkString &buffer, - const TransportAddress& dst) -{ - struct sockaddr_in to; - int to_len = sizeof(to); - memset(&to,0,to_len); - - to.sin_family = AF_INET; - to.sin_port = htons(dst.getPort()); - to.sin_addr.s_addr = htonl(dst.getIP()); - - sendto(m_host->socket, buffer.getData(), buffer.size(), 0, - (sockaddr*)&to, to_len); - if (m_connection_debug) - { - Log::verbose("Network", "Raw packet sent to %s", - dst.toString().c_str()); - } - Network::logPacket(buffer, false); -} // sendRawPacket - -// ---------------------------------------------------------------------------- -/** \brief Receives a packet directly from the network interface and - * filter its address. - * Receive a packet whithout ENet processing it. Checks that the - * sender of the packet is the one that corresponds to the sender - * parameter. Does not check the port right now. - * \param buffer A buffer to receive the data in. - * \param buf_len Length of the buffer. - * \param[out] sender : Transport address of the original sender of the - * wanted packet. If the ip address is 0, do not check - * the sender's ip address, otherwise wait till a message - * from the specified sender arrives. All other messages - * are discarded. - * \param max_tries : Number of times we try to read data from the - * socket. This is aproximately the time we wait in - * milliseconds. -1 means eternal tries. - * \return Length of the received data, or -1 if no data was received. - */ -int Network::receiveRawPacket(char *buffer, int buf_len, - TransportAddress *sender, int max_tries) -{ - memset(buffer, 0, buf_len); - - struct sockaddr_in addr; - socklen_t from_len = sizeof(addr); - - int len = recvfrom(m_host->socket, buffer, buf_len, 0, - (struct sockaddr*)(&addr), &from_len ); - - int count = 0; - // wait to receive the message because enet sockets are non-blocking - while(len < 0 && (countsocket, buffer, buf_len, 0, - (struct sockaddr*)(&addr), &from_len); - } - - // No message received - if(len<0) - return -1; - - Network::logPacket(BareNetworkString(buffer, len), true); - sender->setIP(ntohl((uint32_t)(addr.sin_addr.s_addr)) ); - sender->setPort( ntohs(addr.sin_port) ); - if (addr.sin_family == AF_INET && m_connection_debug) - { - Log::verbose("Network", "IPv4 Address of the sender was %s", - sender->toString().c_str()); - } - return len; -} // receiveRawPacket - // ---------------------------------------------------------------------------- /** \brief Sends a packet whithout ENet adding its headers. * This function is used in particular to achieve the STUN protocol. diff --git a/src/network/network.hpp b/src/network/network.hpp index 8ec2facaa..daf6aa650 100644 --- a/src/network/network.hpp +++ b/src/network/network.hpp @@ -36,7 +36,6 @@ class BareNetworkString; class NetworkString; -class TransportAddress; class SocketAddress; /** \class EnetHost @@ -67,10 +66,6 @@ public: static void logPacket(const BareNetworkString &ns, bool incoming); static void closeLog(); ENetPeer *connectTo(const ENetAddress &address); - void sendRawPacket(const BareNetworkString &buffer, - const TransportAddress& dst); - int receiveRawPacket(char *buffer, int buf_len, - TransportAddress* sender, int max_tries = -1); void sendRawPacket(const BareNetworkString &buffer, const SocketAddress& dst); int receiveRawPacket(char *buffer, int buf_len, diff --git a/src/network/network_config.cpp b/src/network/network_config.cpp index 9331c3635..7eb3c5fee 100644 --- a/src/network/network_config.cpp +++ b/src/network/network_config.cpp @@ -22,6 +22,7 @@ #include "input/device_manager.hpp" #include "modes/world.hpp" #include "network/network.hpp" +#include "network/network_string.hpp" #include "network/rewind_manager.hpp" #include "network/server_config.hpp" #include "network/socket_address.hpp" diff --git a/src/network/protocols/connect_to_peer.cpp b/src/network/protocols/connect_to_peer.cpp index 699c02c5b..a95070dfe 100644 --- a/src/network/protocols/connect_to_peer.cpp +++ b/src/network/protocols/connect_to_peer.cpp @@ -18,6 +18,7 @@ #include "network/protocols/connect_to_peer.hpp" #include "network/network.hpp" +#include "network/network_string.hpp" #include "network/stk_host.hpp" #include "utils/time.hpp" #include "utils/log.hpp" diff --git a/src/network/protocols/game_protocol.cpp b/src/network/protocols/game_protocol.cpp index de63a298f..7dacf6b17 100644 --- a/src/network/protocols/game_protocol.cpp +++ b/src/network/protocols/game_protocol.cpp @@ -25,6 +25,7 @@ #include "network/event.hpp" #include "network/network_config.hpp" #include "network/game_setup.hpp" +#include "network/network.hpp" #include "network/network_config.hpp" #include "network/network_string.hpp" #include "network/protocol_manager.hpp" diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 65d055b65..6b6572599 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -23,6 +23,7 @@ #include "io/file_manager.hpp" #include "network/event.hpp" #include "network/game_setup.hpp" +#include "network/network.hpp" #include "network/network_config.hpp" #include "network/network_console.hpp" #include "network/network_player_profile.hpp" @@ -34,7 +35,6 @@ #include "network/server_config.hpp" #include "network/stk_ipv6.hpp" #include "network/stk_peer.hpp" -#include "network/transport_address.hpp" #include "utils/log.hpp" #include "utils/separate_process.hpp" #include "utils/string_utils.hpp" diff --git a/src/network/stk_host.hpp b/src/network/stk_host.hpp index fc9c8c70d..c216197f5 100644 --- a/src/network/stk_host.hpp +++ b/src/network/stk_host.hpp @@ -22,8 +22,6 @@ #ifndef STK_HOST_HPP #define STK_HOST_HPP -#include "network/network.hpp" -#include "network/network_string.hpp" #include "utils/synchronised.hpp" #include "utils/time.hpp" @@ -45,15 +43,22 @@ #include #include #include +#include +class BareNetworkString; class GameSetup; class LobbyProtocol; +class Network; class NetworkPlayerProfile; +class NetworkString; class NetworkTimerSynchronizer; class Server; class ServerLobby; class SeparateProcess; class SocketAddress; +class STKPeer; + +using namespace irr; enum ENetCommandType : unsigned int { @@ -294,19 +299,6 @@ public: * requested. */ bool requestedShutdown() const { return m_shutdown.load(); } // ------------------------------------------------------------------------ - int receiveRawPacket(char *buffer, int buffer_len, - TransportAddress* sender, int max_tries = -1) - { - return m_network->receiveRawPacket(buffer, buffer_len, sender, - max_tries); - } // receiveRawPacket - // ------------------------------------------------------------------------ - void sendRawPacket(const BareNetworkString &buffer, - const TransportAddress& dst) - { - m_network->sendRawPacket(buffer, dst); - } // sendRawPacket - // ------------------------------------------------------------------------ int receiveRawPacket(char *buffer, int buffer_len, SocketAddress* sender, int max_tries = -1); // ------------------------------------------------------------------------ diff --git a/src/network/stk_peer.cpp b/src/network/stk_peer.cpp index 4d85ffd0b..2cff0d99f 100644 --- a/src/network/stk_peer.cpp +++ b/src/network/stk_peer.cpp @@ -21,12 +21,12 @@ #include "config/user_config.hpp" #include "network/crypto.hpp" #include "network/event.hpp" +#include "network/network.hpp" #include "network/network_config.hpp" #include "network/network_string.hpp" #include "network/socket_address.hpp" #include "network/stk_ipv6.hpp" #include "network/stk_host.hpp" -#include "network/transport_address.hpp" #include "utils/log.hpp" #include "utils/string_utils.hpp" #include "utils/time.hpp" diff --git a/src/network/transport_address.cpp b/src/network/transport_address.cpp deleted file mode 100644 index c8abd78be..000000000 --- a/src/network/transport_address.cpp +++ /dev/null @@ -1,323 +0,0 @@ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013-2015 Joerg Henrichs -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include "network/transport_address.hpp" -#include "network/stk_ipv6.hpp" -#include "utils/log.hpp" -#include "utils/string_utils.hpp" - -#ifdef WIN32 -# include -#else -# include -# include -# include -# include -#endif - -#if defined(WIN32) -# include "ws2tcpip.h" -# define inet_ntop InetNtop -#else -# include -# include -# include -#endif - -#ifdef __MINGW32__ -# undef _WIN32_WINNT -# define _WIN32_WINNT 0x501 -#endif - -#ifdef WIN32 -# include -# include -#else -# include -#endif -#include - -// ---------------------------------------------------------------------------- -/* Return TransportAddress (with optionally port) from string, it can also be - * used with an ipv4 string too. */ -TransportAddress TransportAddress::fromDomain(const std::string& str) -{ - TransportAddress result; - auto split = StringUtils::split(str, ':'); - if (split.empty()) - return result; - struct addrinfo hints; - struct addrinfo* res = NULL; - - memset(&hints, 0, sizeof hints); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - - int status = getaddrinfo_compat(split[0].c_str(), - split.size() > 1 ? split[1].c_str() : NULL, &hints, &res); - if (status != 0 || res == NULL) - { - Log::error("TransportAddress", "Error in getaddrinfo for fromDomain" - " %s: %s", split[0].c_str(), gai_strerror(status)); - return result; - } - struct sockaddr_in* ipv4_addr = (struct sockaddr_in*)(res->ai_addr); - result.setIP(ntohl(ipv4_addr->sin_addr.s_addr)); - result.setPort(ntohs(ipv4_addr->sin_port)); - freeaddrinfo(res); - return result; -} // fromDomain - -// ---------------------------------------------------------------------------- -/** Construct an IO address from a string in the format x.x.x.x with a - * port number. */ -TransportAddress::TransportAddress(const std::string& str, uint16_t port_number) -{ - std::vector ip = StringUtils::splitToUInt(str, '.'); - m_ip = 0; - m_port = 0; - if (ip.size() >= 4) - m_ip = (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3]; - - m_port = port_number; -} // TransportAddress(string of ip, port number) - -// ---------------------------------------------------------------------------- -/** Construct an IO address from a string in the format x.x.x.x:x. */ -TransportAddress::TransportAddress(const std::string& str) -{ - std::string combined = StringUtils::replace(str, ":", "."); - std::vector ip = StringUtils::splitToUInt(combined, '.'); - m_ip = 0; - m_port = 0; - if (ip.size() >= 4) - m_ip = (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3]; - - if(ip.size()==5) - m_port = (uint16_t)(ip[4] < 65536 ? ip[4] : 0); - else - m_port = 0; -} // TransportAddress(string of ip) - -// ---------------------------------------------------------------------------- -/** Returns if this IP address belongs to a LAN, i.e. is in 192.168* or - * 10*, 172.16-31.*, or is on the same host, i.e. 127* or same public address. - */ -bool TransportAddress::isLAN() const -{ - uint32_t ip = getIP(); - if (ip >> 16 == 0xc0a8) // Check for 192.168.* - return true; - else if (ip >> 20 == 0xac1 ) // 172.16-31.* - return true; - else if (ip >> 24 == 0x0a ) // 10.* - return true; - else if (ip >> 24 == 0x7f ) // 127.* localhost - return true; - return false; -} - -// ---------------------------------------------------------------------------- -/** Returns this IP address is localhost (127.0.0.1). - */ -bool TransportAddress::isPublicAddressLocalhost() const -{ -#ifndef WIN32 - char buffer[2048] = {}; - struct ifconf ifc; - ifc.ifc_len = sizeof(buffer); - ifc.ifc_buf = (caddr_t)buffer; - - int fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) - { - Log::error("TransportAddress","create socket failed, errno " - "= %s (%d)\n", strerror(errno), errno); - return false; - } - - if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) - { - if (fd >= 0) - close(fd); - Log::error("TransportAddress", "ioctl SIOCGIFCONF failed, " - "errno = %s (%d)\n", strerror(errno), errno); - return false; - } - bool is_local_host = false; - for (int i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq)) - { - struct ifreq *ifr = (struct ifreq*)(buffer + i); - if (ifr->ifr_addr.sa_family != AF_INET) - { - // only support IPv4 - continue; - } - struct sockaddr_in *addr = (struct sockaddr_in*)&ifr->ifr_addr; - if (ntohl(addr->sin_addr.s_addr) == getIP()) - { - is_local_host = true; - break; - } - } - if (fd >= 0 && close(fd) != 0) - { - Log::error("TransportAddress", "close fd %d failed, errno " - "= %s (%d)\n", strerror(errno), errno); - } - return is_local_host; - -#else - // Query the list of all IP addresses on the local host. First call to - // GetIpAddrTable with 0 bytes buffer will return insufficient buffer - // error, and size will contain the number of bytes needed for all data. - // Repeat the process of querying the size using GetIpAddrTable in a while - // loop since it can happen that an interface comes online between the - // previous call to GetIpAddrTable and the next call. - MIB_IPADDRTABLE *table = NULL; - unsigned long size = 0; - int error = GetIpAddrTable(table, &size, 0); - // Also add a count to limit the while loop - in case that something - // strange is going on. - int count = 0; - while (error == ERROR_INSUFFICIENT_BUFFER && count < 10) - { - delete[] table; // deleting NULL is legal - table = (MIB_IPADDRTABLE*)new char[size]; - error = GetIpAddrTable(table, &size, 0); - count++; - } // while insufficient buffer - for (unsigned int i = 0; i < table->dwNumEntries; i++) - { - unsigned int ip = ntohl(table->table[i].dwAddr); - if (getIP() == ip) // this interface is ours - { - delete[] table; - return true; - } - } - delete[] table; - return false; -#endif -} // isPublicAddressLocalhost - -// ---------------------------------------------------------------------------- -/** Unit testing. Test various LAN patterns to verify that isLAN() works as - * expected. - */ -void TransportAddress::unitTesting() -{ - TransportAddress t1("192.168.0.0"); - assert(t1.getIP() == (192u << 24) + (168u << 16)); - assert(t1.isLAN()); - - TransportAddress t2("192.168.255.255"); - assert(t2.getIP() == (192u << 24) + (168u << 16) + (255u << 8) + 255u); - assert(t2.isLAN()); - - TransportAddress t3("193.168.0.1"); - assert(t3.getIP() == (193u << 24) + (168u << 16) + 1); - assert(!t3.isLAN()); - - TransportAddress t4("192.167.255.255"); - assert(t4.getIP() == (192u << 24) + (167u << 16) + (255u << 8) + 255u); - assert(!t4.isLAN()); - - TransportAddress t5("192.169.0.0"); - assert(t5.getIP() == (192u << 24) + (169u << 16)); - assert(!t5.isLAN()); - - TransportAddress t6("172.16.0.0"); - assert(t6.getIP() == (172u << 24) + (16u << 16)); - assert(t6.isLAN()); - - TransportAddress t7("172.31.255.255"); - assert(t7.getIP() == (172u << 24) + (31u << 16) + (255u << 8) + 255u); - assert(t7.isLAN()); - - TransportAddress t8("172.15.255.255"); - assert(t8.getIP() == (172u << 24) + (15u << 16) + (255u << 8) + 255u); - assert(!t8.isLAN()); - - TransportAddress t9("172.32.0.0"); - assert(t9.getIP() == (172u << 24) + (32u << 16)); - assert(!t9.isLAN()); - - TransportAddress t10("10.0.0.0"); - assert(t10.getIP() == (10u << 24)); - assert(t10.isLAN()); - - TransportAddress t11("10.255.255.255"); - assert(t11.getIP() == (10u << 24) + (255u << 16) + (255u << 8) + 255u); - assert(t11.isLAN()); - - TransportAddress t12("9.255.255.255"); - assert(t12.getIP() == (9u << 24) + (255u << 16) + (255u << 8) + 255u); - assert(!t12.isLAN()); - - TransportAddress t13("11.0.0.0"); - assert(t13.getIP() == (11u << 24)); - assert(!t13.isLAN()); - - TransportAddress t14("127.0.0.0"); - assert(t14.getIP() == (127u << 24)); - assert(t14.isLAN()); - - TransportAddress t15("127.255.255.255"); - assert(t15.getIP() == (127u << 24) + (255u << 16) + (255u << 8) + 255u); - assert(t15.isLAN()); - - TransportAddress t16("126.255.255.255"); - assert(t16.getIP() == (126u << 24) + (255u << 16) + (255u << 8) + 255u); - assert(!t16.isLAN()); - - TransportAddress t17("128.0.0.0"); - assert(t17.getIP() == (128u << 24)); - assert(!t17.isLAN()); - - // Test constructors - TransportAddress t18("128.0.0.0"); - assert(t18.getIP() == (128u << 24)); - assert(t18.getPort() == 0); - - TransportAddress t19("128.0.0.0:1"); - assert(t19.getIP() == (128u << 24)); - assert(t19.getPort() == 1); - - TransportAddress t20("128.0.0.0", 123); - assert(t20.getIP() == (128u << 24)); - assert(t20.getPort() == 123); - -} // unitTesting - -// ---------------------------------------------------------------------------- -/** Returns a std::string representing the ip address and port in human - * readable format. - * \param show_port True if the port should be shown as well, otherwise - * only the ip address will be returned. - */ -std::string TransportAddress::toString(bool show_port) const -{ - std::string s = - StringUtils::insertValues("%d.%d.%d.%d", - ((m_ip >> 24) & 0xff), ((m_ip >> 16) & 0xff), - ((m_ip >> 8) & 0xff), ((m_ip >> 0) & 0xff)); - if (show_port) - s += StringUtils::insertValues(":%d", m_port); - return s; -} // toString diff --git a/src/network/transport_address.hpp b/src/network/transport_address.hpp deleted file mode 100644 index 5a3da4fac..000000000 --- a/src/network/transport_address.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013-2015 SuperTuxKart-Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -/*! \file types.hpp - * \brief Declares the general types that are used by the network. - */ -#ifndef HEADER_TRANSPORT_ADDRESS_HPP -#define HEADER_TRANSPORT_ADDRESS_HPP - -#include "utils/types.hpp" - -#include "enet/enet.h" - -#include - -// ============================================================================ -/*! \class TransportAddress - * \brief Describes a transport-layer address. - * For IP networks, a transport address is the couple ip:port. - */ -class TransportAddress -{ -private: - uint32_t m_ip; //!< The IPv4 address - uint16_t m_port; //!< The port number - -public: - /** Constructor. */ - TransportAddress(uint32_t ip = 0, uint16_t port = 0) - { - m_ip = ip; - m_port = port; - } // TransportAddress - - // ------------------------------------------------------------------------ - TransportAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, - uint16_t port=0) - { - m_ip = (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; - m_port = port; - } // TransportAddress(uint8_t,...) - - // ------------------------------------------------------------------------ - /** Construct an transport address from an ENetAddress. */ - TransportAddress(const ENetAddress &a) - { - m_ip = htonl(a.host); - m_port = a.port; - } // TransportAddress(EnetAddress) - - // ------------------------------------------------------------------------ - TransportAddress(const std::string& str, uint16_t port_number); - // ------------------------------------------------------------------------ - TransportAddress(const std::string& str); - // ------------------------------------------------------------------------ - ~TransportAddress() {} - // ------------------------------------------------------------------------ - static void unitTesting(); -public: - // ------------------------------------------------------------------------ - static TransportAddress fromDomain(const std::string& str); - // ------------------------------------------------------------------------ - bool isPublicAddressLocalhost() const; - // ------------------------------------------------------------------------ - bool isLAN() const; - // ------------------------------------------------------------------------ - bool isUnset() const { return m_ip == 0 || m_port == 0; } - // ------------------------------------------------------------------------ - /** Resets ip and port to 0. */ - void clear() - { - m_ip = 0; - m_port = 0; - } // clear - - // ------------------------------------------------------------------------ - /** Returns the ip address. */ - uint32_t getIP() const { return m_ip; } - - // ------------------------------------------------------------------------ - /** Returns the port number. */ - uint16_t getPort() const { return m_port; } - - // ------------------------------------------------------------------------ - /** Sets the ip address. */ - void setIP(uint32_t ip) { m_ip = ip; } - - // ------------------------------------------------------------------------ - /** Set the port. */ - void setPort(uint16_t port) { m_port = port; } - - // ------------------------------------------------------------------------ - /** Converts the address to an enet address. */ - ENetAddress toEnetAddress() const - { - ENetAddress a; - // because ENet wants little endian - a.host = ((m_ip & 0xff000000) >> 24) - + ((m_ip & 0x00ff0000) >> 8) - + ((m_ip & 0x0000ff00) << 8) - + ((m_ip & 0x000000ff) << 24); - a.port = m_port; - return a; - } // toEnetAddress - - // ------------------------------------------------------------------------ - /** Compares if ip address and port are identical. */ - bool operator==(const TransportAddress& other) const - { - return other.m_ip == m_ip && other.m_port == m_port; - } // operator== - - // ------------------------------------------------------------------------ - bool operator==(const ENetAddress& other) - { - return other.host == ntohl(m_ip) && other.port == m_port; - } - // ------------------------------------------------------------------------ - /** Compares if ip address or port are different. */ - bool operator!=(const TransportAddress& other) const - { - return other.m_ip != m_ip || other.m_port != m_port; - } // operator!= - // ------------------------------------------------------------------------ - std::string toString(bool show_port = true) const; -}; // TransportAddress - -#endif // TYPES_HPP diff --git a/src/states_screens/dialogs/network_player_dialog.cpp b/src/states_screens/dialogs/network_player_dialog.cpp index b9f4aaec9..314db2c15 100644 --- a/src/states_screens/dialogs/network_player_dialog.cpp +++ b/src/states_screens/dialogs/network_player_dialog.cpp @@ -26,6 +26,7 @@ #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp" #include "online/online_profile.hpp" +#include "network/network_string.hpp" #include "network/protocols/client_lobby.hpp" #include "network/stk_host.hpp" #include "states_screens/dialogs/general_text_field_dialog.hpp" diff --git a/src/states_screens/dialogs/server_configuration_dialog.cpp b/src/states_screens/dialogs/server_configuration_dialog.cpp index 49abf209f..845b85e3e 100644 --- a/src/states_screens/dialogs/server_configuration_dialog.cpp +++ b/src/states_screens/dialogs/server_configuration_dialog.cpp @@ -22,6 +22,7 @@ #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/spinner_widget.hpp" +#include "network/network_string.hpp" #include "network/protocols/lobby_protocol.hpp" #include "network/stk_host.hpp" #include "states_screens/state_manager.hpp" diff --git a/src/states_screens/online/network_kart_selection.cpp b/src/states_screens/online/network_kart_selection.cpp index 0c5e88786..1b94dfc32 100644 --- a/src/states_screens/online/network_kart_selection.cpp +++ b/src/states_screens/online/network_kart_selection.cpp @@ -21,6 +21,7 @@ #include "guiengine/widgets/progress_bar_widget.hpp" #include "input/device_manager.hpp" #include "network/network_config.hpp" +#include "network/network_string.hpp" #include "network/protocols/client_lobby.hpp" #include "network/stk_host.hpp" #include "states_screens/state_manager.hpp" diff --git a/src/states_screens/online/networking_lobby.cpp b/src/states_screens/online/networking_lobby.cpp index 8c1fcc738..16c893acc 100644 --- a/src/states_screens/online/networking_lobby.cpp +++ b/src/states_screens/online/networking_lobby.cpp @@ -41,6 +41,7 @@ #include "network/game_setup.hpp" #include "network/race_event_manager.hpp" #include "network/network_config.hpp" +#include "network/network_string.hpp" #include "network/protocols/connect_to_server.hpp" #include "network/protocols/game_protocol.hpp" #include "network/protocols/client_lobby.hpp"