fix: networking fixes + add server
This commit is contained in:
13 files changed
+129
-36
No files matched your search
@@ -2133,6 +2133,11 @@ void CGameNetworkManager::FakeLocalPlayerJoined()
|
||||
}
|
||||
#endif
|
||||
|
||||
void CGameNetworkManager::AddServer(const wchar_t *ip, int port, const wchar_t *name)
|
||||
{
|
||||
((CPlatformNetworkManagerStub *)s_pPlatformNetworkManager)->AddServer(ip, port, name);
|
||||
}
|
||||
|
||||
#if !defined(DISABLE_PSN) && defined(__PSVITA__)
|
||||
bool CGameNetworkManager::usingAdhocMode()
|
||||
{
|
||||
|
||||
@@ -229,6 +229,7 @@ public:
|
||||
#ifndef _XBOX
|
||||
void FakeLocalPlayerJoined(); // Temporary method whilst we don't have real networking to make this happen
|
||||
#endif
|
||||
static void AddServer(const wchar_t *ip, int port, const wchar_t *name);
|
||||
};
|
||||
|
||||
extern CGameNetworkManager g_NetworkManager;
|
||||
|
||||
@@ -71,13 +71,8 @@ std::vector<BYTE> NetworkSocketLayer::s_freeSmallIds;
|
||||
|
||||
// only goes true on a successful Initialize(), and a failed one gets retried
|
||||
static bool s_locksCreated = false;
|
||||
#if !defined _WINDOWS64
|
||||
bool g_MultiplayerHost = true;
|
||||
bool g_MultiplayerJoin = false;
|
||||
#else
|
||||
bool g_MultiplayerHost = false;
|
||||
bool g_MultiplayerJoin = true;
|
||||
#endif
|
||||
|
||||
#ifdef MINECRAFT_SERVER_BUILD
|
||||
int g_DedicatedServerPort = NETWORK_LAN_DEFAULT_PORT;
|
||||
@@ -85,7 +80,7 @@ char g_DedicatedServerBindIP[256] = "";
|
||||
bool g_DedicatedServerLanAdvertise = true;
|
||||
#endif
|
||||
int g_MultiplayerPort = NETWORK_LAN_DEFAULT_PORT;
|
||||
char g_MultiplayerIP[256] = "192.168.8.27";
|
||||
char g_MultiplayerIP[256] = "";
|
||||
|
||||
|
||||
bool NetworkSocketLayer::Initialize()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "..\..\Common\Network\NetworkSocketLayer.h"
|
||||
|
||||
CPlatformNetworkManagerStub *g_pPlatformNetworkManager;
|
||||
|
||||
std::vector<FriendSessionInfo *> serverList;
|
||||
|
||||
void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer )
|
||||
{
|
||||
@@ -790,6 +790,29 @@ void CPlatformNetworkManagerStub::TickSearch()
|
||||
SearchForGames();
|
||||
}
|
||||
|
||||
void CPlatformNetworkManagerStub::AddServer(const wchar_t *ip, int port, const wchar_t *name)
|
||||
{
|
||||
if (!ip || !name) return;
|
||||
|
||||
char narrowIP[256] = {};
|
||||
wcstombs(narrowIP, ip, sizeof(narrowIP) - 1);
|
||||
FriendSessionInfo* info = new FriendSessionInfo();
|
||||
|
||||
size_t nLen = wcslen(name);
|
||||
info->displayLabel = new wchar_t[nLen + 1];
|
||||
wcsncpy(info->displayLabel, name, nLen);
|
||||
info->displayLabel[nLen] = L'\0';
|
||||
info->displayLabelLength = (unsigned char)nLen;
|
||||
|
||||
info->displayLabelViewableStartIndex = 0;
|
||||
info->data.isReadyToJoin = true;
|
||||
info->data.isJoinable = true;
|
||||
strncpy(info->data.hostIP, narrowIP, sizeof(info->data.hostIP) - 1);
|
||||
info->data.hostPort = port;
|
||||
info->sessionId = (SessionID)((uint64_t)(inet_addr(narrowIP)) | ((uint64_t)(port) << 32));
|
||||
serverList.push_back(info);
|
||||
};
|
||||
|
||||
void CPlatformNetworkManagerStub::SearchForGames()
|
||||
{
|
||||
std::vector<LANSession> lanSessions = NetworkSocketLayer::GetDiscoveredSessions();
|
||||
@@ -874,6 +897,27 @@ void CPlatformNetworkManagerStub::SearchForGames()
|
||||
friendsSessions[0].push_back(info);
|
||||
}
|
||||
|
||||
for (AUTO_VAR(it, serverList.begin()); it != serverList.end(); ++it)
|
||||
{
|
||||
FriendSessionInfo *src = *it;
|
||||
|
||||
FriendSessionInfo *copy = new FriendSessionInfo();
|
||||
*copy = *src;
|
||||
|
||||
if (src->displayLabel != NULL)
|
||||
{
|
||||
copy->displayLabel = new wchar_t[(size_t)src->displayLabelLength + 1];
|
||||
wcsncpy(copy->displayLabel, src->displayLabel, src->displayLabelLength);
|
||||
copy->displayLabel[src->displayLabelLength] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
copy->displayLabel = NULL;
|
||||
}
|
||||
|
||||
friendsSessions[0].push_back(copy);
|
||||
}
|
||||
|
||||
m_searchResultsCount[0] = (int)friendsSessions[0].size();
|
||||
|
||||
if (m_SessionsUpdatedCallback != NULL)
|
||||
|
||||
@@ -168,6 +168,8 @@ public:
|
||||
void NotifyPlayerJoined( IQNetPlayer *pQNetPlayer );
|
||||
void NotifyPlayerLeaving( IQNetPlayer *pQNetPlayer );
|
||||
|
||||
void AddServer(const wchar_t *ip, int port, const wchar_t *name);
|
||||
|
||||
#ifndef _XBOX
|
||||
void FakeLocalPlayerJoined() { NotifyPlayerJoined(m_pIQNet->GetLocalPlayerByUserIndex(0)); }
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user