Skip to content

Commit 28d8fae

Browse files
committed
Integrate the sceUtility DNS query with the auto conf system, minor cleanups
1 parent c22c4b7 commit 28d8fae

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

Core/HLE/sceNet.cpp

+31-12
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
205205
continue;
206206
}
207207

208-
std::string name = game.getStringOr("name", "");
209-
std::string dyn_dns = game.getStringOr("dyn_dns", dns->dns.c_str());
208+
dns->gameName = game.getStringOr("name", "");
210209
dns->dns = game.getStringOr("dns", dns->dns.c_str());
211210
dns->dyn_dns = game.getStringOr("dyn_dns", "");
212211
if (game.hasChild("domains", JSON_OBJECT)) {
@@ -762,7 +761,17 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
762761
netInited = true;
763762

764763
auto n = GetI18NCategory(I18NCat::NETWORKING);
765-
g_OSD.Show(OSDType::MESSAGE_INFO, n->T("Network initialized"), 2.0, "networkinit");
764+
765+
std::string msg(n->T("Network initialized"));
766+
if (g_Config.bInfrastructureAutoDNS) {
767+
msg += ": ";
768+
msg += n->T("Auto DNS");
769+
if (!g_infraDNSConfig.gameName.empty()) {
770+
msg += " (" + g_infraDNSConfig.gameName + ")";
771+
}
772+
}
773+
774+
g_OSD.Show(OSDType::MESSAGE_INFO, msg, 2.0, "networkinit");
766775
return hleLogSuccessI(Log::sceNet, 0);
767776
}
768777

@@ -900,8 +909,8 @@ void NetApctl_InitDefaultInfo() {
900909
// Set dummy/fake parameters, assuming this is the currently selected Network Configuration profile
901910
// FIXME: Some of these info supposed to be taken from netConfInfo
902911
int validConfId = std::max(1, netApctlInfoId); // Should be: sceUtilityGetNetParamLatestID(validConfId);
903-
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), (defaultNetConfigName + std::to_string(validConfId)).c_str());
904-
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID.c_str());
912+
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), defaultNetConfigName + std::to_string(validConfId));
913+
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID);
905914
// Default IP Address
906915
char ipstr[INET_ADDRSTRLEN] = "0.0.0.0"; // Driver 76 needs a dot formatted IP instead of a zeroed buffer
907916
truncate_cpy(netApctlInfo.ip, sizeof(netApctlInfo.ip), ipstr);
@@ -915,8 +924,8 @@ void NetApctl_InitInfo(int confId) {
915924
memset(&netApctlInfo, 0, sizeof(netApctlInfo));
916925
// Set dummy/fake values, some of these (ie. IP set to Auto) probably not suppose to have valid info before connected to an AP, right?
917926
// FIXME: Some of these info supposed to be taken from netConfInfo
918-
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), (defaultNetConfigName + std::to_string(confId)).c_str());
919-
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID.c_str());
927+
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), defaultNetConfigName + std::to_string(confId));
928+
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID);
920929
memcpy(netApctlInfo.bssid, "\1\1\2\2\3\3", sizeof(netApctlInfo.bssid)); // fake AP's mac address
921930
netApctlInfo.ssidLength = static_cast<unsigned int>(defaultNetSSID.length());
922931
netApctlInfo.strength = 99;
@@ -932,12 +941,22 @@ void NetApctl_InitInfo(int confId) {
932941
((u8*)&sockAddr.sin_addr.s_addr)[3] = 1;
933942
inet_ntop(AF_INET, &sockAddr.sin_addr, ipstr, sizeof(ipstr));
934943
truncate_cpy(netApctlInfo.gateway, sizeof(netApctlInfo.gateway), ipstr);
935-
// We should probably use public DNS Server instead of localhost IP since most people don't have DNS Server running on localhost (ie. Untold Legends The Warrior's Code is trying to lookup dns using the primary dns), but accessing public DNS Server from localhost may result to ENETUNREACH error if the gateway can't access the public server (ie. using SO_DONTROUTE)
936-
//if (strcmp(ipstr, "127.0.0.1") == 0)
937-
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_Config.sInfrastructureDNSServer.c_str()); // Private Servers may need to use custom DNS Server
938-
//else
939-
// truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), ipstr);
944+
945+
// We use the configured DNS server, whether manually or auto configured.
946+
// Games often use this to perform their own DNS lookups through tcp/ip, so we need to pass in the configured server.
947+
// The reason we need autoconfig is that private Servers may need to use custom DNS Server - and most games are now
948+
// best played on private servers (only a few official ones remain, if any).
949+
if (g_Config.bInfrastructureAutoDNS) {
950+
INFO_LOG(Log::sceNet, "Responding to game query with AutoDNS address");
951+
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_infraDNSConfig.dns);
952+
} else {
953+
INFO_LOG(Log::sceNet, "Responding to game query with manual DNS address");
954+
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_Config.sInfrastructureDNSServer);
955+
}
956+
957+
// We don't bother with a secondary DNS.
940958
truncate_cpy(netApctlInfo.secondaryDns, sizeof(netApctlInfo.secondaryDns), "0.0.0.0"); // Fireteam Bravo 2 seems to try to use secondary DNS too if it's not 0.0.0.0
959+
941960
truncate_cpy(netApctlInfo.subNetMask, sizeof(netApctlInfo.subNetMask), "255.255.255.0");
942961
}
943962

