remove debug network code
This commit is contained in:
1 parent
42b9349755
commit
83a62db82a
2 files changed
+11
-95
No files matched your search
@@ -3,11 +3,6 @@
|
|||||||
#include "NetworkSocketLayer.h"
|
#include "NetworkSocketLayer.h"
|
||||||
#include "..\..\Common\Network\PlatformNetworkManager.h"
|
#include "..\..\Common\Network\PlatformNetworkManager.h"
|
||||||
#include "..\..\..\Minecraft.World\Socket.h"
|
#include "..\..\..\Minecraft.World\Socket.h"
|
||||||
#ifdef __ORBIS__
|
|
||||||
#include <libnetctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const DWORD NETWORK_LAN_DISCOVERY_QUERY_MAGIC = 0x4D435152;
|
|
||||||
|
|
||||||
#if defined _WINDOWS64 || defined _XBOX
|
#if defined _WINDOWS64 || defined _XBOX
|
||||||
SOCKET NetworkSocketLayer::s_listenSocket = INVALID_SOCKET;
|
SOCKET NetworkSocketLayer::s_listenSocket = INVALID_SOCKET;
|
||||||
@@ -1263,7 +1258,7 @@ int NetworkSocketLayer::AdvertiseThreadProc(LPVOID param)
|
|||||||
#ifdef _WINDOWS64
|
#ifdef _WINDOWS64
|
||||||
struct in_addr localAddresses[32];
|
struct in_addr localAddresses[32];
|
||||||
struct in_addr broadcastAddresses[32];
|
struct in_addr broadcastAddresses[32];
|
||||||
int interfaceCount = GetLocalIPv4Interfaces(s_advertiseSock, localAddresses, broadcastAddresses, 32);
|
int interfaceCount = GetLocalIPv4Interfaces(s_advertiseSock, localAddresses, broadcastAddresses, 32); // this is bad fyi and needs to be replaced
|
||||||
for(int i = 0; i < interfaceCount; ++i)
|
for(int i = 0; i < interfaceCount; ++i)
|
||||||
{
|
{
|
||||||
broadcastAddr.sin_addr = broadcastAddresses[i];
|
broadcastAddr.sin_addr = broadcastAddresses[i];
|
||||||
@@ -1294,7 +1289,8 @@ int NetworkSocketLayer::AdvertiseThreadProc(LPVOID param)
|
|||||||
{
|
{
|
||||||
app.DebugPrintf("PS3 LAN: Broadcast sendto failed: %d\n", sent);
|
app.DebugPrintf("PS3 LAN: Broadcast sendto failed: %d\n", sent);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
C4JThread::Sleep(1000);
|
C4JThread::Sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1303,14 +1299,8 @@ int NetworkSocketLayer::AdvertiseThreadProc(LPVOID param)
|
|||||||
|
|
||||||
bool NetworkSocketLayer::StartDiscovery()
|
bool NetworkSocketLayer::StartDiscovery()
|
||||||
{
|
{
|
||||||
if (s_discovering)
|
if (s_discovering) return true;
|
||||||
{
|
if (!s_initialized) return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!s_initialized)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_discoverySock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
s_discoverySock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
#if defined _WINDOWS64 || defined _XBOX
|
#if defined _WINDOWS64 || defined _XBOX
|
||||||
@@ -1331,8 +1321,6 @@ bool NetworkSocketLayer::StartDiscovery()
|
|||||||
|
|
||||||
BOOL reuseAddr = TRUE;
|
BOOL reuseAddr = TRUE;
|
||||||
setsockopt(s_discoverySock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuseAddr, sizeof(reuseAddr));
|
setsockopt(s_discoverySock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuseAddr, sizeof(reuseAddr));
|
||||||
BOOL broadcast = TRUE;
|
|
||||||
setsockopt(s_discoverySock, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast));
|
|
||||||
|
|
||||||
struct sockaddr_in bindAddr;
|
struct sockaddr_in bindAddr;
|
||||||
memset(&bindAddr, 0, sizeof(bindAddr));
|
memset(&bindAddr, 0, sizeof(bindAddr));
|
||||||
@@ -1349,8 +1337,7 @@ bool NetworkSocketLayer::StartDiscovery()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#elif defined __PS3__ || defined __ORBIS__
|
#elif defined __PS3__ || defined __ORBIS__
|
||||||
int bindResult = ::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr));
|
if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0)
|
||||||
if (bindResult < 0)
|
|
||||||
{
|
{
|
||||||
#if defined(__PS3__)
|
#if defined(__PS3__)
|
||||||
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sys_net_errno);
|
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sys_net_errno);
|
||||||
@@ -1413,54 +1400,6 @@ void NetworkSocketLayer::StopDiscovery()
|
|||||||
std::vector<LANSession> NetworkSocketLayer::GetDiscoveredSessions()
|
std::vector<LANSession> NetworkSocketLayer::GetDiscoveredSessions()
|
||||||
{
|
{
|
||||||
std::vector<LANSession> result;
|
std::vector<LANSession> result;
|
||||||
if (!s_discovering && !StartDiscovery())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD query = htonl(NETWORK_LAN_DISCOVERY_QUERY_MAGIC);
|
|
||||||
struct sockaddr_in destination;
|
|
||||||
memset(&destination, 0, sizeof(destination));
|
|
||||||
destination.sin_family = AF_INET;
|
|
||||||
destination.sin_port = htons(NETWORK_LAN_DISCOVERY_PORT);
|
|
||||||
destination.sin_addr.s_addr = INADDR_BROADCAST;
|
|
||||||
sendto(s_discoverySock, (const char *)&query, sizeof(query), 0,
|
|
||||||
(struct sockaddr *)&destination, sizeof(destination));
|
|
||||||
|
|
||||||
#ifdef __ORBIS__
|
|
||||||
SceNetCtlInfo ipInfo;
|
|
||||||
SceNetCtlInfo maskInfo;
|
|
||||||
int ipResult = sceNetCtlGetInfo(SCE_NET_CTL_INFO_IP_ADDRESS, &ipInfo);
|
|
||||||
int maskResult = sceNetCtlGetInfo(SCE_NET_CTL_INFO_NETMASK, &maskInfo);
|
|
||||||
if (ipResult == SCE_OK && maskResult == SCE_OK)
|
|
||||||
{
|
|
||||||
struct in_addr localAddress;
|
|
||||||
struct in_addr netmask;
|
|
||||||
if (inet_pton(AF_INET, ipInfo.ip_address, &localAddress) == 1 &&
|
|
||||||
inet_pton(AF_INET, maskInfo.netmask, &netmask) == 1)
|
|
||||||
{
|
|
||||||
DWORD local = ntohl(localAddress.s_addr);
|
|
||||||
DWORD mask = ntohl(netmask.s_addr);
|
|
||||||
DWORD first = (local & mask) + 1;
|
|
||||||
DWORD last = (local | ~mask) - 1;
|
|
||||||
if (last - first > 1023)
|
|
||||||
{
|
|
||||||
first = local & 0xFFFFFF00;
|
|
||||||
last = first + 254;
|
|
||||||
++first;
|
|
||||||
}
|
|
||||||
for (DWORD address = first; address <= last; ++address)
|
|
||||||
{
|
|
||||||
if (address == local)
|
|
||||||
continue;
|
|
||||||
destination.sin_addr.s_addr = htonl(address);
|
|
||||||
sendto(s_discoverySock, (const char *)&query, sizeof(query), 0,
|
|
||||||
(struct sockaddr *)&destination, sizeof(destination));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (TryEnterCriticalSection(&s_discoveryLock))
|
if (TryEnterCriticalSection(&s_discoveryLock))
|
||||||
{
|
{
|
||||||
result = s_discoveredSessions;
|
result = s_discoveredSessions;
|
||||||
@@ -1498,30 +1437,8 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (recvLen == (int)sizeof(DWORD))
|
|
||||||
{
|
|
||||||
DWORD query;
|
|
||||||
memcpy(&query, recvBuf, sizeof(query));
|
|
||||||
if (ntohl(query) == NETWORK_LAN_DISCOVERY_QUERY_MAGIC && s_advertising)
|
|
||||||
{
|
|
||||||
EnterCriticalSection(&s_advertiseLock);
|
|
||||||
LANBroadcast response = s_advertiseData;
|
|
||||||
LeaveCriticalSection(&s_advertiseLock);
|
|
||||||
response.magic = htonl(response.magic);
|
|
||||||
response.netVersion = htons(response.netVersion);
|
|
||||||
response.gamePort = htons(response.gamePort);
|
|
||||||
response.gameHostSettings = htonl(response.gameHostSettings);
|
|
||||||
response.texturePackParentId = htonl(response.texturePackParentId);
|
|
||||||
sendto(s_discoverySock, (const char *)&response, sizeof(response), 0,
|
|
||||||
(struct sockaddr *)&senderAddr, senderLen);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recvLen < (int)sizeof(LANBroadcast))
|
if (recvLen < (int)sizeof(LANBroadcast))
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
LANBroadcast *broadcast = (LANBroadcast *)recvBuf;
|
LANBroadcast *broadcast = (LANBroadcast *)recvBuf;
|
||||||
|
|
||||||
@@ -1532,9 +1449,7 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param)
|
|||||||
broadcast->texturePackParentId = ntohl(broadcast->texturePackParentId);
|
broadcast->texturePackParentId = ntohl(broadcast->texturePackParentId);
|
||||||
|
|
||||||
if (broadcast->magic != NETWORK_LAN_BROADCAST_MAGIC)
|
if (broadcast->magic != NETWORK_LAN_BROADCAST_MAGIC)
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
char senderIP[64];
|
char senderIP[64];
|
||||||
#if defined _XBOX
|
#if defined _XBOX
|
||||||
@@ -1545,6 +1460,7 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param)
|
|||||||
#else
|
#else
|
||||||
inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP));
|
inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DWORD now = GetTickCount();
|
DWORD now = GetTickCount();
|
||||||
|
|
||||||
EnterCriticalSection(&s_discoveryLock);
|
EnterCriticalSection(&s_discoveryLock);
|
||||||
|
|||||||
@@ -1059,10 +1059,10 @@ int main(int argc, const char *argv[] )
|
|||||||
// XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the
|
// XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the
|
||||||
// ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet.
|
// ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet.
|
||||||
|
|
||||||
g_NetworkManager.Initialise();
|
g_NetworkManager.Initialise();
|
||||||
NetworkSocketLayer::Initialize();
|
NetworkSocketLayer::Initialize();
|
||||||
|
|
||||||
// debug switch to trial version
|
// debug switch to trial version
|
||||||
ProfileManager.SetDebugFullOverride(true);
|
ProfileManager.SetDebugFullOverride(true);
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user