mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-09 04:13:28 -05:00
Separate out GetExternalIPAddress helper function
De-duplicates the two inline implementations and prepares it for use from Android.
This commit is contained in:
parent
39d17b2faf
commit
3e34012148
|
|
@ -9,6 +9,7 @@
|
|||
#include <lzo/lzo1x.h>
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/HttpRequest.h"
|
||||
#include "Common/IOFile.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/SFMLHelper.h"
|
||||
|
|
@ -297,4 +298,18 @@ std::optional<std::vector<u8>> DecompressPacketIntoBuffer(sf::Packet& packet)
|
|||
|
||||
return out_buffer;
|
||||
}
|
||||
|
||||
std::string GetExternalIPAddress()
|
||||
{
|
||||
Common::HttpRequest request;
|
||||
// ENet does not support IPv6, so IPv4 has to be used
|
||||
request.UseIPv4();
|
||||
Common::HttpRequest::Response response =
|
||||
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
||||
|
||||
if (response.has_value())
|
||||
return std::string(response->begin(), response->end());
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace NetPlay
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ using namespace std::chrono_literals;
|
|||
// connection is disconnected
|
||||
constexpr std::chrono::milliseconds PEER_TIMEOUT = 30s;
|
||||
|
||||
std::string GetExternalIPAddress();
|
||||
|
||||
bool CompressFileIntoPacket(const std::string& file_path, sf::Packet& packet);
|
||||
bool CompressFolderIntoPacket(const std::string& folder_path, sf::Packet& packet);
|
||||
bool CompressBufferIntoPacket(std::span<const u8> in_buffer, sf::Packet& packet);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "Common/CommonPaths.h"
|
||||
#include "Common/ENet.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/HttpRequest.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/SFMLHelper.h"
|
||||
|
|
@ -220,16 +219,9 @@ void NetPlayServer::SetupIndex()
|
|||
}
|
||||
else
|
||||
{
|
||||
Common::HttpRequest request;
|
||||
// ENet does not support IPv6, so IPv4 has to be used
|
||||
request.UseIPv4();
|
||||
Common::HttpRequest::Response response =
|
||||
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
||||
|
||||
if (!response.has_value())
|
||||
session.server_id = GetExternalIPAddress();
|
||||
if (session.server_id.empty())
|
||||
return;
|
||||
|
||||
session.server_id = std::string(response->begin(), response->end());
|
||||
}
|
||||
|
||||
session.EncryptID(Config::Get(Config::NETPLAY_INDEX_PASSWORD));
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/HttpRequest.h"
|
||||
#include "Core/NetPlayCommon.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/TraversalClient.h"
|
||||
|
||||
|
|
@ -550,17 +550,8 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
|||
|
||||
void NetPlayDialog::ResetExternalIP()
|
||||
{
|
||||
m_external_ip_address = Common::Lazy<std::string>([]() -> std::string {
|
||||
Common::HttpRequest request;
|
||||
// ENet does not support IPv6, so IPv4 has to be used
|
||||
request.UseIPv4();
|
||||
Common::HttpRequest::Response response =
|
||||
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
||||
|
||||
if (response.has_value())
|
||||
return std::string(response->begin(), response->end());
|
||||
return "";
|
||||
});
|
||||
m_external_ip_address =
|
||||
Common::Lazy<std::string>([]() -> std::string { return NetPlay::GetExternalIPAddress(); });
|
||||
}
|
||||
|
||||
void NetPlayDialog::UpdateDiscordPresence()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user