Use IP detect code in server screen for more info to user
This commit is contained in:
parent
fcdec55bc1
commit
726a40ae2d
@ -51,7 +51,7 @@ class NetworkConfig : public NoCopy
|
||||
public:
|
||||
enum IPType : uint8_t
|
||||
{
|
||||
IP_NONE, IP_V4, IP_V6, IP_DUAL_STACK
|
||||
IP_NONE, IP_V4, IP_V6, IP_V6_NAT64, IP_DUAL_STACK
|
||||
};
|
||||
private:
|
||||
/** The singleton instance. */
|
||||
|
@ -32,7 +32,9 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#if defined(WIN32)
|
||||
# undef _WIN32_WINNT
|
||||
@ -84,14 +86,29 @@ std::shared_ptr<Online::XMLRequest> ServersManager::getWANRefreshRequest() const
|
||||
* when the request is finished. */
|
||||
class WANRefreshRequest : public Online::XMLRequest
|
||||
{
|
||||
private:
|
||||
// Run the ip detect in separate thread, so it can be done parallel
|
||||
// with the wan server request (which takes few seconds too)
|
||||
std::thread m_ip_detect_thread;
|
||||
public:
|
||||
WANRefreshRequest() : Online::XMLRequest(/*priority*/100) {}
|
||||
WANRefreshRequest() : Online::XMLRequest(/*priority*/100)
|
||||
{
|
||||
m_ip_detect_thread = std::thread(std::bind(
|
||||
&NetworkConfig::detectIPType, NetworkConfig::get()));
|
||||
}
|
||||
~WANRefreshRequest()
|
||||
{
|
||||
if (m_ip_detect_thread.joinable())
|
||||
m_ip_detect_thread.join();
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
virtual void afterOperation() OVERRIDE
|
||||
{
|
||||
Online::XMLRequest::afterOperation();
|
||||
if (m_ip_detect_thread.joinable())
|
||||
m_ip_detect_thread.join();
|
||||
ServersManager::get()->setWanServers(isSuccess(), getXMLData());
|
||||
} // callback
|
||||
} // afterOperation
|
||||
// --------------------------------------------------------------------
|
||||
}; // RefreshRequest
|
||||
// ========================================================================
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "guiengine/widgets/check_box_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
@ -49,6 +50,8 @@ ServerSelection::ServerSelection() : Screen("online/server_selection.stkgui")
|
||||
{
|
||||
m_refreshing_server = false;
|
||||
m_refresh_timer = 0.0f;
|
||||
m_ipv6_only_without_nat64 = false;
|
||||
m_ip_warning_shown = false;
|
||||
} // ServerSelection
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -78,6 +81,7 @@ void ServerSelection::refresh(bool full_refresh)
|
||||
// 5 seconds), clear the list and display the waiting message:
|
||||
if (ServersManager::get()->refresh(full_refresh))
|
||||
{
|
||||
m_ip_warning_shown = false;
|
||||
m_server_list_widget->clear();
|
||||
m_reload_widget->setActive(false);
|
||||
m_refreshing_server = true;
|
||||
@ -189,6 +193,8 @@ void ServerSelection::init()
|
||||
/** Triggers the loading of the server list in the servers manager. */
|
||||
ServersManager::get()->reset();
|
||||
refresh(true);
|
||||
m_ipv6_only_without_nat64 = false;
|
||||
m_ip_warning_shown = false;
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -302,6 +308,10 @@ void ServerSelection::eventCallback(GUIEngine::Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
//I18N: Message shown to user if no IPv4 detected by STK
|
||||
auto v4 = _("No IPv4 detected, you may not be able to join any servers.");
|
||||
//I18N: Message shown to user if no IPv6 detected by STK
|
||||
auto v6 = _("No IPv6 detected, you may not be able to join any servers.");
|
||||
if (name == "back")
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
@ -312,6 +322,18 @@ void ServerSelection::eventCallback(GUIEngine::Widget* widget,
|
||||
}
|
||||
else if (name == "private_server" || name == "ipv6")
|
||||
{
|
||||
if (!m_ip_warning_shown && m_ipv6->getState() &&
|
||||
NetworkConfig::get()->getIPType() == NetworkConfig::IP_V4)
|
||||
{
|
||||
m_ip_warning_shown = true;
|
||||
MessageQueue::add(MessageQueue::MT_ERROR, v6);
|
||||
}
|
||||
else if (!m_ip_warning_shown && !m_ipv6->getState() &&
|
||||
NetworkConfig::get()->getIPType() == NetworkConfig::IP_V6)
|
||||
{
|
||||
m_ip_warning_shown = true;
|
||||
MessageQueue::add(MessageQueue::MT_ERROR, v4);
|
||||
}
|
||||
copyFromServersManager();
|
||||
}
|
||||
else if (name == m_server_list_widget->m_properties[GUIEngine::PROP_ID])
|
||||
@ -359,6 +381,14 @@ void ServerSelection::onUpdate(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_ipv6_only_without_nat64 &&
|
||||
NetworkConfig::get()->getIPType() == NetworkConfig::IP_V6)
|
||||
{
|
||||
// Enable IPv6 button if IPv6 only without NAT64
|
||||
m_ipv6_only_without_nat64 = true;
|
||||
m_ipv6->setState(true);
|
||||
}
|
||||
|
||||
if (!m_refreshing_server) return;
|
||||
|
||||
if (ServersManager::get()->listUpdated())
|
||||
|
@ -84,6 +84,8 @@ private:
|
||||
|
||||
void refresh(bool full_refresh);
|
||||
|
||||
bool m_ipv6_only_without_nat64;
|
||||
bool m_ip_warning_shown;
|
||||
public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
Loading…
Reference in New Issue
Block a user