attempt at trying to get XB360 to work
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user