Since broadcasting to 255.255.255.255 does not work in all cases,
add code to create a set of potential broadcast addresses and use them all. Duplicated will be filtered out (since likely a server will replace more than all).
This commit is contained in:
parent
bc8539ae10
commit
59b796a7f5
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "config/user_config.hpp"
|
#include "config/user_config.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
#include "network/network_config.hpp"
|
||||||
#include "network/network_string.hpp"
|
#include "network/network_string.hpp"
|
||||||
#include "network/transport_address.hpp"
|
#include "network/transport_address.hpp"
|
||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
@ -27,12 +28,16 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
# include "ws2tcpip.h"
|
# include "ws2tcpip.h"
|
||||||
|
# include <iphlpapi.h>
|
||||||
# define inet_ntop InetNtop
|
# define inet_ntop InetNtop
|
||||||
#else
|
#else
|
||||||
# include <arpa/inet.h>
|
# include <arpa/inet.h>
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
|
# include <ifaddrs.h>
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
@ -225,3 +230,135 @@ void Network::closeLog()
|
|||||||
m_log_file.unlock();
|
m_log_file.unlock();
|
||||||
}
|
}
|
||||||
} // closeLog
|
} // closeLog
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Sets a list of default broadcast addresses which is used in case no valid
|
||||||
|
* broadcast address is found. This list includes default private network
|
||||||
|
* addresses.
|
||||||
|
*/
|
||||||
|
void Network::setDefaultBroadcastAddresses()
|
||||||
|
{
|
||||||
|
// Add some common LAN addresses
|
||||||
|
m_broadcast_address.emplace_back(std::string("192.168.255.255"));
|
||||||
|
m_broadcast_address.emplace_back(std::string("192.168.255.255"));
|
||||||
|
m_broadcast_address.emplace_back(std::string("192.168.255.255"));
|
||||||
|
m_broadcast_address.emplace_back(std::string("192.168.0.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("172.31.255.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("172.16.255.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("172.16.0.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("10.255.255.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("10.0.255.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("10.0.0.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("255.255.255.255"));
|
||||||
|
m_broadcast_address.emplace_back(std::string("127.0.0.255") );
|
||||||
|
m_broadcast_address.emplace_back(std::string("127.0.0.1") );
|
||||||
|
} // setDefaultBroadcastAddresses
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** This masks various possible broadcast addresses. For example, in a /16
|
||||||
|
* network it would first use *.*.255.255, then *.*.*.255. Also if the
|
||||||
|
* length of the mask is not a multiple of 8, the original value will
|
||||||
|
* be used, before multiple of 8 are create: /22 (*.3f.ff.ff), then
|
||||||
|
* /16 (*.*.ff.ff), /8 (*.*.*.ff). While this is usually an overkill,
|
||||||
|
* it can help in the case that the router does not forward a broadcast
|
||||||
|
* as expected (this problem often happens with 255.255.255.255, which is
|
||||||
|
* why this broadcast address creation code was added).
|
||||||
|
* \param a The transport address for which the broadcast addresses need
|
||||||
|
* to be created.
|
||||||
|
* \param len Number of bits to be or'ed.
|
||||||
|
*/
|
||||||
|
void Network::addAllBroadcastAddresses(const TransportAddress &a, int len)
|
||||||
|
{
|
||||||
|
// Try different broadcast addresses - by masking on
|
||||||
|
// byte boundaries
|
||||||
|
while (len > 0)
|
||||||
|
{
|
||||||
|
unsigned int mask = (1 << len) - 1;
|
||||||
|
TransportAddress bcast(a.getIP() | mask,
|
||||||
|
NetworkConfig::get()->getServerDiscoveryPort());
|
||||||
|
Log::info("Broadcast", "address %s length %d mask %x --> %s",
|
||||||
|
a.toString().c_str(),
|
||||||
|
len, mask,
|
||||||
|
bcast.toString().c_str());
|
||||||
|
m_broadcast_address.push_back(bcast);
|
||||||
|
if (len % 8 != 0)
|
||||||
|
len -= (len % 8);
|
||||||
|
else
|
||||||
|
len = len - 8;
|
||||||
|
} // while len > 0
|
||||||
|
} // addAllBroadcastAddresses
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Returns a list of all possible broadcast addresses on this machine.
|
||||||
|
* It queries all adapters for active IPV4 interfaces, determines their
|
||||||
|
* netmask to create the broadcast addresses. It will also add 'smaller'
|
||||||
|
* broadcast addesses, e.g. in a /16 network, it will add *.*.255.255 and
|
||||||
|
* *.*.*.255, since it was sometimes observed that routers would not let
|
||||||
|
* all broadcast addresses through. Duplicated answers (from the same server
|
||||||
|
* to different addersses) will be filtered out in ServersManager.
|
||||||
|
*/
|
||||||
|
const std::vector<TransportAddress>& Network::getBroadcastAddresses()
|
||||||
|
{
|
||||||
|
if (m_broadcast_address.size() > 0) return m_broadcast_address;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
IP_ADAPTER_ADDRESSES *addresses;
|
||||||
|
int count = 100, return_code;
|
||||||
|
|
||||||
|
int iteration = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
addresses = new IP_ADAPTER_ADDRESSES[count];
|
||||||
|
ULONG buf_len = sizeof(IP_ADAPTER_ADDRESSES)*count;
|
||||||
|
long flags = 0;
|
||||||
|
return_code = GetAdaptersAddresses(AF_INET, flags, NULL, addresses,
|
||||||
|
&buf_len);
|
||||||
|
iteration++;
|
||||||
|
} while (return_code == ERROR_BUFFER_OVERFLOW && iteration<10);
|
||||||
|
|
||||||
|
if (return_code == ERROR_BUFFER_OVERFLOW)
|
||||||
|
{
|
||||||
|
Log::warn("NetworkConfig", "Can not get broadcast addresses.");
|
||||||
|
setDefaultBroadcastAddresses();
|
||||||
|
return m_broadcast_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IP_ADAPTER_ADDRESSES *p = addresses; p; p = p->Next)
|
||||||
|
{
|
||||||
|
// Check all operational IP4 adapters
|
||||||
|
if (p->OperStatus == IfOperStatusUp &&
|
||||||
|
p->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET)
|
||||||
|
{
|
||||||
|
const sockaddr_in *sa = (sockaddr_in*)p->FirstUnicastAddress->Address.lpSockaddr;
|
||||||
|
// Use sa->sin_addr.S_un.S_addr and htonl?
|
||||||
|
TransportAddress ta(sa->sin_addr.S_un.S_un_b.s_b1,
|
||||||
|
sa->sin_addr.S_un.S_un_b.s_b2,
|
||||||
|
sa->sin_addr.S_un.S_un_b.s_b3,
|
||||||
|
sa->sin_addr.S_un.S_un_b.s_b4);
|
||||||
|
int len = 32 - p->FirstUnicastAddress->OnLinkPrefixLength;
|
||||||
|
addAllBroadcastAddresses(ta, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
struct ifaddrs *addresses, *p;
|
||||||
|
|
||||||
|
getifaddrs(&addresses);
|
||||||
|
for (p = addresses; p; p = p->ifa_next)
|
||||||
|
{
|
||||||
|
if (p->ifa_addr->sa_family == AF_INET)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *sa = (struct sockaddr_in *) p->ifa_addr;
|
||||||
|
TransportAddress ta(sa->sin_addr, get);
|
||||||
|
char *addr = inet_ntoa(sa->sin_addr);
|
||||||
|
int ip = ((sockaddr_in*)(p->ifa_netmask))->sin_addr.s_addr;
|
||||||
|
ip = ~ip;
|
||||||
|
printf("Interface: %s\tAddress: %s\tmask: %x -> %x\n", p->ifa_name,
|
||||||
|
addr, p->ifa_netmask, htonl(ip));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return m_broadcast_address;
|
||||||
|
} // getBroadcastAddresses
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <enet/enet.h>
|
#include <enet/enet.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class BareNetworkString;
|
class BareNetworkString;
|
||||||
class NetworkString;
|
class NetworkString;
|
||||||
@ -50,6 +51,12 @@ private:
|
|||||||
/** Where to log packets. If NULL for FILE* logging is disabled. */
|
/** Where to log packets. If NULL for FILE* logging is disabled. */
|
||||||
static Synchronised<FILE*> m_log_file;
|
static Synchronised<FILE*> m_log_file;
|
||||||
|
|
||||||
|
/** List of broadcast addresses to use. */
|
||||||
|
std::vector<TransportAddress> m_broadcast_address;
|
||||||
|
|
||||||
|
void setDefaultBroadcastAddresses();
|
||||||
|
void addAllBroadcastAddresses(const TransportAddress &a, int len);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Network(int peer_count, int channel_limit,
|
Network(int peer_count, int channel_limit,
|
||||||
uint32_t max_incoming_bandwidth,
|
uint32_t max_incoming_bandwidth,
|
||||||
@ -68,6 +75,8 @@ public:
|
|||||||
TransportAddress* sender, int max_tries = -1);
|
TransportAddress* sender, int max_tries = -1);
|
||||||
void broadcastPacket(NetworkString *data,
|
void broadcastPacket(NetworkString *data,
|
||||||
bool reliable = true);
|
bool reliable = true);
|
||||||
|
const std::vector<TransportAddress>& getBroadcastAddresses();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns a pointer to the ENet host object. */
|
/** Returns a pointer to the ENet host object. */
|
||||||
ENetHost* getENetHost() { return m_host; }
|
ENetHost* getENetHost() { return m_host; }
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "network/network_config.hpp"
|
#include "network/network_config.hpp"
|
||||||
#include "config/stk_config.hpp"
|
#include "config/stk_config.hpp"
|
||||||
#include "config/user_config.hpp"
|
#include "config/user_config.hpp"
|
||||||
|
#include "network/transport_address.hpp"
|
||||||
#include "online/xml_request.hpp"
|
#include "online/xml_request.hpp"
|
||||||
#include "states_screens/main_menu_screen.hpp"
|
#include "states_screens/main_menu_screen.hpp"
|
||||||
#include "states_screens/networking_lobby.hpp"
|
#include "states_screens/networking_lobby.hpp"
|
||||||
@ -78,7 +79,7 @@ void NetworkConfig::setIsServer(bool b)
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void NetworkConfig::setServerMode(RaceManager::MinorRaceModeType minor,
|
void NetworkConfig::setServerMode(RaceManager::MinorRaceModeType minor,
|
||||||
RaceManager::MajorRaceModeType major)
|
RaceManager::MajorRaceModeType major)
|
||||||
{
|
{
|
||||||
if (major == RaceManager::MAJOR_MODE_GRAND_PRIX)
|
if (major == RaceManager::MAJOR_MODE_GRAND_PRIX)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "network/transport_address.hpp"
|
#include "network/transport_address.hpp"
|
||||||
#include "race/race_manager.hpp"
|
#include "race/race_manager.hpp"
|
||||||
|
#include "utils/no_copy.hpp"
|
||||||
|
|
||||||
#include "irrString.h"
|
#include "irrString.h"
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -42,7 +43,7 @@ namespace GUIEngine
|
|||||||
class InputDevice;
|
class InputDevice;
|
||||||
class PlayerProfile;
|
class PlayerProfile;
|
||||||
|
|
||||||
class NetworkConfig
|
class NetworkConfig : public NoCopy
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/** The singleton instance. */
|
/** The singleton instance. */
|
||||||
|
@ -97,7 +97,7 @@ void ClientLobby::clearPlayers()
|
|||||||
*/
|
*/
|
||||||
void ClientLobby::setAddress(const TransportAddress &address)
|
void ClientLobby::setAddress(const TransportAddress &address)
|
||||||
{
|
{
|
||||||
m_server_address.copy(address);
|
m_server_address = address;
|
||||||
} // setAddress
|
} // setAddress
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -46,7 +46,7 @@ ConnectToPeer::ConnectToPeer(uint32_t peer_id) : Protocol(PROTOCOL_CONNECTION)
|
|||||||
ConnectToPeer::ConnectToPeer(const TransportAddress &address)
|
ConnectToPeer::ConnectToPeer(const TransportAddress &address)
|
||||||
: Protocol(PROTOCOL_CONNECTION)
|
: Protocol(PROTOCOL_CONNECTION)
|
||||||
{
|
{
|
||||||
m_peer_address.copy(address);
|
m_peer_address = address;
|
||||||
// We don't need to find the peer address, so we can start
|
// We don't need to find the peer address, so we can start
|
||||||
// with the state when we found the peer address.
|
// with the state when we found the peer address.
|
||||||
m_state = WAIT_FOR_CONNECTION;
|
m_state = WAIT_FOR_CONNECTION;
|
||||||
@ -84,7 +84,7 @@ void ConnectToPeer::asynchronousUpdate()
|
|||||||
assert(get_peer_address);
|
assert(get_peer_address);
|
||||||
if (get_peer_address->getAddress().isUnset())
|
if (get_peer_address->getAddress().isUnset())
|
||||||
return;
|
return;
|
||||||
m_peer_address.copy(get_peer_address->getAddress());
|
m_peer_address = get_peer_address->getAddress();
|
||||||
m_current_protocol = nullptr;
|
m_current_protocol = nullptr;
|
||||||
if (m_peer_address.isUnset())
|
if (m_peer_address.isUnset())
|
||||||
{
|
{
|
||||||
@ -117,7 +117,7 @@ void ConnectToPeer::asynchronousUpdate()
|
|||||||
// The wan remote should already start its ping message to us now
|
// The wan remote should already start its ping message to us now
|
||||||
// so we can send packet directly to it.
|
// so we can send packet directly to it.
|
||||||
TransportAddress broadcast_address;
|
TransportAddress broadcast_address;
|
||||||
broadcast_address.copy(m_peer_address);
|
broadcast_address = m_peer_address;
|
||||||
|
|
||||||
BareNetworkString aloha(std::string("aloha_stk"));
|
BareNetworkString aloha(std::string("aloha_stk"));
|
||||||
STKHost::get()->sendRawPacket(aloha, broadcast_address);
|
STKHost::get()->sendRawPacket(aloha, broadcast_address);
|
||||||
|
@ -46,8 +46,8 @@ ConnectToServer::ConnectToServer(std::shared_ptr<Server> server)
|
|||||||
{
|
{
|
||||||
if (server)
|
if (server)
|
||||||
{
|
{
|
||||||
m_server = server;
|
m_server = server;
|
||||||
m_server_address.copy(m_server->getAddress());
|
m_server_address = m_server->getAddress();
|
||||||
}
|
}
|
||||||
setHandleConnections(true);
|
setHandleConnections(true);
|
||||||
} // ConnectToServer(server, host)
|
} // ConnectToServer(server, host)
|
||||||
@ -105,7 +105,7 @@ void ConnectToServer::asynchronousUpdate()
|
|||||||
return a->getCurrentPlayers() < b->getCurrentPlayers();
|
return a->getCurrentPlayers() < b->getCurrentPlayers();
|
||||||
});
|
});
|
||||||
m_server = servers[0];
|
m_server = servers[0];
|
||||||
m_server_address.copy(m_server->getAddress());
|
m_server_address = m_server->getAddress();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -435,7 +435,7 @@ void ConnectToServer::waitingAloha(bool is_wan)
|
|||||||
if (sender.isPublicAddressLocalhost())
|
if (sender.isPublicAddressLocalhost())
|
||||||
sender.setIP(0x7f000001); // 127.0.0.1
|
sender.setIP(0x7f000001); // 127.0.0.1
|
||||||
}
|
}
|
||||||
m_server_address.copy(sender);
|
m_server_address = sender;
|
||||||
m_state = CONNECTING;
|
m_state = CONNECTING;
|
||||||
// Reset timer for next usage
|
// Reset timer for next usage
|
||||||
m_timer = 0.0;
|
m_timer = 0.0;
|
||||||
|
@ -264,7 +264,7 @@ void ServerLobby::asynchronousUpdate()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_server_address.copy(STKHost::get()->getPublicAddress());
|
m_server_address = STKHost::get()->getPublicAddress();
|
||||||
STKHost::get()->startListening();
|
STKHost::get()->startListening();
|
||||||
m_state = REGISTER_SELF_ADDRESS;
|
m_state = REGISTER_SELF_ADDRESS;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ void RewindManager::addEvent(EventRewinder *event_rewinder,
|
|||||||
* \param buffer Pointer to the event data.
|
* \param buffer Pointer to the event data.
|
||||||
*/
|
*/
|
||||||
void RewindManager::addNetworkEvent(EventRewinder *event_rewinder,
|
void RewindManager::addNetworkEvent(EventRewinder *event_rewinder,
|
||||||
BareNetworkString *buffer, int ticks)
|
BareNetworkString *buffer, int ticks)
|
||||||
{
|
{
|
||||||
m_rewind_queue.addNetworkEvent(event_rewinder, buffer, ticks);
|
m_rewind_queue.addNetworkEvent(event_rewinder, buffer, ticks);
|
||||||
} // addNetworkEvent
|
} // addNetworkEvent
|
||||||
|
@ -116,11 +116,11 @@ Server::Server(unsigned server_id, const core::stringw &name, int max_players,
|
|||||||
m_server_owner = 0;
|
m_server_owner = 0;
|
||||||
m_current_players = current_players;
|
m_current_players = current_players;
|
||||||
m_max_players = max_players;
|
m_max_players = max_players;
|
||||||
m_address.copy(address);
|
m_address = address;
|
||||||
// In case of LAN server, public and private port are the same.
|
// In case of LAN server, public and private port are the same.
|
||||||
m_private_port = m_address.getPort();
|
m_private_port = m_address.getPort();
|
||||||
m_difficulty = (RaceManager::Difficulty)difficulty;
|
m_difficulty = (RaceManager::Difficulty)difficulty;
|
||||||
m_server_mode = server_mode;
|
m_server_mode = server_mode;
|
||||||
m_password_protected = password_protected;
|
m_password_protected = password_protected;
|
||||||
m_distance = 0.0f;
|
m_distance = 0.0f;
|
||||||
} // server(server_id, ...)
|
} // server(server_id, ...)
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <irrString.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define SERVER_REFRESH_INTERVAL 5.0f
|
#define SERVER_REFRESH_INTERVAL 5.0f
|
||||||
@ -136,11 +135,14 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
|
|||||||
addr.host = STKHost::HOST_ANY;
|
addr.host = STKHost::HOST_ANY;
|
||||||
addr.port = STKHost::PORT_ANY;
|
addr.port = STKHost::PORT_ANY;
|
||||||
Network *broadcast = new Network(1, 1, 0, 0, &addr);
|
Network *broadcast = new Network(1, 1, 0, 0, &addr);
|
||||||
|
const std::vector<TransportAddress> &all_bcast =
|
||||||
BareNetworkString s(std::string("stk-server"));
|
broadcast->getBroadcastAddresses();
|
||||||
TransportAddress broadcast_address(-1,
|
for (auto &bcast_addr : all_bcast)
|
||||||
NetworkConfig::get()->getServerDiscoveryPort());
|
{
|
||||||
broadcast->sendRawPacket(s, broadcast_address);
|
Log::info("Server Discovery", "Broadcasting to %s",
|
||||||
|
bcast_addr.toString().c_str());
|
||||||
|
broadcast->sendRawPacket(std::string("stk-server"), bcast_addr);
|
||||||
|
}
|
||||||
|
|
||||||
Log::info("ServersManager", "Sent broadcast message.");
|
Log::info("ServersManager", "Sent broadcast message.");
|
||||||
|
|
||||||
@ -153,7 +155,12 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
|
|||||||
const auto& servers = ServersManager::get()->getServers();
|
const auto& servers = ServersManager::get()->getServers();
|
||||||
int cur_server_id = (int)servers.size();
|
int cur_server_id = (int)servers.size();
|
||||||
assert(cur_server_id == 0);
|
assert(cur_server_id == 0);
|
||||||
std::vector<std::shared_ptr<Server> > servers_now;
|
// Use a map with the server name as key to automatically remove
|
||||||
|
// duplicated answers from a server (since we potentially do
|
||||||
|
// multiple broadcasts). We can not use the sender ip address,
|
||||||
|
// because e.g. a local client would answer as 127.0.0.1 and
|
||||||
|
// 192.168.**.
|
||||||
|
std::map<irr::core::stringw, std::shared_ptr<Server> > servers_now;
|
||||||
while (StkTime::getRealTime() - start_time < DURATION)
|
while (StkTime::getRealTime() - start_time < DURATION)
|
||||||
{
|
{
|
||||||
TransportAddress sender;
|
TransportAddress sender;
|
||||||
@ -178,9 +185,10 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
|
|||||||
uint8_t mode = s.getUInt8();
|
uint8_t mode = s.getUInt8();
|
||||||
sender.setPort(port);
|
sender.setPort(port);
|
||||||
uint8_t password = s.getUInt8();
|
uint8_t password = s.getUInt8();
|
||||||
servers_now.emplace_back(std::make_shared<Server>
|
servers_now.emplace(name, std::make_shared<Server>
|
||||||
(cur_server_id++, name, max_players, players,
|
(cur_server_id++, name, max_players, players,
|
||||||
difficulty, mode, sender, password == 1));
|
difficulty, mode, sender, password == 1) );
|
||||||
|
//all_servers.[name] = servers_now.back();
|
||||||
} // if received_data
|
} // if received_data
|
||||||
} // while still waiting
|
} // while still waiting
|
||||||
m_success = true;
|
m_success = true;
|
||||||
@ -199,6 +207,20 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
|
|||||||
|
|
||||||
} // getLANRefreshRequest
|
} // getLANRefreshRequest
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Takes a mapping of server name to server data (to avoid having the same
|
||||||
|
* server listed more than once since the client will be doing multiple
|
||||||
|
* broadcasts to find a server), and converts this into a list of servers.
|
||||||
|
* \param servers Mapping of server name to Server object.
|
||||||
|
*/
|
||||||
|
void ServersManager::setLanServers(const std::map<irr::core::stringw,
|
||||||
|
std::shared_ptr<Server> >& servers)
|
||||||
|
{
|
||||||
|
m_servers.clear();
|
||||||
|
for (auto i : servers) m_servers.emplace_back(i.second);
|
||||||
|
m_list_updated = true;
|
||||||
|
|
||||||
|
}
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Factory function to create either a LAN or a WAN update-of-server
|
/** Factory function to create either a LAN or a WAN update-of-server
|
||||||
* requests. The current list of servers is also cleared.
|
* requests. The current list of servers is also cleared.
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
#ifndef HEADER_SERVERS_MANAGER_HPP
|
#ifndef HEADER_SERVERS_MANAGER_HPP
|
||||||
#define HEADER_SERVERS_MANAGER_HPP
|
#define HEADER_SERVERS_MANAGER_HPP
|
||||||
|
|
||||||
|
#include <irrString.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -48,16 +51,12 @@ private:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setWanServers(bool success, const XMLNode* input);
|
void setWanServers(bool success, const XMLNode* input);
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setLanServers(std::vector<std::shared_ptr<Server> >& servers)
|
|
||||||
{
|
|
||||||
m_servers = std::move(servers);
|
|
||||||
m_list_updated = true;
|
|
||||||
}
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
Online::XMLRequest* getWANRefreshRequest() const;
|
Online::XMLRequest* getWANRefreshRequest() const;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
Online::XMLRequest* getLANRefreshRequest() const;
|
Online::XMLRequest* getLANRefreshRequest() const;
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
void setLanServers(const std::map<irr::core::stringw,
|
||||||
|
std::shared_ptr<Server> >& servers);
|
||||||
public:
|
public:
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Singleton
|
// Singleton
|
||||||
|
@ -577,12 +577,12 @@ void STKHost::setPublicAddress()
|
|||||||
// alternate NAT traversal methods.
|
// alternate NAT traversal methods.
|
||||||
if (!xor_addr.isUnset())
|
if (!xor_addr.isUnset())
|
||||||
{
|
{
|
||||||
m_public_address.copy(xor_addr);
|
m_public_address = xor_addr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log::warn("STKHost", "Only non xor-mapped address returned.");
|
Log::warn("STKHost", "Only non xor-mapped address returned.");
|
||||||
m_public_address.copy(non_xor_addr);
|
m_public_address = non_xor_addr;
|
||||||
}
|
}
|
||||||
// Succeed, save ping
|
// Succeed, save ping
|
||||||
UserConfigParams::m_stun_list[server_name] =
|
UserConfigParams::m_stun_list[server_name] =
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#ifndef HEADER_TRANSPORT_ADDRESS_HPP
|
#ifndef HEADER_TRANSPORT_ADDRESS_HPP
|
||||||
#define HEADER_TRANSPORT_ADDRESS_HPP
|
#define HEADER_TRANSPORT_ADDRESS_HPP
|
||||||
|
|
||||||
#include "utils/no_copy.hpp"
|
|
||||||
#include "utils/string_utils.hpp"
|
#include "utils/string_utils.hpp"
|
||||||
#include "utils/types.hpp"
|
#include "utils/types.hpp"
|
||||||
|
|
||||||
@ -35,7 +34,7 @@
|
|||||||
* \brief Describes a transport-layer address.
|
* \brief Describes a transport-layer address.
|
||||||
* For IP networks, a transport address is the couple ip:port.
|
* For IP networks, a transport address is the couple ip:port.
|
||||||
*/
|
*/
|
||||||
class TransportAddress : public NoCopy
|
class TransportAddress
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint32_t m_ip; //!< The IPv4 address
|
uint32_t m_ip; //!< The IPv4 address
|
||||||
@ -49,6 +48,14 @@ public:
|
|||||||
m_port = port;
|
m_port = port;
|
||||||
} // TransportAddress
|
} // 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. */
|
/** Construct an transport address from an ENetAddress. */
|
||||||
TransportAddress(const ENetAddress &a)
|
TransportAddress(const ENetAddress &a)
|
||||||
@ -92,15 +99,6 @@ public:
|
|||||||
~TransportAddress() {}
|
~TransportAddress() {}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
static void unitTesting();
|
static void unitTesting();
|
||||||
private:
|
|
||||||
friend class NetworkConfig;
|
|
||||||
/** The copy constructor is private, so that the friend class
|
|
||||||
* NetworkConfig can access it to create a copy (getMyAddress), but
|
|
||||||
* no other class can. */
|
|
||||||
TransportAddress(const TransportAddress &other)
|
|
||||||
{
|
|
||||||
copy(other);
|
|
||||||
} // TransportAddress(const TransportAddress&)
|
|
||||||
public:
|
public:
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool isPublicAddressLocalhost() const;
|
bool isPublicAddressLocalhost() const;
|
||||||
@ -108,15 +106,6 @@ public:
|
|||||||
bool isLAN() const;
|
bool isLAN() const;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool isUnset() const { return m_ip == 0 || m_port == 0; }
|
bool isUnset() const { return m_ip == 0 || m_port == 0; }
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** A copy function (to replace the copy constructor which is disabled
|
|
||||||
* using NoCopy): it copies the data from the argument into this object.*/
|
|
||||||
void copy(const TransportAddress &other)
|
|
||||||
{
|
|
||||||
m_ip = other.m_ip;
|
|
||||||
m_port = other.m_port;
|
|
||||||
} // copy
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Resets ip and port to 0. */
|
/** Resets ip and port to 0. */
|
||||||
void clear()
|
void clear()
|
||||||
|
@ -271,8 +271,8 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_entered_server_address.copy(
|
m_entered_server_address =
|
||||||
STKHost::get()->getServerPeerForClient()->getAddress());
|
STKHost::get()->getServerPeerForClient()->getAddress();
|
||||||
auto cl = LobbyProtocol::create<ClientLobby>();
|
auto cl = LobbyProtocol::create<ClientLobby>();
|
||||||
cl->setAddress(m_entered_server_address);
|
cl->setAddress(m_entered_server_address);
|
||||||
cl->requestStart();
|
cl->requestStart();
|
||||||
|
Loading…
Reference in New Issue
Block a user