Skip to content

Commit 0349f91

Browse files
committed
Add "dyndns" or DNS server lookup by domain name as requested by ablondel.
JSON updated.
1 parent ae15cba commit 0349f91

File tree

3 files changed

+89
-7
lines changed

3 files changed

+89
-7
lines changed

Core/HLE/sceNet.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "Common/Serialize/Serializer.h"
2727
#include "Common/Serialize/SerializeFuncs.h"
2828
#include "Common/Serialize/SerializeMap.h"
29+
#include "Common/System/OSD.h"
2930
#include "Common/Data/Format/JSONReader.h"
3031
#include "Core/HLE/HLE.h"
3132
#include "Core/HLE/FunctionWrappers.h"
@@ -208,8 +209,9 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
208209
}
209210

210211
std::string name = game.getStringOr("name", "");
212+
std::string dyn_dns = game.getStringOr("dyn_dns", dns->dns.c_str());
211213
dns->dns = game.getStringOr("dns", dns->dns.c_str());
212-
214+
dns->dyn_dns = game.getStringOr("dyn_dns", "");
213215
if (game.hasChild("domains", JSON_OBJECT)) {
214216
const JsonGet domains = game.getDict("domains");
215217
for (auto iter : domains.value_) {
@@ -712,9 +714,45 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
712714
memset(&adhocSockets, 0, sizeof(adhocSockets));
713715

714716
if (g_Config.bInfrastructureAutoDNS) {
715-
// Load the automatic DNS config.
717+
// Load the automatic DNS config for this game - or the defaults.
716718
std::string discID = g_paramSFO.GetDiscID();
717719
LoadDNSForGameID(discID, &g_infraDNSConfig);
720+
721+
// If dyn_dns is non-empty, try to use it to replace the specified DNS.
722+
// If fails, we just use the dns. TODO: Do this in the background somehow...
723+
const auto &dns = g_infraDNSConfig.dns;
724+
const auto &dyn_dns = g_infraDNSConfig.dyn_dns;
725+
if (!dyn_dns.empty()) {
726+
// Try to look it up in system DNS
727+
INFO_LOG(Log::sceNet, "DynDNS requested, trying to resolve '%s'...", dyn_dns.c_str());
728+
addrinfo *resolved = nullptr;
729+
std::string err;
730+
if (!net::DNSResolve(dyn_dns, "", &resolved, err)) {
731+
ERROR_LOG(Log::sceNet, "Error resolving, falling back to '%s'", dns.c_str());
732+
} else if (resolved) {
733+
bool found = false;
734+
for (auto ptr = resolved; ptr && !found; ptr = ptr->ai_next) {
735+
switch (ptr->ai_family) {
736+
case AF_INET:
737+
{
738+
char ipstr[256];
739+
if (inet_ntop(ptr->ai_family, &(((struct sockaddr_in*)ptr->ai_addr)->sin_addr), ipstr, sizeof(ipstr)) != 0) {
740+
INFO_LOG(Log::sceNet, "Successfully resolved '%s' to '%s', overriding DNS.", dyn_dns.c_str(), ipstr);
741+
if (g_infraDNSConfig.dns != ipstr) {
742+
WARN_LOG(Log::sceNet, "Replacing specified DNS IP %s with dyndns %s!", g_infraDNSConfig.dns.c_str(), ipstr);
743+
g_infraDNSConfig.dns = ipstr;
744+
} else {
745+
INFO_LOG(Log::sceNet, "DynDNS: %s already up to date", g_infraDNSConfig.dns.c_str());
746+
}
747+
found = true;
748+
}
749+
break;
750+
}
751+
}
752+
}
753+
net::DNSResolveFree(resolved);
754+
}
755+
}
718756
}
719757

720758
netInited = true;

Core/HLE/sceNet.h

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ enum class InfraGameState {
140140
struct InfraDNSConfig {
141141
std::string gameName;
142142
std::string dns;
143+
std::string dyn_dns;
143144
InfraGameState state;
144145
std::map<std::string, std::string> fixedDNS;
145146
int score;

assets/infra-dns.json

+48-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
"group": "MOHH Revival",
1818
"url": "https://mohh-revival.pages.dev/"
1919
},
20-
"credit": "AG ",
2120
"dns": "86.223.243.173",
21+
"dyn_dns": "ablondel.ddns.net",
2222
"domains": {
2323
"pspmoh07.ea.com": "86.223.243.173",
24-
"pspmoh08.ea.com": "86.223.243.173",
2524
"tos.ea.com": "86.223.243.173"
2625
},
2726
"score": 5,
@@ -40,9 +39,53 @@
4039
"ULUS10141",
4140
"NPJH50306"
4241
],
43-
"not_working_platforms": [
44-
"Windows"
42+
},
43+
{
44+
"name": "Medal of Honor 2",
45+
"comment": {
46+
"en_US": "Only the menu works!"
47+
},
48+
"revival_credits": {
49+
"group": "MOHH Revival",
50+
"url": "https://mohh-revival.pages.dev/"
51+
},
52+
"dns": "86.223.243.173",
53+
"dyn_dns": "ablondel.ddns.net",
54+
"domains": {
55+
"pspmoh08.ea.com": "86.223.243.173",
56+
"tos.ea.com": "86.223.243.173"
57+
},
58+
"score": 1,
59+
"known_working_ids": [
60+
"ULUS10310",
61+
"ULES00955",
62+
"ULES00956",
63+
"ULES00988"
4564
],
65+
"not_working_ids": [
66+
"ULJM05301",
67+
]
68+
},
69+
{
70+
"name": "Wipeout Pure",
71+
"comment": {
72+
"en_US": "Web browser only, no multiplayer"
73+
},
74+
"revival_credits": {
75+
"group": "The AG Racing Foundation",
76+
"url": "https://agracingfoundation.org/"
77+
},
78+
"dns": "145.239.30.230",
79+
"domains": {
80+
"hub.psnexus.net": "145.239.30.230",
81+
},
82+
"other_ids": [
83+
"UCUS98612",
84+
"UCJS10007",
85+
"UCES00001",
86+
"UCKS45008",
87+
"NPJG00059"
88+
]
4689
},
4790
{
4891
"name": "Wipeout Pulse",
@@ -79,7 +122,7 @@
79122
"known_working_ids": [
80123
"UCES01250",
81124
"UCUS98743",
82-
"UCJS10104",
125+
"UCJS10104"
83126
],
84127
"not_working_ids": [],
85128
"other_ids": [

0 commit comments

Comments
 (0)