add ps4 support

This commit is contained in:
2026-08-02 22:06:27 +03:00
parent 94f1cefcf9
commit 92209cf909
36 changed files with 257 additions and 123 deletions
@@ -68,7 +68,7 @@ void CGameNetworkManager::Initialise()
int flagIndexSize = LevelRenderer::getGlobalChunkCount() / (Level::maxBuildHeight / 16); // dividing here by number of renderer chunks in one column
#if !defined(_DISABLE_XBLIVE) && defined _XBOX
s_pPlatformNetworkManager = new CPlatformNetworkManagerXbox();
#elif !defined(DISABLE_PSN) && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
#elif !defined(DISABLE_PSN) && (defined __PS3__ || defined __ORBIS__ || defined __PSVITA__)
s_pPlatformNetworkManager = new CPlatformNetworkManagerSony();
#elif defined _DURANGO
s_pPlatformNetworkManager = new CPlatformNetworkManagerDurango();
@@ -801,7 +801,7 @@ int CGameNetworkManager::JoinFromInvite_SignInReturned(void *pParam,bool bContin
// Check if user-created content is allowed, as we cannot play multiplayer if it's not
bool noUGC = false;
#if !defined(DISABLE_PSN) && defined(__PS3__) || defined(__PSVITA__)
#if !defined(DISABLE_PSN) && (defined(__PS3__) || defined(__PSVITA__))
ProfileManager.GetChatAndContentRestrictions(iPad,false,&noUGC,NULL,NULL);
#elif defined(__ORBIS__)
ProfileManager.GetChatAndContentRestrictions(iPad,false,NULL,&noUGC,NULL);
@@ -1815,7 +1815,7 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO *
#endif
if( !g_NetworkManager.IsInSession() )
{
#if !defined(DISABLE_PSN) && defined (__PS3__) || defined (__PSVITA__)
#if !defined(DISABLE_PSN) && (defined (__PS3__) || defined (__PSVITA__))
// PS3 is more complicated here - we need to make sure that the player is online. If they are then we can do the same as the xbox, if not we need to try and get them online and then, if they do sign in, go down the same path
// Determine why they're not "signed in live"
@@ -1965,7 +1965,7 @@ void CGameNetworkManager::HandleDisconnect(bool bLostRoomOnly)
if((g_NetworkManager.GetLockedProfile()!=-1) && iPrimaryPlayer!=-1 && g_NetworkManager.IsInSession() )
{
m_bLastDisconnectWasLostRoomOnly = bLostRoomOnly;
#if !defined(DISABLE_PSN) && defined __PS3__ || defined __PSVITA__ || defined __ORBIS__
#if !defined(DISABLE_PSN) && (defined __PS3__ || defined __PSVITA__ || defined __ORBIS__)
m_bSignedOutofPSN=bPSNSignout;
#endif
app.SetAction(iPrimaryPlayer,eAppAction_EthernetDisconnected);
@@ -8,7 +8,7 @@ using namespace std;
#include "NetworkPlayerInterface.h"
#if defined _XBOX && !defined _DISABLE_XBLIVE
#include "..\..\Xbox\Network\PlatformNetworkManagerXbox.h"
#elif !defined DISABLE_PSN && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
#elif !defined DISABLE_PSN && (defined __PS3__ || defined __ORBIS__ || defined __PSVITA__)
#include "..\..\Common\Network\Sony\PlatformNetworkManagerSony.h"
#elif defined _DURANGO
#include "..\..\Durango\Network\PlatformNetworkManagerDurango.h"
@@ -34,7 +34,7 @@ class CGameNetworkManager
{
#if defined _XBOX && !defined _DISABLE_XBLIVE
friend class CPlatformNetworkManagerXbox;
#elif !defined DISABLE_PSN && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
#elif !defined DISABLE_PSN && (defined __PS3__ || defined __ORBIS__ || defined __PSVITA__)
friend class CPlatformNetworkManagerSony;
#elif defined _DURANGO
friend class CPlatformNetworkManagerDurango;
@@ -5,9 +5,7 @@
#include "..\..\Xbox\Network\NetworkPlayerXbox.h" // TODO - stub version of this?
#include "..\..\Minecraft.h"
#include "..\..\User.h"
#if defined _WINDOWS64 || defined __PS3__ || defined _XBOX
#include "..\..\Common\Network\WinsockNetLayer.h"
#endif
CPlatformNetworkManagerStub *g_pPlatformNetworkManager;
@@ -770,8 +768,13 @@ void CPlatformNetworkManagerStub::SearchForGames()
}
}
#ifdef __ORBIS__
SceNetInAddr ip_addr = {};
sceNetInetPton(SCE_NET_AF_INET, lanSessions[i].hostIP, &ip_addr);
info->sessionId = (ULONGLONG)((uint64_t)ip_addr.s_addr | ((uint64_t)lanSessions[i].hostPort << 32));
#else
info->sessionId = (ULONGLONG)((unsigned __int64)inet_addr(lanSessions[i].hostIP) | ((unsigned __int64)lanSessions[i].hostPort << 32));
#endif
friendsSessions[0].push_back(info);
}
@@ -32,7 +32,7 @@ typedef struct _GameSessionData
subTexturePackId = 0;
}
} GameSessionData;
#elif (defined __PS3__ && !defined DISABLE_PSN) || defined __ORBIS__ || defined(__PSVITA__)
#elif !defined DISABLE_PSN && (defined __PS3__ || defined __ORBIS__ || defined(__PSVITA__))
typedef struct _GameSessionData
{
unsigned short netVersion; // 2 bytes
@@ -114,7 +114,7 @@ public:
SessionID sessionId;
#ifdef _XBOX
XSESSION_SEARCHRESULT searchResult;
#elif (defined __PS3__ && !defined DISABLE_PSN) || defined(__ORBIS__) || defined (__PSVITA__)
#elif !defined(DISABLE_PSN) && (defined(__PS3__) || defined(__ORBIS__) || defined (__PSVITA__))
SQRNetworkManager::SessionSearchResult searchResult;
#elif defined(_DURANGO)
DQRNetworkManager::SessionSearchResult searchResult;
@@ -9,15 +9,22 @@ SOCKET WinsockNetLayer::s_listenSocket = INVALID_SOCKET;
SOCKET WinsockNetLayer::s_hostConnectionSocket = INVALID_SOCKET;
SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET;
SOCKET WinsockNetLayer::s_discoverySock = INVALID_SOCKET;
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
SOCKET WinsockNetLayer::s_listenSocket = -1;
SOCKET WinsockNetLayer::s_hostConnectionSocket = -1;
SOCKET WinsockNetLayer::s_advertiseSock = -1;
SOCKET WinsockNetLayer::s_discoverySock = -1;
#if defined __PS3__
int closesocket(int s) { return socketclose(s); };
void terminate_networking() { cellNetCtlTerm(); sys_net_finalize_network(); };
#elif defined __ORBIS__
int closesocket(int s) { return sceNetSocketClose(s); };
int socketclose(int s) { return sceNetSocketClose(s); };
void terminate_networking() {};
void WSACleanup() {};
#endif
#endif
C4JThread* WinsockNetLayer::s_acceptThread = NULL;
C4JThread* WinsockNetLayer::s_clientRecvThread = NULL;
@@ -118,7 +125,7 @@ void WinsockNetLayer::Shutdown()
closesocket(s_hostConnectionSocket);
s_hostConnectionSocket = INVALID_SOCKET;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_listenSocket >= 0)
{
socketclose(s_listenSocket);
@@ -139,7 +146,7 @@ void WinsockNetLayer::Shutdown()
s_connections[i].active = false;
#if defined _WINDOWS64 || defined _XBOX
if (s_connections[i].tcpSocket != INVALID_SOCKET)
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_connections[i].tcpSocket >= 0)
#endif
{
@@ -231,7 +238,7 @@ bool WinsockNetLayer::HostGame(int port)
app.DebugPrintf("socket() failed: %d\n", WSAGetLastError());
return false;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -285,7 +292,7 @@ bool WinsockNetLayer::HostGame(int port)
s_listenSocket = INVALID_SOCKET;
return false;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
iResult = ::bind(s_listenSocket, (struct sockaddr*)&addr, sizeof(addr));
if (iResult < 0)
{
@@ -539,7 +546,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
connected = true;
break;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_hostConnectionSocket != -1)
{
socketclose(s_hostConnectionSocket);
@@ -551,12 +558,20 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
addr.sin_family = AF_INET;
addr.sin_port = htons((uint16_t)port);
#if defined(__PS3__)
addr.sin_addr.s_addr = inet_addr(ip);
if (addr.sin_addr.s_addr == INADDR_NONE)
{
app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port);
return false;
}
#elif defined(__ORBIS__)
if (sceNetInetPton(SCE_NET_AF_INET, ip, &addr.sin_addr.s_addr) <= 0)
{
app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port);
return false;
}
#endif
bool connected = false;
BYTE assignedSmallId = 0;
@@ -575,14 +590,24 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay));
int nonBlocking = 1;
#ifdef __PS3__
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_NBIO, &nonBlocking, sizeof(nonBlocking));
#elif defined(__ORBIS__)
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SCE_NET_SO_NBIO, &nonBlocking, sizeof(nonBlocking));
#endif
iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr));
if (iResult < 0)
{
#if defined(__PS3__)
int err = sys_net_errno;
if (err == SYS_NET_EINPROGRESS)
{
#elif defined(__ORBIS__)
int err = sce_net_errno;
if (err == SCE_NET_EINPROGRESS)
{
#endif
fd_set writeFds, exceptFds;
FD_ZERO(&writeFds);
FD_ZERO(&exceptFds);
@@ -593,7 +618,11 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
tv.tv_sec = connectTimeoutMs / 1000;
tv.tv_usec = (connectTimeoutMs % 1000) * 1000;
#if defined(__PS3__)
int selectResult = socketselect(s_hostConnectionSocket + 1, NULL, &writeFds, &exceptFds, &tv);
#elif defined(__ORBIS__)
int selectResult = select(s_hostConnectionSocket + 1, NULL, &writeFds, &exceptFds, &tv);
#endif
if (selectResult <= 0 || FD_ISSET(s_hostConnectionSocket, &exceptFds))
{
app.DebugPrintf("connect() to %s:%d timed out or failed (attempt %d/%d)\n", ip, port, attempt + 1, maxAttempts);
@@ -623,7 +652,11 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
}
int blocking = 0;
#ifdef __PS3__
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_NBIO, &blocking, sizeof(blocking));
#elif defined(__ORBIS__)
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SCE_NET_SO_NBIO, &blocking, sizeof(blocking));
#endif
DWORD recvTimeout = 3000;
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&recvTimeout, sizeof(recvTimeout));
@@ -675,7 +708,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{
#if defined _WINDOWS64 || defined _XBOX
if (sock == INVALID_SOCKET || dataSize <= 0) return false;
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (sock < 0 || dataSize <= 0) return false;
#endif
@@ -694,7 +727,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0);
#if defined _WINDOWS64 || defined _XBOX
if (sent == SOCKET_ERROR || sent == 0)
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (sent < 0 || sent == 0)
#endif
{
@@ -711,7 +744,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
#if defined _WINDOWS64 || defined _XBOX
if (sent == SOCKET_ERROR || sent == 0)
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (sent < 0 || sent == 0)
#endif
{
@@ -734,7 +767,7 @@ bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int da
SOCKET sock = GetSocketForSmallId(targetSmallId);
#if defined _WINDOWS64 || defined _XBOX
if (sock == INVALID_SOCKET) return false;
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (sock < 0) return false;
#endif
return SendOnSocket(sock, data, dataSize);
@@ -760,7 +793,7 @@ SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId)
LeaveCriticalSection(&s_connectionsLock);
#if defined _WINDOWS64 || defined _XBOX
return INVALID_SOCKET;
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
return -1;
#endif
}
@@ -810,7 +843,7 @@ int WinsockNetLayer::AcceptThreadProc(LPVOID param)
app.DebugPrintf("accept() failed: %d\n", WSAGetLastError());
break;
}
#elif __PS3__
#elif __PS3__ || defined __ORBIS__
if (clientSocket < 0)
{
if (s_active)
@@ -1017,7 +1050,7 @@ int WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
#if defined _WINDOWS64 || defined _XBOX
while (s_active && s_hostConnectionSocket != INVALID_SOCKET)
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
while (s_active && s_hostConnectionSocket >= 0)
#endif
{
@@ -1082,7 +1115,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, un
app.DebugPrintf("Win64 LAN: Failed to create advertise socket: %d\n", WSAGetLastError());
return false;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_advertiseSock < 0)
{
app.DebugPrintf("PS3 LAN: Failed to create advertise socket: %d\n", s_advertiseSock);
@@ -1110,7 +1143,7 @@ void WinsockNetLayer::StopAdvertising()
closesocket(s_advertiseSock);
s_advertiseSock = INVALID_SOCKET;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_advertiseSock >= 0)
{
closesocket(s_advertiseSock);
@@ -1180,7 +1213,7 @@ int WinsockNetLayer::AdvertiseThreadProc(LPVOID param)
{
app.DebugPrintf("Win64 LAN: Broadcast sendto failed: %d\n", WSAGetLastError());
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (sent < 0 && s_advertising)
{
app.DebugPrintf("PS3 LAN: Broadcast sendto failed: %d\n", sent);
@@ -1205,13 +1238,12 @@ bool WinsockNetLayer::StartDiscovery()
app.DebugPrintf("Win64 LAN: Failed to create discovery socket: %d\n", WSAGetLastError());
return false;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
app.DebugPrintf("Discovery socket: %d\n", s_discoverySock);
if (s_discoverySock < 0)
{
app.DebugPrintf("PS3 LAN: Failed to create discovery socket: %d\n", s_discoverySock);
cellNetCtlTerm();
sys_net_finalize_network();
terminate_networking();
return false;
}
#endif
@@ -1233,10 +1265,14 @@ bool WinsockNetLayer::StartDiscovery()
s_discoverySock = INVALID_SOCKET;
return false;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0)
{
#if defined(__PS3__)
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sys_net_errno);
#elif defined(__ORBIS__)
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sce_net_errno);
#endif
socketclose(s_discoverySock);
s_discoverySock = -1;
return false;
@@ -1263,7 +1299,7 @@ void WinsockNetLayer::StopDiscovery()
closesocket(s_discoverySock);
s_discoverySock = INVALID_SOCKET;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (s_discoverySock >= 0)
{
socketclose(s_discoverySock);
@@ -1304,7 +1340,7 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
struct sockaddr_in senderAddr;
#if defined _WINDOWS64 || defined _XBOX
int senderLen = sizeof(senderAddr);
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
socklen_t senderLen = sizeof(senderAddr);
#endif
@@ -1316,7 +1352,7 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
{
continue;
}
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
if (recvLen < 0)
{
continue;
@@ -7,12 +7,10 @@
#include <stdint.h>
#include <winsockx.h>
#include <xtl.h>
#elif defined __PS3__
#elif defined __PS3__ || defined __ORBIS__
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netex/net.h>
#include <netex/errno.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -20,6 +18,11 @@
#include <sys/select.h>
#endif
#ifdef __PS3__
#include <netex/net.h>
#include <netex/errno.h>
#endif
#include <vector>
#include "..\..\Common\Network\NetworkPlayerInterface.h"
@@ -34,7 +37,7 @@
#define WIN64_LAN_DISCOVERY_PORT 25566
#define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E
#ifdef __PS3__
#if defined __PS3__ || defined __ORBIS__
typedef int SOCKET;
#define INVALID_SOCKET -1
#endif