Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Core/HLE/proAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,6 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){
socklen_t addrLen = sizeof(LocalIP);
memset(&LocalIP, 0, addrLen);
getsockname((int)metasocket, &LocalIP, &addrLen);
g_OSD.Show(OSDType::MESSAGE_SUCCESS, n->T("Network initialized"), 1.0, "networkinit");
return 0;
} else {
return SOCKET_ERROR;
Expand Down
10 changes: 7 additions & 3 deletions Core/HLE/sceHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ static int sceHttpCreateRequest(int connectionID, int method, const char *path,
return hleLogSuccessI(Log::sceNet, retid);
}

// FIXME: port type is probably u16
// FIXME: port type is probably u16 (but passed in a single register anyway, so type doesn't matter)
static int sceHttpCreateConnection(int templateID, const char *hostString, const char *scheme, u32 port, int enableKeepalive) {
WARN_LOG(Log::sceNet, "UNTESTED sceHttpCreateConnection(%d, %s, %s, %d, %d)", templateID, safe_string(hostString), safe_string(scheme), port, enableKeepalive);
std::lock_guard<std::mutex> guard(httpLock);
Expand All @@ -588,6 +588,8 @@ static int sceHttpCreateConnection(int templateID, const char *hostString, const
if (httpObjects[templateID - 1LL]->className() != name_HTTPTemplate)
return hleLogError(Log::sceNet, SCE_HTTP_ERROR_INVALID_ID, "invalid id");

// TODO: Look up hostString in DNS here.
Copy link
Collaborator

@anr2me anr2me Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i remembered the hostString contains a full path used in request header, thus resolving here instead of the resolver at HTTPClient.cpp might not works properly on shared webhosting that use subdomain, since each subdomains might be pointed to the same IP and the server might be routing it to the correct server based on the subdomain string in the request header.

Reference: https://www.resellerspanel.com/articles/domain-names-articles/domains-subdomains/why-all-of-my-sites-use-the-same-ip/

Because the IP is shared by all the hosts (domains and subdomains), the visitors will not be able to reach a specific website by simply typing the IP address of the server in their browser's address bar. Instead, the visitors should type the domain name of your website. When the web browser requests an address from a web server from our network, it includes the requested hostname (domain or subdomain) as a part of the request. The server then uses this information to determine which website is being requested.

Then again i could be wrong :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good point...


httpObjects.emplace_back(std::make_shared<HTTPConnection>(templateID, hostString ? hostString : "", scheme ? scheme : "", port, enableKeepalive));
int retid = (int)httpObjects.size();
return hleLogSuccessI(Log::sceNet, retid);
Expand Down Expand Up @@ -742,7 +744,7 @@ static int sceHttpCreateRequestWithURL(int connectionID, int method, const char
if (!baseURL.Valid())
return hleLogError(Log::sceNet, SCE_HTTP_ERROR_INVALID_URL, "invalid url");

httpObjects.emplace_back(std::make_shared<HTTPRequest>(connectionID, method, url? url:"", contentLength));
httpObjects.emplace_back(std::make_shared<HTTPRequest>(connectionID, method, url ? url : "", contentLength));
int retid = (int)httpObjects.size();
return hleLogSuccessI(Log::sceNet, retid);
}
Expand All @@ -756,10 +758,12 @@ static int sceHttpCreateConnectionWithURL(int templateID, const char *url, int e
if (httpObjects[templateID - 1LL]->className() != name_HTTPTemplate)
return hleLogError(Log::sceNet, SCE_HTTP_ERROR_INVALID_ID, "invalid id");

Url baseURL(url? url: "");
Url baseURL(url ? url: "");
if (!baseURL.Valid())
return hleLogError(Log::sceNet, SCE_HTTP_ERROR_INVALID_URL, "invalid url");

// TODO: Here we should look up baseURL.Host() in DNS.

httpObjects.emplace_back(std::make_shared<HTTPConnection>(templateID, baseURL.Host().c_str(), baseURL.Protocol().c_str(), baseURL.Port(), enableKeepalive));
int retid = (int)httpObjects.size();
return hleLogSuccessI(Log::sceNet, retid);
Expand Down
64 changes: 45 additions & 19 deletions Core/HLE/sceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#include "Common/Net/Resolve.h"
#include "Common/Net/SocketCompat.h"
#include "Common/Data/Text/Parsers.h"
#include "Common/Data/Text/I18n.h"
#include "Common/File/VFS/VFS.h"

#include "Common/System/OSD.h"
#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"
Expand All @@ -40,18 +40,15 @@
#include "Core/Util/PortManager.h"
#include "Core/CoreTiming.h"
#include "Core/Instance.h"

#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelThread.h"
#include "Core/HLE/sceUtility.h"

#include "Core/HLE/sceNetAdhoc.h"
#include "Core/HLE/sceNetAdhocMatching.h"
#include "Core/HLE/sceNet.h"
#include "Core/HLE/sceNetApctl.h"
#include "Core/HLE/sceNp.h"
#include "Core/HLE/sceNp2.h"

#include "Core/HLE/sceNetInet.h"
#include "Core/HLE/sceNetResolver.h"

Expand Down Expand Up @@ -208,8 +205,7 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
continue;
}

std::string name = game.getStringOr("name", "");
std::string dyn_dns = game.getStringOr("dyn_dns", dns->dns.c_str());
dns->gameName = game.getStringOr("name", "");
dns->dns = game.getStringOr("dns", dns->dns.c_str());
dns->dyn_dns = game.getStringOr("dyn_dns", "");
if (game.hasChild("domains", JSON_OBJECT)) {
Expand Down Expand Up @@ -618,7 +614,8 @@ static inline void FreeUser(u32 &addr) {
}

u32 Net_Term() {
// May also need to Terminate netAdhocctl and netAdhoc to free some resources & threads, since the game (ie. GTA:VCS, Wipeout Pulse, etc) might not called them before calling sceNetTerm and causing them to behave strangely on the next sceNetInit & sceNetAdhocInit
// May also need to Terminate netAdhocctl and netAdhoc to free some resources & threads, since the game (ie. GTA:VCS, Wipeout Pulse, etc) might not have called
// them before calling sceNetTerm and causing them to behave strangely on the next sceNetInit & sceNetAdhocInit
NetAdhocctl_Term();
NetAdhocMatching_Term();
NetAdhoc_Term();
Expand Down Expand Up @@ -653,6 +650,9 @@ u32 Net_Term() {
}

static u32 sceNetTerm() {
auto n = GetI18NCategory(I18NCat::NETWORKING);
g_OSD.Show(OSDType::MESSAGE_INFO, n->T("Network shutdown"), 2.0, "networkinit");

WARN_LOG(Log::sceNet, "sceNetTerm() at %08x", currentMIPS->pc);
int retval = Net_Term();

Expand All @@ -673,8 +673,11 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
// TODO: Create Network Threads using given priority & stack
// TODO: The correct behavior is actually to allocate more and leak the other threads/pool.
// But we reset here for historic reasons (GTA:VCS potentially triggers this.)
if (netInited)
Net_Term(); // This cleanup attempt might not worked when SaveState were loaded in the middle of multiplayer game and re-entering multiplayer, thus causing memory leaks & wasting binded ports. May be we shouldn't save/load "Inited" vars on SaveState?
if (netInited) {
// This cleanup attempt might not worked when SaveState were loaded in the middle of multiplayer game and re-entering multiplayer, thus causing memory leaks & wasting binded ports.
// Maybe we shouldn't save/load "Inited" vars on SaveState?
Net_Term();
}

if (poolSize == 0) {
return hleLogError(Log::sceNet, SCE_KERNEL_ERROR_ILLEGAL_MEMSIZE, "invalid pool size");
Expand Down Expand Up @@ -756,6 +759,19 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
}

netInited = true;

auto n = GetI18NCategory(I18NCat::NETWORKING);

std::string msg(n->T("Network initialized"));
if (g_Config.bInfrastructureAutoDNS) {
msg += ": ";
msg += n->T("Auto DNS");
if (!g_infraDNSConfig.gameName.empty()) {
msg += " (" + g_infraDNSConfig.gameName + ")";
}
}

g_OSD.Show(OSDType::MESSAGE_INFO, msg, 2.0, "networkinit");
return hleLogSuccessI(Log::sceNet, 0);
}

Expand Down Expand Up @@ -893,8 +909,8 @@ void NetApctl_InitDefaultInfo() {
// Set dummy/fake parameters, assuming this is the currently selected Network Configuration profile
// FIXME: Some of these info supposed to be taken from netConfInfo
int validConfId = std::max(1, netApctlInfoId); // Should be: sceUtilityGetNetParamLatestID(validConfId);
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), (defaultNetConfigName + std::to_string(validConfId)).c_str());
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID.c_str());
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), defaultNetConfigName + std::to_string(validConfId));
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID);
// Default IP Address
char ipstr[INET_ADDRSTRLEN] = "0.0.0.0"; // Driver 76 needs a dot formatted IP instead of a zeroed buffer
truncate_cpy(netApctlInfo.ip, sizeof(netApctlInfo.ip), ipstr);
Expand All @@ -908,8 +924,8 @@ void NetApctl_InitInfo(int confId) {
memset(&netApctlInfo, 0, sizeof(netApctlInfo));
// 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?
// FIXME: Some of these info supposed to be taken from netConfInfo
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), (defaultNetConfigName + std::to_string(confId)).c_str());
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID.c_str());
truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), defaultNetConfigName + std::to_string(confId));
truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), defaultNetSSID);
memcpy(netApctlInfo.bssid, "\1\1\2\2\3\3", sizeof(netApctlInfo.bssid)); // fake AP's mac address
netApctlInfo.ssidLength = static_cast<unsigned int>(defaultNetSSID.length());
netApctlInfo.strength = 99;
Expand All @@ -925,12 +941,22 @@ void NetApctl_InitInfo(int confId) {
((u8*)&sockAddr.sin_addr.s_addr)[3] = 1;
inet_ntop(AF_INET, &sockAddr.sin_addr, ipstr, sizeof(ipstr));
truncate_cpy(netApctlInfo.gateway, sizeof(netApctlInfo.gateway), ipstr);
// 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)
//if (strcmp(ipstr, "127.0.0.1") == 0)
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_Config.sInfrastructureDNSServer.c_str()); // Private Servers may need to use custom DNS Server
//else
// truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), ipstr);

