attempt at trying to get XB360 to work

This commit is contained in:
2026-08-01 06:15:37 +03:00
parent 2170209e26
commit 01abe05b18
27 changed files with 435 additions and 187 deletions
@@ -66,7 +66,7 @@ void CGameNetworkManager::Initialise()
ServerStoppedCreate( false );
ServerReadyCreate( false );
int flagIndexSize = LevelRenderer::getGlobalChunkCount() / (Level::maxBuildHeight / 16); // dividing here by number of renderer chunks in one column
#ifdef _XBOX
#if !defined(_DISABLE_XBLIVE) && defined _XBOX
s_pPlatformNetworkManager = new CPlatformNetworkManagerXbox();
#elif !defined(DISABLE_PSN) && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
s_pPlatformNetworkManager = new CPlatformNetworkManagerSony();
@@ -1,10 +1,12 @@
#pragma once
using namespace std;
#include <vector>
#ifndef _DISABLE_XBLIVE
#include <qnet.h>
#endif
#include "..\..\..\Minecraft.World\C4JThread.h"
#include "NetworkPlayerInterface.h"
#ifdef _XBOX
#if defined _XBOX && !defined _DISABLE_XBLIVE
#include "..\..\Xbox\Network\PlatformNetworkManagerXbox.h"
#elif !defined DISABLE_PSN && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
#include "..\..\Common\Network\Sony\PlatformNetworkManagerSony.h"
@@ -30,7 +32,7 @@ const int NON_QNET_SENDDATA_ACK_REQUIRED = 1;
class CGameNetworkManager
{
#ifdef _XBOX
#if defined _XBOX && !defined _DISABLE_XBLIVE
friend class CPlatformNetworkManagerXbox;
#elif !defined DISABLE_PSN && defined __PS3__ || defined __ORBIS__ || defined __PSVITA__
friend class CPlatformNetworkManagerSony;
+94
View File
@@ -0,0 +1,94 @@
#pragma once
const int QNET_GETSENDQUEUESIZE_SECONDARY_TYPE = 0;
const int QNET_GETSENDQUEUESIZE_MESSAGES = 0;
const int QNET_GETSENDQUEUESIZE_BYTES = 0;
const int QNET_SENDDATA_LOW_PRIORITY = 0;
const int QNET_SENDDATA_SECONDARY = 0;
const int QNET_SENDDATA_RELIABLE = 0;
const int QNET_SENDDATA_SEQUENTIAL = 0;
#define QNET_E_SESSION_FULL 0
#define QNET_USER_MASK_USER0 1
#define QNET_USER_MASK_USER1 2
#define QNET_USER_MASK_USER2 4
#define QNET_USER_MASK_USER3 8
typedef enum _QNET_STATE
{
QNET_STATE_IDLE,
QNET_STATE_SESSION_HOSTING,
QNET_STATE_SESSION_JOINING,
QNET_STATE_GAME_LOBBY,
QNET_STATE_SESSION_REGISTERING,
QNET_STATE_SESSION_STARTING,
QNET_STATE_GAME_PLAY,
QNET_STATE_SESSION_ENDING,
QNET_STATE_SESSION_LEAVING,
QNET_STATE_SESSION_DELETING
} QNET_STATE, * PQNET_STATE;
class IQNetPlayer
{
public:
BYTE GetSmallId();
void SendData(IQNetPlayer *player, const void *pvData, DWORD dwDataSize, DWORD dwFlags);
bool IsSameSystem(IQNetPlayer *player);
DWORD GetSendQueueSize( IQNetPlayer *player, DWORD dwFlags );
DWORD GetCurrentRtt();
bool IsHost();
bool IsGuest();
bool IsLocal();
PlayerUID GetXuid();
LPCWSTR GetGamertag();
int GetSessionIndex();
bool IsTalking();
bool IsMutedByLocalUser(DWORD dwUserIndex);
bool HasVoice();
bool HasCamera();
int GetUserIndex();
void SetCustomDataValue(ULONG_PTR ulpCustomDataValue);
ULONG_PTR GetCustomDataValue();
BYTE m_smallId;
bool m_isRemote;
bool m_isHostPlayer;
wchar_t m_gamertag[32];
private:
ULONG_PTR m_customData;
};
void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal);
class IQNetCallbacks
{
};
class IQNetGameSearch
{
};
class IQNet
{
public:
HRESULT AddLocalPlayerByUserIndex(DWORD dwUserIndex);
IQNetPlayer *GetHostPlayer();
IQNetPlayer *GetLocalPlayerByUserIndex(DWORD dwUserIndex);
IQNetPlayer *GetPlayerByIndex(DWORD dwPlayerIndex);
IQNetPlayer *GetPlayerBySmallId(BYTE SmallId);
IQNetPlayer *GetPlayerByXuid(PlayerUID xuid);
DWORD GetPlayerCount();
QNET_STATE GetState();
bool IsHost();
HRESULT JoinGameFromInviteInfo(DWORD dwUserIndex, DWORD dwUserMask, const INVITE_INFO *pInviteInfo);
void HostGame();
void ClientJoinGame();
void EndGame();
static IQNetPlayer m_player[MINECRAFT_NET_MAX_PLAYERS];
static DWORD s_playerCount;
static bool s_isHosting;
};
@@ -1,7 +1,11 @@
#pragma once
using namespace std;
#include <vector>
#ifndef _DISABLE_XBLIVE
#include <qnet.h>
#else
#include "IQNet.h"
#endif
#include "..\..\..\Minecraft.World\C4JThread.h"
#include "NetworkPlayerInterface.h"
#include "SessionInfo.h"
@@ -5,7 +5,7 @@
#include "..\..\Xbox\Network\NetworkPlayerXbox.h" // TODO - stub version of this?
#include "..\..\Minecraft.h"
#include "..\..\User.h"
#if defined _WINDOWS64 || defined __PS3__
#if defined _WINDOWS64 || defined __PS3__ || defined _XBOX
#include "..\..\Common\Network\WinsockNetLayer.h"
#endif
@@ -23,11 +23,7 @@ public:
virtual bool RemoveLocalPlayerByUserIndex( int userIndex );
virtual INetworkPlayer *GetLocalPlayerByUserIndex( int userIndex );
virtual INetworkPlayer *GetPlayerByIndex(int playerIndex);
#ifdef __PS3
virtual INetworkPlayer * GetPlayerByXuid(PlayerUID* xuid)
#else
virtual INetworkPlayer * GetPlayerByXuid(PlayerUID xuid);
#endif
virtual INetworkPlayer * GetPlayerBySmallId(unsigned char smallId);
virtual bool ShouldMessageForFullSession();
@@ -6,7 +6,7 @@
// A struct that we store in the QoS data when we are hosting the session. Max size 1020 bytes.
#ifdef _XBOX
#if defined _XBOX && !defined _DISABLE_XBLIVE
typedef struct _GameSessionData
{
unsigned short netVersion; // 2 bytes
@@ -4,7 +4,7 @@
#include "..\..\Common\Network\PlatformNetworkManagerStub.h"
#include "..\..\..\Minecraft.World\Socket.h"
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
SOCKET WinsockNetLayer::s_listenSocket = INVALID_SOCKET;
SOCKET WinsockNetLayer::s_hostConnectionSocket = INVALID_SOCKET;
SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET;
@@ -61,7 +61,7 @@ char g_Win64MultiplayerIP[256] = "127.0.0.1";
bool WinsockNetLayer::Initialize()
{
if (s_initialized) return true;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (result != 0)
@@ -106,7 +106,7 @@ void WinsockNetLayer::Shutdown()
s_active = false;
s_connected = false;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_listenSocket != INVALID_SOCKET)
{
closesocket(s_listenSocket);
@@ -137,7 +137,7 @@ void WinsockNetLayer::Shutdown()
for (size_t i = 0; i < s_connections.size(); i++)
{
s_connections[i].active = false;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_connections[i].tcpSocket != INVALID_SOCKET)
#elif defined __PS3__
if (s_connections[i].tcpSocket >= 0)
@@ -219,6 +219,18 @@ bool WinsockNetLayer::HostGame(int port)
freeaddrinfo(result);
return false;
}
#elif defined _XBOX
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons((WORD)port);
s_listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s_listenSocket == INVALID_SOCKET)
{
app.DebugPrintf("socket() failed: %d\n", WSAGetLastError());
return false;
}
#elif defined __PS3__
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
@@ -247,6 +259,24 @@ bool WinsockNetLayer::HostGame(int port)
return false;
}
iResult = listen(s_listenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR)
{
app.DebugPrintf("listen() failed: %d\n", WSAGetLastError());
closesocket(s_listenSocket);
s_listenSocket = INVALID_SOCKET;
return false;
}
#elif defined _XBOX
iResult = ::bind(s_listenSocket, (struct sockaddr*)&addr, sizeof(addr));
if (iResult == SOCKET_ERROR)
{
app.DebugPrintf("bind() failed: %d\n", WSAGetLastError());
closesocket(s_listenSocket);
s_listenSocket = INVALID_SOCKET;
return false;
}
iResult = listen(s_listenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR)
{
@@ -330,6 +360,51 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
s_hostConnectionSocket = INVALID_SOCKET;
return false;
}
#elif defined _XBOX
XNDNS *pDns = NULL;
int iResult = XNetDnsLookup(ip, NULL, &pDns);
if (iResult != 0 || pDns == NULL)
{
app.DebugPrintf("XNetDnsLookup failed for %s - %d\n", ip, iResult);
return false;
}
while (pDns->iStatus == WSAEINPROGRESS)
{
Sleep(10);
}
if (pDns->iStatus != 0 || pDns->cina == 0)
{
app.DebugPrintf("pDns->iStatus failed for %s - %d\n", ip, iResult);
XNetDnsRelease(pDns);
return false;
}
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_port = htons((WORD)port);
addr.sin_addr = pDns->aina[0];
XNetDnsRelease(pDns);
s_hostConnectionSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s_hostConnectionSocket == INVALID_SOCKET)
{
app.DebugPrintf("socket() failed: %d\n", WSAGetLastError());
return false;
}
int noDelay = 1;
setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay));
iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr));
if (iResult == SOCKET_ERROR)
{
app.DebugPrintf("connect() to %s:%d failed: %d\n", ip, port, WSAGetLastError());
closesocket(s_hostConnectionSocket);
s_hostConnectionSocket = INVALID_SOCKET;
return false;
}
#elif defined __PS3__
struct sockaddr_in addr = {};
@@ -388,7 +463,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (sock == INVALID_SOCKET || dataSize <= 0) return false;
#elif defined __PS3__
if (sock < 0 || dataSize <= 0) return false;
@@ -407,7 +482,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
while (totalSent < toSend)
{
int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (sent == SOCKET_ERROR || sent == 0)
#elif defined __PS3__
if (sent < 0 || sent == 0)
@@ -424,7 +499,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
{
int sent = send(sock, (const char *)data + totalSent, dataSize - totalSent, 0);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (sent == SOCKET_ERROR || sent == 0)
#elif defined __PS3__
if (sent < 0 || sent == 0)
@@ -447,7 +522,7 @@ bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int da
if (s_isHost)
{
SOCKET sock = GetSocketForSmallId(targetSmallId);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (sock == INVALID_SOCKET) return false;
#elif defined __PS3__
if (sock < 0) return false;
@@ -473,7 +548,7 @@ SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId)
}
}
LeaveCriticalSection(&s_connectionsLock);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
return INVALID_SOCKET;
#elif defined __PS3__
return -1;
@@ -518,7 +593,7 @@ int WinsockNetLayer::AcceptThreadProc(LPVOID param)
while (s_active)
{
SOCKET clientSocket = accept(s_listenSocket, NULL, NULL);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (clientSocket == INVALID_SOCKET)
{
if (s_active)
@@ -698,7 +773,7 @@ int WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
{
BYTE *recvBuf = new BYTE[WIN64_NET_RECV_BUFFER_SIZE];
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
while (s_active && s_hostConnectionSocket != INVALID_SOCKET)
#elif defined __PS3__
while (s_active && s_hostConnectionSocket >= 0)
@@ -755,7 +830,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, un
LeaveCriticalSection(&s_advertiseLock);
s_advertiseSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_advertiseSock == INVALID_SOCKET)
{
app.DebugPrintf("Win64 LAN: Failed to create advertise socket: %d\n", WSAGetLastError());
@@ -842,7 +917,7 @@ int WinsockNetLayer::AdvertiseThreadProc(LPVOID param)
int sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0,
(struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr));
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (sent == SOCKET_ERROR && s_advertising)
{
app.DebugPrintf("Win64 LAN: Broadcast sendto failed: %d\n", WSAGetLastError());
@@ -866,7 +941,7 @@ bool WinsockNetLayer::StartDiscovery()
if (!s_initialized) return false;
s_discoverySock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_discoverySock == INVALID_SOCKET)
{
app.DebugPrintf("Win64 LAN: Failed to create discovery socket: %d\n", WSAGetLastError());
@@ -892,7 +967,7 @@ bool WinsockNetLayer::StartDiscovery()
bindAddr.sin_port = htons(WIN64_LAN_DISCOVERY_PORT);
bindAddr.sin_addr.s_addr = INADDR_ANY;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) == SOCKET_ERROR)
{
app.DebugPrintf("Win64 LAN: Discovery bind failed: %d\n", WSAGetLastError());
@@ -924,7 +999,7 @@ void WinsockNetLayer::StopDiscovery()
{
s_discovering = false;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_discoverySock != INVALID_SOCKET)
{
closesocket(s_discoverySock);
@@ -967,7 +1042,7 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
while (s_discovering)
{
struct sockaddr_in senderAddr;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
int senderLen = sizeof(senderAddr);
#elif defined __PS3__
socklen_t senderLen = sizeof(senderAddr);
@@ -1003,7 +1078,14 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
continue;
char senderIP[64];
#if defined _XBOX
unsigned char *ipBytes = (unsigned char *)&senderAddr.sin_addr;
sprintf_s(senderIP, sizeof(senderIP), "%d.%d.%d.%d",
ipBytes[0], ipBytes[1], ipBytes[2], ipBytes[3]);
#else
inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP));
#endif
DWORD now = GetTickCount();
@@ -3,6 +3,9 @@
#if defined _WINDOWS64
#include <WinSock2.h>
#include <WS2tcpip.h>
#elif defined _XBOX
#include <winsockx.h>
#include <xtl.h>
#elif defined __PS3__
#include <sys/socket.h>
#include <sys/types.h>