Add "dyndns" or DNS server lookup by domain name as requested by ablondel.

JSON updated.
This commit is contained in:
Henrik Rydgård 2025-01-12 17:55:42 +01:00
parent ae15cba56c
commit 0349f91a9e
3 changed files with 89 additions and 7 deletions

View file

@ -26,6 +26,7 @@
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
#include "Common/Serialize/SerializeMap.h"
#include "Common/System/OSD.h"
#include "Common/Data/Format/JSONReader.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
@ -208,8 +209,9 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
}
std::string name = game.getStringOr("name", "");
std::string dyn_dns = game.getStringOr("dyn_dns", dns->dns.c_str());
dns->dns = game.getStringOr("dns", dns->dns.c_str());
dns->dyn_dns = game.getStringOr("dyn_dns", "");
if (game.hasChild("domains", JSON_OBJECT)) {
const JsonGet domains = game.getDict("domains");
for (auto iter : domains.value_) {
@ -712,9 +714,45 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
memset(&adhocSockets, 0, sizeof(adhocSockets));
if (g_Config.bInfrastructureAutoDNS) {
// Load the automatic DNS config.
// Load the automatic DNS config for this game - or the defaults.
std::string discID = g_paramSFO.GetDiscID();
LoadDNSForGameID(discID, &g_infraDNSConfig);
// If dyn_dns is non-empty, try to use it to replace the specified DNS.
// If fails, we just use the dns. TODO: Do this in the background somehow...
const auto &dns = g_infraDNSConfig.dns;
const auto &dyn_dns = g_infraDNSConfig.dyn_dns;
if (!dyn_dns.empty()) {
// Try to look it up in system DNS
INFO_LOG(Log::sceNet, "DynDNS requested, trying to resolve '%s'...", dyn_dns.c_str());
addrinfo *resolved = nullptr;
std::string err;
if (!net::DNSResolve(dyn_dns, "", &resolved, err)) {
ERROR_LOG(Log::sceNet, "Error resolving, falling back to '%s'", dns.c_str());
} else if (resolved) {
bool found = false;
for (auto ptr = resolved; ptr && !found; ptr = ptr->ai_next) {
switch (ptr->ai_family) {
case AF_INET:
{
char ipstr[256];
if (inet_ntop(ptr->ai_family, &(((struct sockaddr_in*)ptr->ai_addr)->sin_addr), ipstr, sizeof(ipstr)) != 0) {
INFO_LOG(Log::sceNet, "Successfully resolved '%s' to '%s', overriding DNS.", dyn_dns.c_str(), ipstr);
if (g_infraDNSConfig.dns != ipstr) {
WARN_LOG(Log::sceNet, "Replacing specified DNS IP %s with dyndns %s!", g_infraDNSConfig.dns.c_str(), ipstr);
g_infraDNSConfig.dns = ipstr;
} else {
INFO_LOG(Log::sceNet, "DynDNS: %s already up to date", g_infraDNSConfig.dns.c_str());
}
found = true;
}
break;
}
}
}
net::DNSResolveFree(resolved);
}
}
}
netInited = true;

View file

@ -140,6 +140,7 @@ enum class InfraGameState {
struct InfraDNSConfig {
std::string gameName;
std::string dns;
std::string dyn_dns;
InfraGameState state;
std::map<std::string, std::string> fixedDNS;
int score;

View file

@ -17,11 +17,10 @@
"group": "MOHH Revival",
"url": "https://mohh-revival.pages.dev/"
},
"credit": "AG ",
"dns": "86.223.243.173",
"dyn_dns": "ablondel.ddns.net",
"domains": {
"pspmoh07.ea.com": "86.223.243.173",
"pspmoh08.ea.com": "86.223.243.173",
"tos.ea.com": "86.223.243.173"
},
"score": 5,
@ -40,9 +39,53 @@
"ULUS10141",
"NPJH50306"
],
"not_working_platforms": [
"Windows"
},
{
"name": "Medal of Honor 2",
"comment": {
"en_US": "Only the menu works!"
},
"revival_credits": {
"group": "MOHH Revival",
"url": "https://mohh-revival.pages.dev/"
},
"dns": "86.223.243.173",
"dyn_dns": "ablondel.ddns.net",
"domains": {
"pspmoh08.ea.com": "86.223.243.173",
"tos.ea.com": "86.223.243.173"
},
"score": 1,
"known_working_ids": [
"ULUS10310",
"ULES00955",
"ULES00956",
"ULES00988"
],
"not_working_ids": [
"ULJM05301",
]
},
{
"name": "Wipeout Pure",
"comment": {
"en_US": "Web browser only, no multiplayer"
},
"revival_credits": {
"group": "The AG Racing Foundation",
"url": "https://agracingfoundation.org/"
},
"dns": "145.239.30.230",
"domains": {
"hub.psnexus.net": "145.239.30.230",
},
"other_ids": [
"UCUS98612",
"UCJS10007",
"UCES00001",
"UCKS45008",
"NPJG00059"
]
},
{
"name": "Wipeout Pulse",
@ -79,7 +122,7 @@
"known_working_ids": [
"UCES01250",
"UCUS98743",
"UCJS10104",
"UCJS10104"
],
"not_working_ids": [],
"other_ids": [