Finish the format, actually use the things from it

This commit is contained in:
Henrik Rydgård 2025-01-11 19:38:29 +01:00
parent 608ff2ff39
commit 05906bc8f3
4 changed files with 107 additions and 71 deletions

View file

@ -200,7 +200,14 @@ bool LoadDNSForGameID(std::string_view jsonStr, std::string_view gameID, InfraDN
std::string name = game.getStringOr("name", "");
dns->dns = game.getStringOr("dns", dns->dns.c_str());
// const JsonGet domains = game.getDict("domains");
if (game.hasChild("domains", JSON_OBJECT)) {
const JsonGet domains = game.getDict("domains");
for (auto iter : domains.value_) {
std::string domain = std::string(iter->key);
std::string ipAddr = std::string(iter->value.toString());
dns->fixedDNS[domain] = ipAddr;
}
}
// TODO: Check for not working platforms
@ -305,15 +312,6 @@ void __NetCallbackInit() {
}
void __NetInit() {
// Load the DNS config.
std::string discID = g_paramSFO.GetDiscID();
size_t jsonSize;
uint8_t *data = g_VFS.ReadFile("infra-dns.json", &jsonSize);
if (data && g_Config.bInfrastructureAutoDNS) {
std::string_view json = std::string_view((const char *)data, jsonSize);
LoadDNSForGameID(json, discID, &g_infraDNSConfig);
}
// Windows: Assuming WSAStartup already called beforehand
portOffset = g_Config.iPortOffset;
isOriPort = g_Config.bEnableUPnP && g_Config.bUPnPUseOriginalPort;
@ -703,6 +701,17 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
// Clear Socket Translator Memory
memset(&adhocSockets, 0, sizeof(adhocSockets));
if (g_Config.bInfrastructureAutoDNS) {
// Load the automatic DNS config.
std::string discID = g_paramSFO.GetDiscID();
size_t jsonSize;
uint8_t *data = g_VFS.ReadFile("infra-dns.json", &jsonSize);
if (data && g_Config.bInfrastructureAutoDNS) {
std::string_view json = std::string_view((const char *)data, jsonSize);
LoadDNSForGameID(json, discID, &g_infraDNSConfig);
}
}
netInited = true;
return hleLogSuccessI(Log::sceNet, 0);
}

View file

@ -88,15 +88,26 @@ int NetResolver_StartNtoA(u32 resolverId, u32 hostnamePtr, u32 inAddrPtr, int ti
SockAddrIN4 addr{};
addr.in.sin_addr.s_addr = INADDR_NONE;
// Resolve any aliases
if (g_Config.mHostToAlias.find(hostname) != g_Config.mHostToAlias.end()) {
const std::string& alias = g_Config.mHostToAlias[hostname];
// Resolve any aliases. First check the ini file, then check the hardcoded DNS config.
auto aliasIter = g_Config.mHostToAlias.find(hostname);
if (aliasIter != g_Config.mHostToAlias.end()) {
const std::string& alias = aliasIter->second;
INFO_LOG(Log::sceNet, "%s - Resolved alias %s from hostname %s", __FUNCTION__, alias.c_str(), hostname.c_str());
hostname = alias;
}
if (g_Config.bInfrastructureAutoDNS) {
// Also look up into the preconfigured fixed DNS JSON.
auto fixedDNSIter = g_infraDNSConfig.fixedDNS.find(hostname);
if (fixedDNSIter != g_infraDNSConfig.fixedDNS.end()) {
const std::string& domainIP = fixedDNSIter->second;
INFO_LOG(Log::sceNet, "%s - Resolved IP %s from fixed DNS lookup with '%s'", __FUNCTION__, domainIP.c_str(), hostname.c_str());
hostname = domainIP;
}
}
// Check if hostname is already an IPv4 address, if so we do not need further lookup. This usually happens
// after the mHostToAlias lookup, which effectively is hardcoded DNS.
// after the mHostToAlias or fixedDNSIter lookups, which effectively both are hardcoded DNS.
uint32_t resolvedAddr;
if (inet_pton(AF_INET, hostname.c_str(), &resolvedAddr)) {
INFO_LOG(Log::sceNet, "Not looking up '%s', already an IP address.", hostname.c_str());
@ -108,9 +119,10 @@ int NetResolver_StartNtoA(u32 resolverId, u32 hostnamePtr, u32 inAddrPtr, int ti
resolver->SetIsRunning(true);
// Now use the configured primary DNS server to do a lookup.
// TODO: Pick a DNS server per-game according to a table downloaded from ppsspp.org.
if (net::DirectDNSLookupIPV4(g_Config.sInfrastructureDNSServer.c_str(), hostname.c_str(), &resolvedAddr)) {
INFO_LOG(Log::sceNet, "Direct lookup of '%s' succeeded: %08x", hostname.c_str(), resolvedAddr);
// If auto DNS, use the server from that config.
const std::string &dnsServer = (g_Config.bInfrastructureAutoDNS && !g_infraDNSConfig.dns.empty()) ? g_infraDNSConfig.dns : g_Config.sInfrastructureDNSServer;
if (net::DirectDNSLookupIPV4(dnsServer.c_str(), hostname.c_str(), &resolvedAddr)) {
INFO_LOG(Log::sceNet, "Direct lookup of '%s' from '%s' succeeded: %08x", hostname.c_str(), dnsServer.c_str(), resolvedAddr);
resolver->SetIsRunning(false);
Memory::Write_U32(resolvedAddr, inAddrPtr);
return 0;

View file

@ -953,8 +953,8 @@ void GameSettingsScreen::CreateNetworkingSettings(UI::ViewGroup *networkingSetti
networkingSettings->Add(new CheckBox(&g_Config.bInfrastructureAutoDNS, "Auto DNS"));
networkingSettings->Add(new PopupTextInputChoice(GetRequesterToken(), &g_Config.sInfrastructureDNSServer, n->T("DNS server"), "", 32, screenManager()));
networkingSettings->SetDisabledPtr(&g_Config.bInfrastructureAutoDNS);
auto *dnsServer = networkingSettings->Add(new PopupTextInputChoice(GetRequesterToken(), &g_Config.sInfrastructureDNSServer, n->T("DNS server"), "", 32, screenManager()));
dnsServer->SetDisabledPtr(&g_Config.bInfrastructureAutoDNS);
networkingSettings->Add(new ItemHeader(n->T("Chat")));
networkingSettings->Add(new CheckBox(&g_Config.bEnableNetworkChat, n->T("Enable network chat", "Enable network chat")));

View file

@ -3,58 +3,73 @@
"default": {
"dns": "67.222.156.251",
},
"Medal of Honor: Heroes": {
"comment": {
"en_US": "Works, but not on Windows",
"games": [
{
"name": "Medal of Honor: Heroes",
"comment": {
"en_US": "Works, but not on Windows",
},
"dns": "86.223.243.173",
"domains": {
"pspmoh07.ea.com": "86.223.243.173",
"pspmoh08.ea.com": "86.223.243.173",
"tos.ea.com": "86.223.243.173"
},
"score": 5,
"known_working_ids": [
"ULES00557",
"ULES00558",
"ULES00559",
"ULES00560",
"ULES00561",
"ULES00562"
],
"not_working_ids": [],
"other_ids": [
"ULUS10141",
"ULJM05213",
"ULUS10141",
"NPJH50306"
],
"not_working_platforms": [
"Windows"
],
},
"dns": "142.24.13.25",
"score": 5,
"known_working_ids": [
"ULES00557"
],
"not_working_ids": [],
"other_ids": [
"ULUS10141",
"ULJM05213",
"ULUS-10141",
"NPJH50306"
],
"not_working_platforms": [
"Windows"
],
},
"Wipeout Pulse": {
"comment": {
"en_US": "Great",
{
"name": "Wipeout Pulse",
"comment": {
"en_US": "Great",
},
"dns": "145.239.30.230",
"score": 5,
"known_working_ids": [
"UCES00465",
"UCUS98712"
],
"not_working_ids": [],
"other_ids": [
"UCKS45078"
],
"not_working_platforms": [],
},
"dns": "145.239.30.230",
"score": 5,
"known_working_ids": [
"UCES00465",
"UCUS98712"
],
"not_working_ids": [],
"other_ids": [
"UCKS45078"
],
"not_working_platforms": [],
},
"Motorstorm: Artic Edge": {
"comment": {
"en_US": "Works",
},
"dns": "145.239.30.230",
"score": 5,
"known_working_ids": [
"UCES01250",
],
"not_working_ids": [],
"other_ids": [
"UCAS40266",
"UCUS98743",
"UCKS45124",
"UCJS10104",
"NPJG00047"
],
}
{
"name": "Motorstorm: Artic Edge",
"comment": {
"en_US": "Works",
},
"dns": "145.239.30.230",
"score": 5,
"known_working_ids": [
"UCES01250",
],
"not_working_ids": [],
"other_ids": [
"UCAS40266",
"UCUS98743",
"UCKS45124",
"UCJS10104",
"NPJG00047"
],
}
]
}