From 6d3607341330b6264de97224f99c39eb57219c0c Mon Sep 17 00:00:00 2001 From: cy33hc Date: Sun, 31 May 2026 02:24:31 -0700 Subject: [PATCH] handle proper loading of ezremote server payload --- ps4-ezremote-server | 2 +- source/installer.cpp | 71 +++++++++++++++++++++++++++++++++++++++++--- source/installer.h | 1 + source/lang.cpp | 2 +- source/main.cpp | 5 +++- source/orbis_jbc.c | 2 -- source/windows.cpp | 2 -- 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/ps4-ezremote-server b/ps4-ezremote-server index 81533f5..2c38d24 160000 --- a/ps4-ezremote-server +++ b/ps4-ezremote-server @@ -1 +1 @@ -Subproject commit 81533f5a28be906d65467721822c3fd86e49f504 +Subproject commit 2c38d24f2ef1a3ffed92fe39ac68d0817902fd99 diff --git a/source/installer.cpp b/source/installer.cpp index 9889c42..be96555 100644 --- a/source/installer.cpp +++ b/source/installer.cpp @@ -1238,6 +1238,9 @@ namespace INSTALLER std::string EzRemoteServerVersion() { + if (!IsPortOpen("127.0.0.1", 6701, 1)) + return ""; + httplib::Client tmp_client = httplib::Client("http://127.0.0.1:6701"); tmp_client.set_connection_timeout(1); @@ -1253,6 +1256,68 @@ namespace INSTALLER return ""; } + bool IsPortOpen(const char *ip, uint16_t port, int timeout_sec) + { + int sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) + return 0; + + // Set socket to non-blocking mode + int flags = fcntl(sockfd, F_GETFL, 0); + fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); + + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + inet_pton(AF_INET, ip, &addr.sin_addr); + + // Attempt connection + int res = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)); + + if (res < 0) + { + if (errno == EINPROGRESS) + { + // Wait for connection completion using select() + fd_set write_fds; + struct timeval timeout; + + FD_ZERO(&write_fds); + FD_SET(sockfd, &write_fds); + + timeout.tv_sec = timeout_sec; + timeout.tv_usec = 0; + + res = select(sockfd + 1, NULL, &write_fds, NULL, &timeout); + + if (res > 0) + { + // Check if connection succeeded or failed with an error + int so_error; + socklen_t len = sizeof(so_error); + getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &so_error, &len); + + if (so_error == 0) + { + // Port is open! Clean up and return success + close(sockfd); + return 1; + } + } + } + } + else + { + // Connected instantly (e.g., local loopback) + close(sockfd); + return 1; + } + + close(sockfd); + return 0; // Port is closed or timed out + } + int StartEzRemoteServer() { char buffer[8192]; @@ -1266,13 +1331,11 @@ namespace INSTALLER struct sockaddr_in sockaddr_in; unsigned short server_port = 9090; - /* - if (EzRemoteServerVersion().empty()) + if (IsPortOpen("127.0.0.1", 6701, 1)) { return 0; } - */ - + filefd = open(SERVER_ELF_PATH, O_RDONLY); if (filefd == -1) { diff --git a/source/installer.h b/source/installer.h index 213c384..d25538c 100644 --- a/source/installer.h +++ b/source/installer.h @@ -171,4 +171,5 @@ namespace INSTALLER std::string StoreBgInstallHostData(RemoteSettings *remote_settings, const std::string &path); RemoteClient *GetRemoteClient(int site_idx); RemoteClient *GetRemoteClient(RemoteSettings *settings); + bool IsPortOpen(const char *ip, uint16_t port, int timeout_sec); } diff --git a/source/lang.cpp b/source/lang.cpp index 2b7dc3d..c831bfa 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -183,7 +183,7 @@ char lang_strings[LANG_STRINGS_NUM][LANG_STR_SIZE] = { "Stop Server", // STR_STOP_SERVER "Warning", // STR_WARNING "The version of ezRemote Server payload running does not match the required version needed by ezRemote Client.", // STR_WARNING_MSG_1 - "If you are using an auto payload loader, then update the elf that comes with ezRemoteClient package.", // STR_WARNING_MSG_2 + "If you are using Goldhen payload loader, then update the elf that comes with ezRemoteClient package.", // STR_WARNING_MSG_2 "You may goto the Global Settings and restart ezRemote Server with the version that came packaged.", // STR_WARNING_MSG_3 "Enable background download", // STR_ENABLE_BG_DOWNLOAD "Minimum background file size (bytes)", // STR_BG_DOWNLOAD_MIN_SIZE diff --git a/source/main.cpp b/source/main.cpp index 091dcec..e1ff446 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -329,7 +329,10 @@ int main() atexit(terminate); HttpServer::Start(); - INSTALLER::StartEzRemoteServer(); + if (INSTALLER::StartEzRemoteServer() < 0) + { + Util::Notify("Cloud not load ezRemote Server. It is needed for background install and download. Please ensure Bin loader is enabled"); + } GUI::RenderLoop(renderer); SDL_DestroyRenderer(renderer); diff --git a/source/orbis_jbc.c b/source/orbis_jbc.c index 9c546fa..508e195 100644 --- a/source/orbis_jbc.c +++ b/source/orbis_jbc.c @@ -62,13 +62,11 @@ int mount_large_fs(const char* device, const char* mountpoint, const char* fstyp build_iovec(&iov, &iovlen, "mask", mode, -1); } - dbglogger_log("##^ [I] Mounting %s \"%s\" to \"%s\"", fstype, device, mountpoint); ret = nmount(iov, iovlen, flags); if (ret < 0) { goto error; } else { - dbglogger_log("##^ [I] Success."); } error: diff --git a/source/windows.cpp b/source/windows.cpp index 8217299..df5031b 100644 --- a/source/windows.cpp +++ b/source/windows.cpp @@ -19,7 +19,6 @@ #include "textures.h" #include "sfo.h" #include "system.h" -#include "dbglogger.h" #define MAX_IMAGE_HEIGHT 980 #define MAX_IMAGE_WIDTH 1820 @@ -142,7 +141,6 @@ namespace Windows std::string cur_version = INSTALLER::EzRemoteServerVersion(); ezremote_server_version_match = cur_version.empty() || (cur_version.compare(EZREMOTE_SERVER_REQUIRED_VERSION) == 0); show_ezremote_server_warning = !ezremote_server_version_match; - dbglogger_log("verion=%s, show_warning=%d", cur_version.c_str(), show_ezremote_server_warning); Actions::RefreshLocalFiles(false); }