Core/HLE/sceNetAdhoc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
27032703
if (isLocalMAC(maddr)) {
27042704
SceNetAdhocctlNickname nickname;
27052705

2706-
truncate_cpy((char*)&nickname.data, ADHOCCTL_NICKNAME_LEN, g_Config.sNickName.c_str());
2706+
truncate_cpy((char*)&nickname.data, ADHOCCTL_NICKNAME_LEN, g_Config.sNickName);
27072707
buf->next = 0;
27082708
buf->nickname = nickname;
27092709
buf->nickname.data[ADHOCCTL_NICKNAME_LEN - 1] = 0; // last char need to be null-terminated char

Core/HLE/sceNp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int sceNpGetUserProfile(u32 profilePtr)
285285

286286
profile.FillWithZero();
287287
strncpy(profile->userId.handle.data, npOnlineId.c_str(), sizeof(profile->userId.handle.data));
288-
truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl.c_str());
288+
truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl);
289289

290290
INFO_LOG(Log::sceNet, "%s - Online ID: %s", __FUNCTION__, profile->userId.handle.data);
291291
std::string datahex;

Core/HLE/sceUtility.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ static int sceUtilityGetNetParam(int id, int param, u32 dataAddr) {
745745

746746
// TODO: Replace the temporary netApctlInfo with netConfInfo, since some of netApctlInfo contents supposed to be taken from netConfInfo during ApctlInit, while sceUtilityGetNetParam can be used before Apctl Initialized
747747
char name[APCTL_PROFILENAME_MAXLEN];
748-
truncate_cpy(name, sizeof(name), (defaultNetConfigName + std::to_string(id == 0 ? netParamLatestId:id)).c_str());
748+
truncate_cpy(name, sizeof(name), defaultNetConfigName + std::to_string(id == 0 ? netParamLatestId:id));
749749
char dummyWEPKey[6] = "XXXXX"; // WEP 64-bit = 10 hex digits key or 5-digit ASCII equivalent
750750
char dummyUserPass[256] = "PPSSPP"; // FIXME: Username / Password max length = 255 chars?
751751
char dummyWPAKey[64] = "XXXXXXXX"; // FIXME: WPA 256-bit = 64 hex digits key or 8 to 63-chars ASCII passphrases?
@@ -811,7 +811,7 @@ static int sceUtilityGetNetParam(int id, int param, u32 dataAddr) {
811811
break;
812812
case PSP_NETPARAM_MANUAL_DNS:
813813
// 0 is auto.
814-
// 1 is manual.
814+
// 1 is manual. We always use manual.
815815
if (!Memory::IsValidRange(dataAddr, 4))
816816
return hleLogError(Log::sceNet, -1, "invalid arg");
817817
Memory::WriteUnchecked_U32(1, dataAddr); // manual

0 commit comments

Comments
 (0)