diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 769dbfee9..ba40b43ee 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -832,9 +832,10 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) #ifdef _WINDOWS64 { - IQNetPlayer* matchedQNetPlayer = NULL; + IQNetPlayer* matchedQNetPlayer = nullptr; PlayerUID pktXuid = player->getXuid(); const PlayerUID WIN64_XUID_BASE = (PlayerUID)0xe000d45248242f2e; + // Legacy compatibility path for peers still using embedded smallId XUIDs. if (pktXuid >= WIN64_XUID_BASE && pktXuid < WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS) { BYTE smallId = (BYTE)(pktXuid - WIN64_XUID_BASE); @@ -847,25 +848,26 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) } // Current Win64 path: identify QNet player by name and attach packet XUID. - if (matchedQNetPlayer == NULL) + if (matchedQNetPlayer == nullptr) { for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { BYTE smallId = static_cast(i); INetworkPlayer* np = g_NetworkManager.GetPlayerBySmallId(smallId); - if (np == NULL) + if (np == nullptr) continue; NetworkPlayerXbox* npx = (NetworkPlayerXbox*)np; IQNetPlayer* qp = npx->GetQNetPlayer(); - if (qp != NULL && _wcsicmp(qp->m_gamertag, packet->name.c_str()) == 0) + if (qp != nullptr && _wcsicmp(qp->m_gamertag, packet->name.c_str()) == 0) { - wcsncpy_s(qp->m_gamertag, 32, packet->name.c_str(), _TRUNCATE); + matchedQNetPlayer = qp; + break; } } } - if (matchedQNetPlayer != NULL) + if (matchedQNetPlayer != nullptr) { // Store packet-authoritative XUID on this network slot so later lookups by XUID // (e.g. remove player, display mapping) work for both legacy and uid.dat clients. diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index cd0c568d6..0d9674fbc 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -5,6 +5,7 @@ #include "..\..\Xbox\Network\NetworkPlayerXbox.h" #ifdef _WINDOWS64 #include "..\..\Windows64\Network\WinsockNetLayer.h" +#include "..\..\Windows64\Windows64_Xuid.h" #include "..\..\Minecraft.h" #include "..\..\User.h" #include "..\..\MinecraftServer.h" @@ -236,6 +237,7 @@ void CPlatformNetworkManagerStub::DoWork() qnetPlayer->m_smallId = 0; qnetPlayer->m_isRemote = false; qnetPlayer->m_isHostPlayer = false; + qnetPlayer->m_resolvedXuid = INVALID_XUID; qnetPlayer->m_gamertag[0] = 0; qnetPlayer->SetCustomDataValue(0); if (IQNet::s_playerCount > 1) @@ -408,7 +410,9 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, #ifdef _WINDOWS64 IQNet::m_player[0].m_smallId = 0; IQNet::m_player[0].m_isRemote = false; + // world host is pinned to legacy host XUID to keep old player data compatibility. IQNet::m_player[0].m_isHostPlayer = true; + IQNet::m_player[0].m_resolvedXuid = Win64Xuid::GetLegacyEmbeddedHostXuid(); IQNet::s_playerCount = 1; #endif @@ -465,6 +469,8 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo* searchResult, int l IQNet::m_player[0].m_smallId = 0; IQNet::m_player[0].m_isRemote = true; IQNet::m_player[0].m_isHostPlayer = true; + // Remote host still maps to legacy host XUID in mixed old/new sessions. + IQNet::m_player[0].m_resolvedXuid = Win64Xuid::GetLegacyEmbeddedHostXuid(); wcsncpy_s(IQNet::m_player[0].m_gamertag, 32, searchResult->data.hostName, _TRUNCATE); WinsockNetLayer::StopDiscovery(); @@ -480,6 +486,8 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo* searchResult, int l IQNet::m_player[localSmallId].m_smallId = localSmallId; IQNet::m_player[localSmallId].m_isRemote = false; IQNet::m_player[localSmallId].m_isHostPlayer = false; + // Local non-host identity is the persistent uid.dat XUID. + IQNet::m_player[localSmallId].m_resolvedXuid = Win64Xuid::ResolvePersistentXuid(); Minecraft* pMinecraft = Minecraft::GetInstance(); wcscpy_s(IQNet::m_player[localSmallId].m_gamertag, 32, pMinecraft->user->name.c_str()); @@ -853,7 +861,7 @@ void CPlatformNetworkManagerStub::SearchForGames() std::fclose(file); } - m_searchResultsCount[0] = (int)friendsSessions[0].size(); + m_searchResultsCount[0] = static_cast(friendsSessions[0].size()); if (m_SessionsUpdatedCallback != nullptr) m_SessionsUpdatedCallback(m_pSearchParam); diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 436b4ab2d..67436d05e 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -747,7 +747,7 @@ void Minecraft::run() while (System::currentTimeMillis() >= lastTime + 1000) { - fpsString = std::to_wstring(frames) + L" fps, " + std::to_wstring(Chunk::updates) + L" chunk updates)"; + fpsString = std::to_wstring(frames) + L" fps (" + std::to_wstring(Chunk::updates) + L" chunk updates)"; Chunk::updates = 0; lastTime += 1000; frames = 0; @@ -2084,7 +2084,7 @@ void Minecraft::run_middle() while (System::nanoTime() >= lastTime + 1000000000) { MemSect(31); - fpsString = std::to_wstring(frames) + L" fps," + std::to_wstring(Chunk::updates) + L" chunk updates"; + fpsString = std::to_wstring(frames) + L" fps (" + std::to_wstring(Chunk::updates) + L" chunk updates)"; MemSect(0); Chunk::updates = 0; lastTime += 1000000000; diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 405a287fa..763e6ac43 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -68,15 +68,15 @@ //4J Added MinecraftServer *MinecraftServer::server = nullptr; bool MinecraftServer::setTimeAtEndOfTick = false; -__int64 MinecraftServer::setTime = 0; +int64_t MinecraftServer::setTime = 0; bool MinecraftServer::setTimeOfDayAtEndOfTick = false; -__int64 MinecraftServer::setTimeOfDay = 0; +int64_t MinecraftServer::setTimeOfDay = 0; bool MinecraftServer::m_bPrimaryPlayerSignedOut=false; bool MinecraftServer::s_bServerHalted=false; bool MinecraftServer::s_bSaveOnExitAnswered=false; #ifdef _ACK_CHUNK_SEND_THROTTLING bool MinecraftServer::s_hasSentEnoughPackets = false; -__int64 MinecraftServer::s_tickStartTime = 0; +int64_t MinecraftServer::s_tickStartTime = 0; vector MinecraftServer::s_sentTo; #else int MinecraftServer::s_slowQueuePlayerIndex = 0; @@ -586,7 +586,7 @@ MinecraftServer::~MinecraftServer() DeleteCriticalSection(&m_consoleInputCS); } -bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DWORD initSettings, bool findSeed) +bool MinecraftServer::initServer(int64_t seed, NetworkGameInitData *initData, DWORD initSettings, bool findSeed) { // 4J - removed #if 0 @@ -703,7 +703,7 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW // TODO: Stop loading, add error message. } - __int64 levelNanoTime = System::nanoTime(); + int64_t levelNanoTime = System::nanoTime(); wstring levelName = (initData && !initData->levelName.empty()) ? initData->levelName : GetDedicatedServerString(settings, L"level-name", L"world"); wstring levelTypeString; @@ -747,10 +747,10 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW #if 0 wstring levelSeedString = settings->getString(L"level-seed", L""); - __int64 levelSeed = (new Random())->nextLong(); + int64_t levelSeed = (new Random())->nextLong(); if (levelSeedString.length() > 0) { - long newSeed = _fromString<__int64>(levelSeedString); + long newSeed = _fromString(levelSeedString); if (newSeed != 0) { levelSeed = newSeed; } @@ -877,7 +877,7 @@ void MinecraftServer::postProcessTerminate(ProgressRenderer *mcprogress) DeleteCriticalSection(&m_postProcessCS); } -bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring& name, __int64 levelSeed, LevelType *pLevelType, NetworkGameInitData *initData) +bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring& name, int64_t levelSeed, LevelType *pLevelType, NetworkGameInitData *initData) { // 4J - TODO - do with new save stuff // if (storageSource->requiresConversion(name)) @@ -1027,7 +1027,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring m_postUpdateThread->SetPriority(THREAD_PRIORITY_ABOVE_NORMAL); m_postUpdateThread->Run(); - __int64 startTime = System::currentTimeMillis(); + int64_t startTime = System::currentTimeMillis(); // 4J Stu - Added this to temporarily make starting games on vita faster #ifdef __PSVITA__ @@ -1057,7 +1057,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring csf->closeHandle(fe); } - __int64 lastTime = System::currentTimeMillis(); + int64_t lastTime = System::currentTimeMillis(); #ifdef _LARGE_WORLDS if(app.GetGameNewWorldSize() > levels[0]->getLevelData()->getXZSizeOld()) { @@ -1085,7 +1085,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring } #if 0 - __int64 lastStorageTickTime = System::currentTimeMillis(); + int64_t lastStorageTickTime = System::currentTimeMillis(); // Test code to enable full creation of levels at start up int halfsidelen = ( i == 0 ) ? 27 : 9; @@ -1108,7 +1108,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring } } #else - __int64 lastStorageTickTime = System::currentTimeMillis(); + int64_t lastStorageTickTime = System::currentTimeMillis(); Pos *spawnPos = level->getSharedSpawnPos(); int twoRPlusOne = r*2 + 1; @@ -1125,7 +1125,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring return false; } // printf(">>>%d %d %d\n",i,x,z); - // __int64 now = System::currentTimeMillis(); + // int64_t now = System::currentTimeMillis(); // if (now < lastTime) lastTime = now; // if (now > lastTime + 1000) { @@ -1700,7 +1700,7 @@ bool MinecraftServer::getForceGameType() return forceGameType; } -__int64 MinecraftServer::getCurrentTimeMillis() +int64_t MinecraftServer::getCurrentTimeMillis() { return System::currentTimeMillis(); } @@ -1716,7 +1716,7 @@ void MinecraftServer::setPlayerIdleTimeout(int playerIdleTimeout) } extern int c0a, c0b, c1a, c1b, c1c, c2a, c2b; -void MinecraftServer::run(__int64 seed, void *lpParameter) +void MinecraftServer::run(int64_t seed, void *lpParameter) { NetworkGameInitData *initData = nullptr; DWORD initSettings = 0; @@ -1749,18 +1749,18 @@ void MinecraftServer::run(__int64 seed, void *lpParameter) } } - __int64 lastTime = getCurrentTimeMillis(); - __int64 unprocessedTime = 0; + int64_t lastTime = getCurrentTimeMillis(); + int64_t unprocessedTime = 0; while (running && !s_bServerHalted) { - __int64 now = getCurrentTimeMillis(); + int64_t now = getCurrentTimeMillis(); // 4J Stu - When we pause the server, we don't want to count that as time passed // 4J Stu - TU-1 hotifx - Remove this line. We want to make sure that we tick connections at the proper rate when paused //Fix for #13191 - The host of a game can get a message informing them that the connection to the server has been lost //if(m_isServerPaused) lastTime = now; - __int64 passedTime = now - lastTime; + int64_t passedTime = now - lastTime; if (passedTime > MS_PER_TICK * 40) { // logger.warning("Can't keep up! Did the system time change, or is the server overloaded?"); @@ -1786,19 +1786,19 @@ void MinecraftServer::run(__int64 seed, void *lpParameter) else { // int tickcount = 0; - // __int64 beforeall = System::currentTimeMillis(); + // int64_t beforeall = System::currentTimeMillis(); while (unprocessedTime > MS_PER_TICK) { unprocessedTime -= MS_PER_TICK; chunkPacketManagement_PreTick(); -// __int64 before = System::currentTimeMillis(); +// int64_t before = System::currentTimeMillis(); tick(); -// __int64 after = System::currentTimeMillis(); +// int64_t after = System::currentTimeMillis(); // PIXReportCounter(L"Server time",(float)(after-before)); chunkPacketManagement_PostTick(); } -// __int64 afterall = System::currentTimeMillis(); +// int64_t afterall = System::currentTimeMillis(); // PIXReportCounter(L"Server time all",(float)(afterall-beforeall)); // PIXReportCounter(L"Server ticks",(float)tickcount); } @@ -2140,15 +2140,15 @@ void MinecraftServer::tick() players->broadcastAll(std::make_shared(level->getGameTime(), level->getDayTime(), level->getGameRules()->getBoolean(GameRules::RULE_DAYLIGHT)), level->dimension->id); } // #ifndef __PS3__ - static __int64 stc = 0; - __int64 st0 = System::currentTimeMillis(); + static int64_t stc = 0; + int64_t st0 = System::currentTimeMillis(); PIXBeginNamedEvent(0,"Level tick %d",i); - ((Level *)level)->tick(); + static_cast(level)->tick(); int64_t st1 = System::currentTimeMillis(); PIXEndNamedEvent(); PIXBeginNamedEvent(0,"Update lights %d",i); - __int64 st2 = System::currentTimeMillis(); + int64_t st2 = System::currentTimeMillis(); PIXEndNamedEvent(); PIXBeginNamedEvent(0,"Entity tick %d",i); // 4J added to stop ticking entities in levels when players are not in those levels. @@ -2176,7 +2176,7 @@ void MinecraftServer::tick() level->getTracker()->tick(); PIXEndNamedEvent(); - __int64 st3 = System::currentTimeMillis(); + int64_t st3 = System::currentTimeMillis(); // printf(">>>>>>>>>>>>>>>>>>>>>> Tick %d %d %d : %d\n", st1 - st0, st2 - st1, st3 - st2, st0 - stc ); stc = st0; // #endif// __PS3__ @@ -2231,7 +2231,7 @@ void MinecraftServer::handleConsoleInputs() } } -void MinecraftServer::main(__int64 seed, void *lpParameter) +void MinecraftServer::main(int64_t seed, void *lpParameter) { #if __PS3__ ShutdownManager::HasStarted(ShutdownManager::eServerThread ); @@ -2311,7 +2311,7 @@ bool MinecraftServer::chunkPacketManagement_CanSendTo(INetworkPlayer *player) void MinecraftServer::chunkPacketManagement_DidSendTo(INetworkPlayer *player) { - __int64 currentTime = System::currentTimeMillis(); + int64_t currentTime = System::currentTimeMillis(); if( ( currentTime - s_tickStartTime ) >= MAX_TICK_TIME_FOR_PACKET_SENDS ) { diff --git a/Minecraft.Client/MinecraftServer.h b/Minecraft.Client/MinecraftServer.h index 851dded27..f639ffc9b 100644 --- a/Minecraft.Client/MinecraftServer.h +++ b/Minecraft.Client/MinecraftServer.h @@ -31,14 +31,14 @@ class CommandDispatcher; typedef struct _LoadSaveDataThreadParam { LPVOID data; - __int64 fileSize; + int64_t fileSize; const wstring saveName; - _LoadSaveDataThreadParam(LPVOID data, __int64 filesize, const wstring &saveName) : data( data ), fileSize( filesize ), saveName( saveName ) {} + _LoadSaveDataThreadParam(LPVOID data, int64_t filesize, const wstring &saveName) : data( data ), fileSize( filesize ), saveName( saveName ) {} } LoadSaveDataThreadParam; typedef struct _NetworkGameInitData { - __int64 seed; + int64_t seed; LoadSaveDataThreadParam *saveData; DWORD settings; LevelGenerationOptions *levelGen; @@ -137,9 +137,9 @@ public: ~MinecraftServer(); private: // 4J Added - LoadSaveDataThreadParam - bool initServer(__int64 seed, NetworkGameInitData *initData, DWORD initSettings, bool findSeed); + bool initServer(int64_t seed, NetworkGameInitData *initData, DWORD initSettings, bool findSeed); void postProcessTerminate(ProgressRenderer *mcprogress); - bool loadLevel(LevelStorageSource *storageSource, const wstring& name, __int64 levelSeed, LevelType *pLevelType, NetworkGameInitData *initData); + bool loadLevel(LevelStorageSource *storageSource, const wstring& name, int64_t levelSeed, LevelType *pLevelType, NetworkGameInitData *initData); void setProgress(const wstring& status, int progress); void endProgress(); void saveGameRules(); @@ -176,13 +176,13 @@ public: bool isUnderSpawnProtection(Level *level, int x, int y, int z, shared_ptr player); void setForceGameType(bool forceGameType); bool getForceGameType(); - static __int64 getCurrentTimeMillis(); + static int64_t getCurrentTimeMillis(); int getPlayerIdleTimeout(); void setPlayerIdleTimeout(int playerIdleTimeout); public: void halt(); - void run(__int64 seed, void *lpParameter); + void run(int64_t seed, void *lpParameter); void broadcastStartSavingPacket(); void broadcastStopSavingPacket(); @@ -193,7 +193,7 @@ public: void handleConsoleInput(const wstring& msg, ConsoleInputSource *source); void handleConsoleInputs(); // void addTickable(Tickable tickable); // 4J removed - static void main(__int64 seed, void *lpParameter); + static void main(int64_t seed, void *lpParameter); static void HaltServer(bool bPrimaryPlayerSignedOut=false); File *getFile(const wstring& name); @@ -213,9 +213,9 @@ private: static MinecraftServer *server; static bool setTimeOfDayAtEndOfTick; - static __int64 setTimeOfDay; + static int64_t setTimeOfDay; static bool setTimeAtEndOfTick; - static __int64 setTime; + static int64_t setTime; static bool m_bPrimaryPlayerSignedOut; // 4J-PB added to tell the stopserver not to save the game - another player may have signed in in their place, so ProfileManager.IsSignedIn isn't enough static bool s_bServerHalted; // 4J Stu Added so that we can halt the server even before it's been created properly @@ -237,8 +237,7 @@ private: public: void addPostProcessRequest(ChunkSource *chunkSource, int x, int z); -public: - static PlayerList *getPlayerList() { if( server != NULL ) return server->players; else return NULL; } + static PlayerList *getPlayerList() { if( server != nullptr) return server->players; else return nullptr; } static void SetTimeOfDay(int64_t time) { setTimeOfDayAtEndOfTick = true; setTimeOfDay = time; } static void SetTime(int64_t time) { setTimeAtEndOfTick = true; setTime = time; } @@ -250,7 +249,7 @@ private: // 4J Added - A static that stores the QNet index of the player that is next allowed to send a packet in the slow queue #ifdef _ACK_CHUNK_SEND_THROTTLING static bool s_hasSentEnoughPackets; - static __int64 s_tickStartTime; + static int64_t s_tickStartTime; static vector s_sentTo; static const int MAX_TICK_TIME_FOR_PACKET_SENDS = 35; #else @@ -272,7 +271,7 @@ public: #ifndef _ACK_CHUNK_SEND_THROTTLING static void cycleSlowQueueIndex(); #endif - + void chunkPacketManagement_PreTick(); void chunkPacketManagement_PostTick(); @@ -280,5 +279,5 @@ public: void Suspend(); bool IsSuspending(); - // 4J Stu - A load of functions were all added in 1.0.1 in the ServerInterface, but I don't think we need any of them -}; \ No newline at end of file + // 4J Stu - A load of functions were all added in 1.0.1 in the ServerInterface, but I don't think we need any of them +}; diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index db8f2ab92..9672b2312 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -589,7 +589,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_CHAR: // Buffer typed characters so UIScene_Keyboard can dispatch them to the Iggy Flash player if (wParam >= 0x20 || wParam == 0x08 || wParam == 0x0D) // printable chars + backspace + enter - g_KBMInput.OnChar((wchar_t)wParam); + g_KBMInput.OnChar(static_cast(wParam)); break; case WM_KEYDOWN: @@ -620,12 +620,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) else if (vk == VK_MENU) vk = (lParam & (1 << 24)) ? VK_RMENU : VK_LMENU; g_KBMInput.OnKeyDown(vk); - break; + return DefWindowProc(hWnd, message, wParam, lParam); } case WM_KEYUP: case WM_SYSKEYUP: { - int vk = (int)wParam; + int vk = static_cast(wParam); if (vk == VK_SHIFT) vk = (MapVirtualKey((lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK_EX) == VK_RSHIFT) ? VK_RSHIFT : VK_LSHIFT; else if (vk == VK_CONTROL) @@ -1673,6 +1673,12 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, const Win64LaunchOptions launchOptions = ParseLaunchOptions(); ApplyScreenMode(launchOptions.screenMode); + // Ensure uid.dat exists from startup in client mode (before any multiplayer/login path). + if (!launchOptions.serverMode) + { + Win64Xuid::ResolvePersistentXuid(); + } + // If no username, let's fall back if (g_Win64Username[0] == 0) { @@ -2135,6 +2141,14 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } + // Open chat + if (g_KBMInput.IsKeyPressed('T') && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) + { + g_KBMInput.ClearCharBuffer(); + pMinecraft->setScreen(new ChatScreen()); + SetFocus(g_hWnd); + } + #if 0 // has the game defined profile data been changed (by a profile load) if(app.uiGameDefinedDataChangedBitmask!=0)