forked from cafeberry/cafeberry
fix: networking fixes + add server
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user