fix: networking fixes + add server

This commit is contained in:
2026-09-25 13:43:05 +01:00
parent faf3a3edea
commit d24c73d4c7
13 changed files with 129 additions and 36 deletions
@@ -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 = @(
@@ -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
@@ -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;
@@ -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__
+3 -5
View File
@@ -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())
{
+1 -1
View File
@@ -76,7 +76,7 @@ using namespace DirectX;
#include <windows.h>
#include <malloc.h>
#include <tchar.h>
#include "Windows64Stubs.h"
#include "..\Minecraft.Client\Windows64\Windows64Extras\Windows64Stubs.h"
#define HRESULT_SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#endif
+1 -1
View File
@@ -121,7 +121,7 @@
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>powershell -ExecutionPolicy Bypass -File "../Minecraft.Client/Common/Postbuilds/Server-postbuild.ps1" -OutDir "$(OutDir)/" -ProjectDir "$(ProjectDir)/"</Command>
<Command>powershell -ExecutionPolicy Bypass -File "../Minecraft.Client/Common/Buildsteps/Server-postbuild.ps1" -OutDir "$(OutDir)/" -ProjectDir "$(ProjectDir)/"</Command>
<Message>Run Server postbuild script</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
+1 -1
View File
@@ -195,7 +195,7 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<ExceptionsAndRtti>WithExceptsWithRtti</ExceptionsAndRtti>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>SNC</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PSVita'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
-2
View File
@@ -333,8 +333,6 @@ shared_ptr<Packet> 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);