// We use the configured DNS server, whether manually or auto configured.
// Games (for example, Wipeout Pulse) often use this to perform their own DNS lookups through UDP, so we need to pass in the configured server.
// The reason we need autoconfig is that private Servers may need to use custom DNS Server - and most games are now
// best played on private servers (only a few official ones remain, if any).
if (g_Config.bInfrastructureAutoDNS) {
INFO_LOG(Log::sceNet, "Responding to game query with AutoDNS address");
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_infraDNSConfig.dns);
} else {
INFO_LOG(Log::sceNet, "Responding to game query with manual DNS address");
truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), g_Config.sInfrastructureDNSServer);
}

// We don't bother with a secondary DNS.
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

truncate_cpy(netApctlInfo.subNetMask, sizeof(netApctlInfo.subNetMask), "255.255.255.0");
}

Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceNetAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
if (isLocalMAC(maddr)) {
SceNetAdhocctlNickname nickname;

truncate_cpy((char*)&nickname.data, ADHOCCTL_NICKNAME_LEN, g_Config.sNickName.c_str());
truncate_cpy((char*)&nickname.data, ADHOCCTL_NICKNAME_LEN, g_Config.sNickName);
buf->next = 0;
buf->nickname = nickname;
buf->nickname.data[ADHOCCTL_NICKNAME_LEN - 1] = 0; // last char need to be null-terminated char
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceNp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static int sceNpGetUserProfile(u32 profilePtr)

profile.FillWithZero();
strncpy(profile->userId.handle.data, npOnlineId.c_str(), sizeof(profile->userId.handle.data));
truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl.c_str());
truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl);

