From d24c73d4c70a767a6104781b78eb56b2f8e9c34d Mon Sep 17 00:00:00 2001 From: piebot Date: Fri, 25 Sep 2026 13:43:05 +0100 Subject: [PATCH] fix: networking fixes + add server --- .../Common/Buildsteps/Server-postbuild.ps1 | 13 ++-- .../Common/Network/GameNetworkManager.cpp | 5 ++ .../Common/Network/GameNetworkManager.h | 1 + .../Common/Network/NetworkSocketLayer.cpp | 7 +- .../Common/Network/PlatformNetworkManager.cpp | 46 +++++++++++- .../Common/Network/PlatformNetworkManager.h | 2 + .../Common/UI/UIScene_LoadOrJoinMenu.cpp | 72 +++++++++++++++---- .../Common/UI/UIScene_LoadOrJoinMenu.h | 3 + Minecraft.Client/PS3/PS3_Minecraft.cpp | 8 +-- Minecraft.Client/stdafx.h | 2 +- Minecraft.Server/Minecraft.Server.vcxproj | 2 +- Minecraft.World/Minecraft.World.vcxproj | 2 +- Minecraft.World/Packet.cpp | 2 - 13 files changed, 129 insertions(+), 36 deletions(-) diff --git a/Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1 b/Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1 index d5d4e660..02a233af 100644 --- a/Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1 +++ b/Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1 @@ -32,17 +32,20 @@ foreach ($copy in $folderCopies) { } $fileCopies = @( - @{ Source = "Common\Postbuilds\Contents\Windows64\Effects.msscmp"; Dest = "Effects.msscmp" }, - @{ Source = "Common\Postbuilds\Contents\Windows64\iggy_w64.dll"; Dest = "iggy_w64.dll" }, - @{ Source = "Common\Postbuilds\Contents\Windows64\mss64.dll"; Dest = "mss64.dll" } + @{ Source = Join-Path "$ProjectDir\..\Minecraft.Client" "Windows64\4JLibs\4J_Input\Windows64\vendor\SDL\lib\x64\SDL3.dll"; Dest = "SDL3.dll" }, + @{ Source = "Common\Media\MediaWindows64.arc"; Dest = "Common\Media\MediaWindows64.arc" }, + @{ Source = Join-Path $PSScriptRoot "Contents\Windows64\mss64.dll"; Dest = "mss64.dll" }, + @{ Source = "Windows64\Iggy\lib\redist64\iggy_w64.dll"; Dest = "iggy_w64.dll" } ) foreach ($copy in $fileCopies) { - $src = Join-Path "$ProjectDir\..\Minecraft.Client" $copy.Source + $src = $copy.Source $dst = Join-Path $OutDir $copy.Dest if (Test-Path $src) { Copy-Item -Path $src -Destination $dst -Force - } + } else { + Write-Host "Server Postbuild: File not found, skipping: $src" + } } $deleteDirs = @( diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index db4ff7a8..c6cf5424 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -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() { diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.h b/Minecraft.Client/Common/Network/GameNetworkManager.h index 4c707ba8..91bf189b 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.h +++ b/Minecraft.Client/Common/Network/GameNetworkManager.h @@ -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; diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp index d30267b9..94586485 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp @@ -71,13 +71,8 @@ std::vector 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() diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp index aab08a09..20d37573 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp @@ -8,7 +8,7 @@ #include "..\..\Common\Network\NetworkSocketLayer.h" CPlatformNetworkManagerStub *g_pPlatformNetworkManager; - +std::vector 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 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) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.h b/Minecraft.Client/Common/Network/PlatformNetworkManager.h index dc7653ec..9adfe5b6 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.h +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.h @@ -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 diff --git a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp index 78e78959..51218243 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp @@ -14,7 +14,7 @@ #include "..\..\TexturePackRepository.h" #include "..\..\TexturePack.h" #include "..\Network\SessionInfo.h" -#include "..\..\Common\Network\NetworkSocketLayer.h" +#include "..\..\Common\Network\NetworkSocketLayer.h" #if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__) #include "Common\Network\Sony\SonyHttp.h" #include "Common\Network\Sony\SonyRemoteStorage.h" @@ -413,6 +413,8 @@ void UIScene_LoadOrJoinMenu::Initialise() m_iDefaultButtonsC = 0; m_iMashUpButtonsC=0; + m_iServerDefaultButtonsC = 0; + // Check if we're in the trial version if(ProfileManager.IsFullVersion()==false) { @@ -935,8 +937,13 @@ void UIScene_LoadOrJoinMenu::AddDefaultButtons() m_iMashUpButtonsC=0; m_generators.clear(); + m_iServerDefaultButtonsC = 0; m_buttonListSaves.addItem(app.GetString(IDS_CREATE_NEW_WORLD)); + + // hard-coded FOR NOW! + m_buttonListGames.addItem(L"Add Server"); m_iDefaultButtonsC++; + m_iServerDefaultButtonsC++; int i = 0; @@ -1391,23 +1398,43 @@ void UIScene_LoadOrJoinMenu::handlePress(F64 controlId, F64 childId) //CD - Added for audio ui.PlayUISFX(eSFX_Press); + int nIndex = (int)childId; + if(nIndex == ADD_SERVER_BUTTON_INDEX) { - int nIndex = (int)childId; - m_iGameListIndex = nIndex; - CheckAndJoinGame(nIndex); + InputManager.RequestKeyboard(app.GetString(IDS_SIGN_TITLE),L"192.168.",(DWORD)m_iPad,15,&UIScene_LoadOrJoinMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_IP_Address); + } + else + { + m_iGameListIndex = nIndex - m_iServerDefaultButtonsC; + CheckAndJoinGame(nIndex - m_iServerDefaultButtonsC); } - break; } } } +int UIScene_LoadOrJoinMenu::KeyboardCompleteCallback(LPVOID lpParam,bool bRes) +{ + // 4J HEG - No reason to set value if keyboard was cancelled + UIScene_LoadOrJoinMenu *pClass=(UIScene_LoadOrJoinMenu *)lpParam; + pClass->m_bIgnoreInput = false; + if (bRes) + { + uint16_t pchText[128]; + ZeroMemory(pchText, 128 * sizeof(uint16_t) ); + InputManager.GetText(pchText); + + CGameNetworkManager::AddServer((const wchar_t *)pchText, NETWORK_LAN_DEFAULT_PORT, (const wchar_t *)pchText); + } + return 0; +} + void UIScene_LoadOrJoinMenu::CheckAndJoinGame(int gameIndex) { if( m_buttonListGames.getItemCount() > 0 && gameIndex < m_currentSessions->size() ) { #if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__) - const bool bManualJoin = (g_MultiplayerJoin == true); + const bool bManualJoin = (g_MultiplayerJoin == true); // 4J-PB - is the player allowed to join games? bool noUGC=false; bool bContentRestricted=false; @@ -1686,10 +1713,14 @@ void UIScene_LoadOrJoinMenu::UpdateGamesList() FriendSessionInfo *pSelectedSession = NULL; - if(DoesGamesListHaveFocus() && m_buttonListGames.getItemCount() > 0) + unsigned int nIndex = 0; + if(DoesGamesListHaveFocus() && (m_buttonListGames.getItemCount() - m_iServerDefaultButtonsC) > 0) { - unsigned int nIndex = m_buttonListGames.getCurrentSelection(); - pSelectedSession = m_currentSessions->at( nIndex ); + nIndex = m_buttonListGames.getCurrentSelection(); + if (nIndex >= m_iServerDefaultButtonsC) + { + pSelectedSession = m_currentSessions->at( nIndex - m_iServerDefaultButtonsC ); + } } SessionID selectedSessionId; @@ -1714,7 +1745,7 @@ void UIScene_LoadOrJoinMenu::UpdateGamesList() BOOL gamesListHasFocus = DoesGamesListHaveFocus(); - if(filteredListSize > 0) + if(filteredListSize > 0 || m_iServerDefaultButtonsC > 0) { #if TO_BE_IMPLEMENTED if( !m_pGamesList->IsEnabled() ) @@ -1742,11 +1773,24 @@ void UIScene_LoadOrJoinMenu::UpdateGamesList() // clear out the games list and re-fill m_buttonListGames.clearList(); - if( filteredListSize > 0 ) + m_iServerDefaultButtonsC = 0; + m_buttonListGames.addItem(app.GetString(IDS_ACTION_BAN_LEVEL_TITLE)); + m_iServerDefaultButtonsC++; + + if( filteredListSize > 0 ) { // Reset the focus to the selected session if it still exists unsigned int sessionIndex = 0; - m_buttonListGames.setCurrentSelection(0); + + if (DoesGamesListHaveFocus()) + { + m_buttonListGames.setCurrentSelection( 0 ); + + if (nIndex >= m_iServerDefaultButtonsC) + { + m_buttonListGames.setCurrentSelection( nIndex ); + } + } for( AUTO_VAR(it, m_currentSessions->begin()); it < m_currentSessions->end(); ++it) { @@ -1807,9 +1851,9 @@ void UIScene_LoadOrJoinMenu::UpdateGamesList() m_buttonListGames.addItem( sessionInfo->displayLabel, textureName ); - if(memcmp( &selectedSessionId, &sessionInfo->sessionId, sizeof(SessionID) ) == 0) + if(memcmp( &selectedSessionId, &sessionInfo->sessionId, sizeof(SessionID) ) == 0 && DoesGamesListHaveFocus()) { - m_buttonListGames.setCurrentSelection(sessionIndex); + m_buttonListGames.setCurrentSelection(sessionIndex + m_iServerDefaultButtonsC); break; } ++sessionIndex; diff --git a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.h b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.h index 3d832f33..54a00fb6 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.h +++ b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.h @@ -43,6 +43,7 @@ private: eActions m_eAction; static const int JOIN_LOAD_CREATE_BUTTON_INDEX = 0; + static const int ADD_SERVER_BUTTON_INDEX = 0; SaveListDetails *m_saveDetails; int m_iSaveDetailsCount; @@ -73,6 +74,7 @@ private: #endif UI_END_MAP_ELEMENTS_AND_NAMES() + int m_iServerDefaultButtonsC; int m_iDefaultButtonsC; int m_iMashUpButtonsC; int m_iState; @@ -167,6 +169,7 @@ protected: void LoadSaveFromCloud(); #endif public: + static int KeyboardCompleteCallback(LPVOID lpParam,bool bRes); virtual void HandleDLCMountingComplete(); #ifdef __ORBIS__ diff --git a/Minecraft.Client/PS3/PS3_Minecraft.cpp b/Minecraft.Client/PS3/PS3_Minecraft.cpp index 9265e17b..1c8afc90 100644 --- a/Minecraft.Client/PS3/PS3_Minecraft.cpp +++ b/Minecraft.Client/PS3/PS3_Minecraft.cpp @@ -1031,11 +1031,6 @@ int main() while( ShutdownManager::ShouldRun(ShutdownManager::eMainThread) ) { - // PIEBOT: This previously was under SQRNetworkManager_PS3::Tick() - // It ticks all callbacks for SysUtil, including the ones used in INP_OnScreenKeyboard.cpp - // When we nuked SQRNetworkManager_PS3, We also unintentionally broke the on-screen keyboard. - - // TO-DO: put it under app.Tick(); cellSysutilCheckCallback(); app.UpdateTime(); @@ -1163,6 +1158,9 @@ int main() g_NetworkManager.DoWork(); PIXEndNamedEvent(); + // Any threading type things to deal with from the xui side? + app.HandleXuiActions(); + // 4J-PB - Update the trial timer display if we are in the trial version if(!ProfileManager.IsFullVersion()) { diff --git a/Minecraft.Client/stdafx.h b/Minecraft.Client/stdafx.h index 7409d4b0..a728cb1c 100644 --- a/Minecraft.Client/stdafx.h +++ b/Minecraft.Client/stdafx.h @@ -76,7 +76,7 @@ using namespace DirectX; #include #include #include -#include "Windows64Stubs.h" +#include "..\Minecraft.Client\Windows64\Windows64Extras\Windows64Stubs.h" #define HRESULT_SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) #endif diff --git a/Minecraft.Server/Minecraft.Server.vcxproj b/Minecraft.Server/Minecraft.Server.vcxproj index 330f822a..0d0abfbb 100644 --- a/Minecraft.Server/Minecraft.Server.vcxproj +++ b/Minecraft.Server/Minecraft.Server.vcxproj @@ -121,7 +121,7 @@ d3d11.lib;..\Minecraft.Client\x64_Server\Minecraft.Client.lib;..\Minecraft.World\x64_$(Configuration)\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;;XInput9_1_0.lib;Windows64\Miles\Lib\mss64.lib;wsock32.lib;%(AdditionalDependencies) - powershell -ExecutionPolicy Bypass -File "../Minecraft.Client/Common/Postbuilds/Server-postbuild.ps1" -OutDir "$(OutDir)/" -ProjectDir "$(ProjectDir)/" + powershell -ExecutionPolicy Bypass -File "../Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1" -OutDir "$(OutDir)/" -ProjectDir "$(ProjectDir)/" Run Server postbuild script diff --git a/Minecraft.World/Minecraft.World.vcxproj b/Minecraft.World/Minecraft.World.vcxproj index 1b978266..c4fa529e 100644 --- a/Minecraft.World/Minecraft.World.vcxproj +++ b/Minecraft.World/Minecraft.World.vcxproj @@ -195,7 +195,7 @@ StaticLibrary MultiByte WithExceptsWithRtti - v110 + SNC StaticLibrary diff --git a/Minecraft.World/Packet.cpp b/Minecraft.World/Packet.cpp index 0dbaf793..85341f17 100644 --- a/Minecraft.World/Packet.cpp +++ b/Minecraft.World/Packet.cpp @@ -333,8 +333,6 @@ shared_ptr Packet::readPacket(DataInputStream *dis, bool isServer) // th id = dis->read(); if (id == -1) return nullptr; - app.DebugPrintf("GOT PACKET ID: %d", id); - if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end())) { //app.DebugPrintf("Bad packet id %d\n", id);