mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-12-02 22:18:09 +01:00
Social System
+Discord account connection +Friends List +UPnP Connection +Cosmetics (Iggy menus need to be fixed up a little)
This commit is contained in:
1 parent
3ebbf6f243
commit
55c9b5c827
61 files changed
+7725
-1564
No files matched your search
@@ -19,6 +19,9 @@
|
||||
#include "..\..\..\Minecraft.World\Socket.h"
|
||||
#include "..\..\Common\Network\ExternalServerList.h"
|
||||
#include "..\Windows64_Xuid.h"
|
||||
#ifndef MINECRAFT_SERVER_BUILD
|
||||
#include "..\..\Common\UI\SocialOnlineService.h"
|
||||
#endif
|
||||
|
||||
bool g_Win64MultiplayerHost = false;
|
||||
bool g_Win64MultiplayerJoin = false;
|
||||
@@ -377,7 +380,47 @@ CPlatformNetworkManagerWindows::~CPlatformNetworkManagerWindows() {
|
||||
if (g_pPlatformNetworkManagerWindows == this) g_pPlatformNetworkManagerWindows = nullptr;
|
||||
}
|
||||
|
||||
static CPlatformNetworkManagerWindows* s_windowsNetworkManager = nullptr;
|
||||
|
||||
int Win64_GetHostedGamePort() {
|
||||
return s_windowsNetworkManager != nullptr ? s_windowsNetworkManager->GetHostedPort() : 0;
|
||||
}
|
||||
|
||||
bool Win64_GetJoinAddress(std::string& host, int& port) {
|
||||
return s_windowsNetworkManager != nullptr && s_windowsNetworkManager->GetJoinAddress(host, port);
|
||||
}
|
||||
|
||||
int CPlatformNetworkManagerWindows::GetHostedPort() const {
|
||||
return (m_isHost && !m_isLeaving && m_listenSocket != INVALID_SOCKET) ? static_cast<int>(m_gamePort) : 0;
|
||||
}
|
||||
|
||||
bool CPlatformNetworkManagerWindows::GetJoinAddress(std::string& host, int& port) const {
|
||||
if (m_isHost || m_joinHost.empty() || m_joinPort <= 0) return false;
|
||||
host = m_joinHost;
|
||||
port = m_joinPort;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ResolveFriendSession(FriendSessionInfo* session) {
|
||||
#ifndef MINECRAFT_SERVER_BUILD
|
||||
if (session == nullptr || !session->isFriendGame) return false;
|
||||
std::string ip;
|
||||
int port = 0;
|
||||
if (!SocialOnlineService::ResolveFriendGame(static_cast<unsigned long long>(session->sessionId), ip, port) || ip.empty() || port <= 0) {
|
||||
app.DebugPrintf("Friend game is no longer available\n");
|
||||
return false;
|
||||
}
|
||||
strncpy_s(session->data.hostIP, sizeof(session->data.hostIP), ip.c_str(), _TRUNCATE);
|
||||
session->data.hostPort = port;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CPlatformNetworkManagerWindows::Initialise(CGameNetworkManager* pGameNetworkManager, int flagIndexSize) {
|
||||
s_windowsNetworkManager = this;
|
||||
m_joinPort = 0;
|
||||
m_gameNetworkManager = pGameNetworkManager;
|
||||
m_flagIndexSize = flagIndexSize;
|
||||
|
||||
@@ -878,7 +921,10 @@ bool CPlatformNetworkManagerWindows::_StartGame() {
|
||||
|
||||
int CPlatformNetworkManagerWindows::JoinGame(FriendSessionInfo* searchResult, int localUsersMask, int primaryUserIndex) {
|
||||
if (searchResult == nullptr || primaryUserIndex < 0 || primaryUserIndex >= XUSER_MAX_COUNT) return CGameNetworkManager::JOINGAME_FAIL_GENERAL;
|
||||
if (searchResult->isFriendGame && !ResolveFriendSession(searchResult)) return CGameNetworkManager::JOINGAME_FAIL_GENERAL;
|
||||
|
||||
m_joinHost.clear();
|
||||
m_joinPort = 0;
|
||||
sockaddr_in address;
|
||||
if (searchResult->sessionId == LOCAL_SESSION_ID) {
|
||||
memset(&address, 0, sizeof(address));
|
||||
@@ -891,8 +937,13 @@ int CPlatformNetworkManagerWindows::JoinGame(FriendSessionInfo* searchResult, in
|
||||
} else if (searchResult->data.hostIP[0] != '\0' && searchResult->data.hostPort > 0) {
|
||||
if (!ResolveIPv4(searchResult->data.hostIP, static_cast<unsigned short>(searchResult->data.hostPort), &address))
|
||||
return CGameNetworkManager::JOINGAME_FAIL_GENERAL;
|
||||
m_joinHost = searchResult->data.hostIP;
|
||||
m_joinPort = searchResult->data.hostPort;
|
||||
} else if (!GetLanAddress(searchResult->sessionId, &address)) {
|
||||
return CGameNetworkManager::JOINGAME_FAIL_GENERAL;
|
||||
} else {
|
||||
m_joinHost = inet_ntoa(address.sin_addr);
|
||||
m_joinPort = ntohs(address.sin_port);
|
||||
}
|
||||
|
||||
SetLocalGame(true);
|
||||
@@ -1174,6 +1225,37 @@ std::vector<FriendSessionInfo*>* CPlatformNetworkManagerWindows::GetSessionList(
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef MINECRAFT_SERVER_BUILD
|
||||
{
|
||||
static DWORD s_lastGamesRefresh = 0;
|
||||
DWORD tick = GetTickCount();
|
||||
if (s_lastGamesRefresh == 0 || tick - s_lastGamesRefresh >= 10000) {
|
||||
s_lastGamesRefresh = tick;
|
||||
SocialOnlineService::RefreshFriendGames();
|
||||
}
|
||||
for (const SocialOnlineService::FriendGame& game : SocialOnlineService::GetFriendGames()) {
|
||||
unsigned long long onlineId = _wcstoui64(game.onlineId.c_str(), nullptr, 16);
|
||||
if (onlineId == 0 || onlineId == SocialOnlineService::GetJoinOnlineId()) continue;
|
||||
std::wstring label = game.username;
|
||||
if (!game.worldName.empty()) label += L" - " + game.worldName;
|
||||
if (!game.viaFriend.empty()) label += L" (via " + game.viaFriend + L")";
|
||||
if (SocialOnlineService::HasRecentInviteFrom(onlineId)) label += L" (Invited)";
|
||||
FriendSessionInfo* sessionInfo = new FriendSessionInfo();
|
||||
SetSessionLabel(sessionInfo, label.c_str(), static_cast<SessionID>(onlineId));
|
||||
sessionInfo->isFriendGame = true;
|
||||
sessionInfo->data.netVersion = MINECRAFT_NET_VERSION;
|
||||
sessionInfo->data.isReadyToJoin = true;
|
||||
sessionInfo->data.isJoinable = true;
|
||||
sessionInfo->data.hostIP[0] = '\0';
|
||||
sessionInfo->data.hostPort = 0;
|
||||
wcsncpy_s(sessionInfo->data.hostName, XUSER_NAME_SIZE, game.username.c_str(), _TRUNCATE);
|
||||
sessionInfo->data.playerCount = static_cast<unsigned char>(game.playerCount);
|
||||
sessionInfo->data.maxPlayers = static_cast<unsigned char>(game.maxPlayers);
|
||||
sessions->push_back(sessionInfo);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_winsockStarted) return sessions;
|
||||
|
||||
SOCKET querySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
@@ -1324,6 +1406,7 @@ bool CPlatformNetworkManagerWindows::GetGameSessionInfo(int iPad, SessionID sess
|
||||
SetSessionLabel(foundSession, L"Localhost", LOCAL_SESSION_ID);
|
||||
return true;
|
||||
}
|
||||
if (foundSession->isFriendGame && foundSession->data.hostIP[0] == '\0' && !ResolveFriendSession(foundSession)) return false;
|
||||
if (!IsLanSessionId(sessionId) &&
|
||||
(foundSession->data.hostIP[0] == '\0' || foundSession->data.hostPort <= 0)) return false;
|
||||
|
||||
@@ -1338,6 +1421,8 @@ void CPlatformNetworkManagerWindows::SetSessionsUpdatedCallback(void (*SessionsU
|
||||
}
|
||||
|
||||
void CPlatformNetworkManagerWindows::GetFullFriendSessionInfo(FriendSessionInfo* foundSession, void (*FriendSessionUpdatedFn)(bool success, void* pParam), void* pParam) {
|
||||
if (foundSession != nullptr && foundSession->isFriendGame && foundSession->data.hostIP[0] == '\0')
|
||||
ResolveFriendSession(foundSession);
|
||||
bool hasSavedAddress = foundSession != nullptr && foundSession->data.hostIP[0] != '\0' && foundSession->data.hostPort > 0;
|
||||
bool success = foundSession != nullptr &&
|
||||
(foundSession->sessionId == LOCAL_SESSION_ID || IsLanSessionId(foundSession->sessionId) || hasSavedAddress);
|
||||
|
||||
Reference in new issue
Block a user