diff options
| author | ModMaker101 <119018978+ModMaker101@users.noreply.github.com> | 2026-03-08 19:08:36 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-08 18:08:36 -0500 |
| commit | 28614b922fb77149a54da1a87bebfbc98736f296 (patch) | |
| tree | 7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp | |
| parent | 88798b501d0cf6287b6f87acb2592676e3cec58d (diff) | |
Modernize project codebase (#906)
* Fixed boats falling and a TP glitch #266
* Replaced every C-style cast with C++ ones
* Replaced every C-style cast with C++ ones
* Fixed boats falling and a TP glitch #266
* Updated NULL to nullptr and fixing some type issues
* Modernized and fixed a few bugs
- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.
* Fixing more conflicts
* Replace int loops with size_t and start work on overrides
* Add safety checks and fix a issue with vector going OOR
Diffstat (limited to 'Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp')
| -rw-r--r-- | Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index 3d088935..b32cc934 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -26,7 +26,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) bool createFakeSocket = false; bool localPlayer = false; - NetworkPlayerXbox *networkPlayer = (NetworkPlayerXbox *)addNetworkPlayer(pQNetPlayer); + NetworkPlayerXbox *networkPlayer = static_cast<NetworkPlayerXbox *>(addNetworkPlayer(pQNetPlayer)); if( pQNetPlayer->IsLocal() ) { @@ -90,8 +90,8 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) pQNetPlayer, pQNetPlayer->GetGamertag(), pszDescription, - (int) pQNetPlayer->HasVoice(), - (int) pQNetPlayer->HasCamera() ); + pQNetPlayer->HasVoice(), + pQNetPlayer->HasCamera() ); if( m_pIQNet->IsHost() ) @@ -103,7 +103,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) for( int idx = 0; idx < XUSER_MAX_COUNT; ++idx) { - if(playerChangedCallback[idx] != NULL) + if(playerChangedCallback[idx] != nullptr) playerChangedCallback[idx]( playerChangedCallbackParam[idx], networkPlayer, false ); } @@ -112,7 +112,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) int localPlayerCount = 0; for(unsigned int idx = 0; idx < XUSER_MAX_COUNT; ++idx) { - if( m_pIQNet->GetLocalPlayerByUserIndex(idx) != NULL ) ++localPlayerCount; + if( m_pIQNet->GetLocalPlayerByUserIndex(idx) != nullptr ) ++localPlayerCount; } float appTime = app.getAppTime(); @@ -127,11 +127,11 @@ void CPlatformNetworkManagerStub::NotifyPlayerLeaving(IQNetPlayer* pQNetPlayer) app.DebugPrintf("Player 0x%p \"%ls\" leaving.\n", pQNetPlayer, pQNetPlayer->GetGamertag()); INetworkPlayer* networkPlayer = getNetworkPlayer(pQNetPlayer); - if (networkPlayer == NULL) + if (networkPlayer == nullptr) return; Socket* socket = networkPlayer->GetSocket(); - if (socket != NULL) + if (socket != nullptr) { if (m_pIQNet->IsHost()) g_NetworkManager.CloseConnection(networkPlayer); @@ -146,7 +146,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerLeaving(IQNetPlayer* pQNetPlayer) for (int idx = 0; idx < XUSER_MAX_COUNT; ++idx) { - if (playerChangedCallback[idx] != NULL) + if (playerChangedCallback[idx] != nullptr) playerChangedCallback[idx](playerChangedCallbackParam[idx], networkPlayer, true); } @@ -162,7 +162,7 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa g_pPlatformNetworkManager = this; for( int i = 0; i < XUSER_MAX_COUNT; i++ ) { - playerChangedCallback[ i ] = NULL; + playerChangedCallback[ i ] = nullptr; } m_bLeavingGame = false; @@ -173,8 +173,8 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa m_bSearchPending = false; m_bIsOfflineGame = false; - m_pSearchParam = NULL; - m_SessionsUpdatedCallback = NULL; + m_pSearchParam = nullptr; + m_SessionsUpdatedCallback = nullptr; for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) { @@ -182,10 +182,10 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa m_lastSearchStartTime[i] = 0; // The results that will be filled in with the current search - m_pSearchResults[i] = NULL; - m_pQoSResult[i] = NULL; - m_pCurrentSearchResults[i] = NULL; - m_pCurrentQoSResult[i] = NULL; + m_pSearchResults[i] = nullptr; + m_pQoSResult[i] = nullptr; + m_pCurrentSearchResults[i] = nullptr; + m_pCurrentQoSResult[i] = nullptr; m_currentSearchResultsCount[i] = 0; } @@ -231,7 +231,7 @@ void CPlatformNetworkManagerStub::DoWork() while (WinsockNetLayer::PopDisconnectedSmallId(&disconnectedSmallId)) { IQNetPlayer* qnetPlayer = m_pIQNet->GetPlayerBySmallId(disconnectedSmallId); - if (qnetPlayer != NULL && qnetPlayer->m_smallId == disconnectedSmallId) + if (qnetPlayer != nullptr && qnetPlayer->m_smallId == disconnectedSmallId) { NotifyPlayerLeaving(qnetPlayer); qnetPlayer->m_smallId = 0; @@ -254,7 +254,7 @@ void CPlatformNetworkManagerStub::DoWork() // old Connection threads are dead. // // Clear chunk visibility flags for this system so rejoin gets fresh chunk state. - SystemFlagRemoveBySmallId((int)disconnectedSmallId); + SystemFlagRemoveBySmallId(disconnectedSmallId); } } #endif @@ -267,7 +267,7 @@ bool CPlatformNetworkManagerStub::CanAcceptMoreConnections() if (server == NULL) return true; PlayerList* list = server->getPlayerList(); if (list == NULL) return true; - return (unsigned int)list->players.size() < (unsigned int)list->getMaxPlayers(); + return static_cast<unsigned int>(list->players.size()) < static_cast<unsigned int>(list->getMaxPlayers()); #else return true; #endif @@ -420,7 +420,7 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, #ifdef _WINDOWS64 int port = WIN64_NET_DEFAULT_PORT; - const char* bindIp = NULL; + const char* bindIp = nullptr; if (g_Win64DedicatedServer) { if (g_Win64DedicatedServerPort > 0) @@ -453,7 +453,7 @@ bool CPlatformNetworkManagerStub::_StartGame() int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo* searchResult, int localUsersMask, int primaryUserIndex) { #ifdef _WINDOWS64 - if (searchResult == NULL) + if (searchResult == nullptr) return CGameNetworkManager::JOINGAME_FAIL_GENERAL; const char* hostIP = searchResult->data.hostIP; @@ -527,8 +527,8 @@ void CPlatformNetworkManagerStub::UnRegisterPlayerChangedCallback(int iPad, void { if(playerChangedCallbackParam[iPad] == callbackParam) { - playerChangedCallback[iPad] = NULL; - playerChangedCallbackParam[iPad] = NULL; + playerChangedCallback[iPad] = nullptr; + playerChangedCallbackParam[iPad] = nullptr; } } @@ -548,7 +548,7 @@ bool CPlatformNetworkManagerStub::_RunNetworkGame() if (IQNet::m_player[i].m_isRemote) { INetworkPlayer* pNetworkPlayer = getNetworkPlayer(&IQNet::m_player[i]); - if (pNetworkPlayer != NULL && pNetworkPlayer->GetSocket() != NULL) + if (pNetworkPlayer != nullptr && pNetworkPlayer->GetSocket() != nullptr) { Socket::addIncomingSocket(pNetworkPlayer->GetSocket()); } @@ -558,14 +558,14 @@ bool CPlatformNetworkManagerStub::_RunNetworkGame() return true; } -void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving /*= NULL*/) +void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving /*= nullptr*/) { // DWORD playerCount = m_pIQNet->GetPlayerCount(); // // if( this->m_bLeavingGame ) // return; // -// if( GetHostPlayer() == NULL ) +// if( GetHostPlayer() == nullptr ) // return; // // for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) @@ -585,13 +585,13 @@ void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pN // } // else // { -// m_hostGameSessionData.players[i] = NULL; +// m_hostGameSessionData.players[i] = nullptr; // memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE); // } // } // else // { -// m_hostGameSessionData.players[i] = NULL; +// m_hostGameSessionData.players[i] = nullptr; // memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE); // } // } @@ -602,18 +602,18 @@ void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pN int CPlatformNetworkManagerStub::RemovePlayerOnSocketClosedThreadProc( void* lpParam ) { - INetworkPlayer *pNetworkPlayer = (INetworkPlayer *)lpParam; + INetworkPlayer *pNetworkPlayer = static_cast<INetworkPlayer *>(lpParam); Socket *socket = pNetworkPlayer->GetSocket(); - if( socket != NULL ) + if( socket != nullptr ) { //printf("Waiting for socket closed event\n"); socket->m_socketClosedEvent->WaitForSignal(INFINITE); //printf("Socket closed event has fired\n"); // 4J Stu - Clear our reference to this socket - pNetworkPlayer->SetSocket( NULL ); + pNetworkPlayer->SetSocket( nullptr ); delete socket; } @@ -635,7 +635,7 @@ CPlatformNetworkManagerStub::PlayerFlags::PlayerFlags(INetworkPlayer *pNetworkPl this->flags = new unsigned char [ count / 8 ]; memset( this->flags, 0, count / 8 ); this->count = count; - this->m_smallId = (pNetworkPlayer && pNetworkPlayer->IsLocal()) ? 256 : (pNetworkPlayer ? (int)pNetworkPlayer->GetSmallId() : -1); + this->m_smallId = (pNetworkPlayer && pNetworkPlayer->IsLocal()) ? 256 : (pNetworkPlayer ? static_cast<int>(pNetworkPlayer->GetSmallId()) : -1); } CPlatformNetworkManagerStub::PlayerFlags::~PlayerFlags() { @@ -703,7 +703,7 @@ void CPlatformNetworkManagerStub::SystemFlagReset() void CPlatformNetworkManagerStub::SystemFlagSet(INetworkPlayer *pNetworkPlayer, int index) { if( ( index < 0 ) || ( index >= m_flagIndexSize ) ) return; - if( pNetworkPlayer == NULL ) return; + if( pNetworkPlayer == nullptr ) return; for( unsigned int i = 0; i < m_playerFlags.size(); i++ ) { @@ -719,7 +719,7 @@ void CPlatformNetworkManagerStub::SystemFlagSet(INetworkPlayer *pNetworkPlayer, bool CPlatformNetworkManagerStub::SystemFlagGet(INetworkPlayer *pNetworkPlayer, int index) { if( ( index < 0 ) || ( index >= m_flagIndexSize ) ) return false; - if( pNetworkPlayer == NULL ) + if( pNetworkPlayer == nullptr ) { return false; } @@ -747,7 +747,7 @@ wstring CPlatformNetworkManagerStub::GatherRTTStats() for(unsigned int i = 0; i < GetPlayerCount(); ++i) { - IQNetPlayer *pQNetPlayer = ((NetworkPlayerXbox *)GetPlayerByIndex( i ))->GetQNetPlayer(); + IQNetPlayer *pQNetPlayer = static_cast<NetworkPlayerXbox *>(GetPlayerByIndex(i))->GetQNetPlayer(); if(!pQNetPlayer->IsLocal()) { @@ -762,7 +762,7 @@ wstring CPlatformNetworkManagerStub::GatherRTTStats() void CPlatformNetworkManagerStub::TickSearch() { #ifdef _WINDOWS64 - if (m_SessionsUpdatedCallback == NULL) + if (m_SessionsUpdatedCallback == nullptr) return; static DWORD lastSearchTime = 0; @@ -791,7 +791,7 @@ void CPlatformNetworkManagerStub::SearchForGames() size_t nameLen = wcslen(lanSessions[i].hostName); info->displayLabel = new wchar_t[nameLen + 1]; wcscpy_s(info->displayLabel, nameLen + 1, lanSessions[i].hostName); - info->displayLabelLength = (unsigned char)nameLen; + info->displayLabelLength = static_cast<unsigned char>(nameLen); info->displayLabelViewableStartIndex = 0; info->data.netVersion = lanSessions[i].netVersion; @@ -806,14 +806,13 @@ void CPlatformNetworkManagerStub::SearchForGames() info->data.playerCount = lanSessions[i].playerCount; info->data.maxPlayers = lanSessions[i].maxPlayers; - info->sessionId = (SessionID)((uint64_t)inet_addr(lanSessions[i].hostIP) | ((uint64_t)lanSessions[i].hostPort << 32)); + info->sessionId = static_cast<uint64_t>(inet_addr(lanSessions[i].hostIP)) | + static_cast<uint64_t>(lanSessions[i].hostPort) << 32; friendsSessions[0].push_back(info); } - std::FILE* file = std::fopen("servers.db", "rb"); - - if (file) { + if (std::FILE* file = std::fopen("servers.db", "rb")) { char magic[4] = {}; if (std::fread(magic, 1, 4, file) == 4 && memcmp(magic, "MCSV", 4) == 0) { @@ -831,7 +830,6 @@ void CPlatformNetworkManagerStub::SearchForGames() char ipBuf[257] = {}; if (std::fread(ipBuf, 1, ipLen, file) != ipLen) break; - if (std::fread(&port, sizeof(uint16_t), 1, file) != 1) break; if (std::fread(&nameLen, sizeof(uint16_t), 1, file) != 1) break; @@ -849,13 +847,13 @@ void CPlatformNetworkManagerStub::SearchForGames() size_t nLen = wName.length(); info->displayLabel = new wchar_t[nLen + 1]; wcscpy_s(info->displayLabel, nLen + 1, wName.c_str()); - info->displayLabelLength = (unsigned char)nLen; + info->displayLabelLength = static_cast<unsigned char>(nLen); info->displayLabelViewableStartIndex = 0; info->data.isReadyToJoin = true; info->data.isJoinable = true; strncpy_s(info->data.hostIP, sizeof(info->data.hostIP), ipBuf, _TRUNCATE); info->data.hostPort = port; - info->sessionId = (SessionID)(static_cast<uint64_t>(inet_addr(ipBuf)) | (static_cast<uint64_t>(port) << 32)); + info->sessionId = static_cast<uint64_t>(inet_addr(ipBuf)) | static_cast<uint64_t>(port) << 32; friendsSessions[0].push_back(info); } } @@ -863,9 +861,9 @@ void CPlatformNetworkManagerStub::SearchForGames() std::fclose(file); } - m_searchResultsCount[0] = (int)friendsSessions[0].size(); + m_searchResultsCount[0] = static_cast<int>(friendsSessions[0].size()); - if (m_SessionsUpdatedCallback != NULL) + if (m_SessionsUpdatedCallback != nullptr) m_SessionsUpdatedCallback(m_pSearchParam); #endif } @@ -913,7 +911,7 @@ void CPlatformNetworkManagerStub::ForceFriendsSessionRefresh() m_searchResultsCount[i] = 0; m_lastSearchStartTime[i] = 0; delete m_pSearchResults[i]; - m_pSearchResults[i] = NULL; + m_pSearchResults[i] = nullptr; } } @@ -940,7 +938,7 @@ void CPlatformNetworkManagerStub::removeNetworkPlayer(IQNetPlayer *pQNetPlayer) INetworkPlayer *CPlatformNetworkManagerStub::getNetworkPlayer(IQNetPlayer *pQNetPlayer) { - return pQNetPlayer ? (INetworkPlayer *)(pQNetPlayer->GetCustomDataValue()) : NULL; + return pQNetPlayer ? (INetworkPlayer *)(pQNetPlayer->GetCustomDataValue()) : nullptr; } |