INFO_LOG(Log::sceNet, "%s - Online ID: %s", __FUNCTION__, profile->userId.handle.data);
std::string datahex;
Expand Down
4 changes: 2 additions & 2 deletions Core/HLE/sceUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ static int sceUtilityGetNetParam(int id, int param, u32 dataAddr) {

// 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
char name[APCTL_PROFILENAME_MAXLEN];
truncate_cpy(name, sizeof(name), (defaultNetConfigName + std::to_string(id == 0 ? netParamLatestId:id)).c_str());
truncate_cpy(name, sizeof(name), defaultNetConfigName + std::to_string(id == 0 ? netParamLatestId:id));
char dummyWEPKey[6] = "XXXXX"; // WEP 64-bit = 10 hex digits key or 5-digit ASCII equivalent
char dummyUserPass[256] = "PPSSPP"; // FIXME: Username / Password max length = 255 chars?
char dummyWPAKey[64] = "XXXXXXXX"; // FIXME: WPA 256-bit = 64 hex digits key or 8 to 63-chars ASCII passphrases?
Expand Down Expand Up @@ -811,7 +811,7 @@ static int sceUtilityGetNetParam(int id, int param, u32 dataAddr) {
break;
case PSP_NETPARAM_MANUAL_DNS:
// 0 is auto.
// 1 is manual.
// 1 is manual. We always use manual.
if (!Memory::IsValidRange(dataAddr, 4))
return hleLogError(Log::sceNet, -1, "invalid arg");
Memory::WriteUnchecked_U32(1, dataAddr); // manual
Expand Down
Loading