From 28614b922fb77149a54da1a87bebfbc98736f296 Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Sun, 8 Mar 2026 19:08:36 -0400 Subject: 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 --- Minecraft.World/Socket.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Minecraft.World/Socket.cpp') diff --git a/Minecraft.World/Socket.cpp b/Minecraft.World/Socket.cpp index 107fd884..2d5b257d 100644 --- a/Minecraft.World/Socket.cpp +++ b/Minecraft.World/Socket.cpp @@ -14,7 +14,7 @@ CRITICAL_SECTION Socket::s_hostQueueLock[2]; std::queue Socket::s_hostQueue[2]; Socket::SocketOutputStreamLocal *Socket::s_hostOutStream[2]; Socket::SocketInputStreamLocal *Socket::s_hostInStream[2]; -ServerConnection *Socket::s_serverConnection = NULL; +ServerConnection *Socket::s_serverConnection = nullptr; void Socket::Initialise(ServerConnection *serverConnection) { @@ -67,7 +67,7 @@ Socket::Socket(bool response) { m_endClosed[i] = false; } - m_socketClosedEvent = NULL; + m_socketClosedEvent = nullptr; createdOk = true; networkPlayerSmallId = g_NetworkManager.GetHostPlayer()->GetSmallId(); } @@ -80,8 +80,8 @@ Socket::Socket(INetworkPlayer *player, bool response /* = false*/, bool hostLoca for( int i = 0; i < 2; i++ ) { InitializeCriticalSection(&m_queueLockNetwork[i]); - m_inputStream[i] = NULL; - m_outputStream[i] = NULL; + m_inputStream[i] = nullptr; + m_outputStream[i] = nullptr; m_endClosed[i] = false; } @@ -105,7 +105,7 @@ Socket::Socket(INetworkPlayer *player, bool response /* = false*/, bool hostLoca SocketAddress *Socket::getRemoteSocketAddress() { - return NULL; + return nullptr; } INetworkPlayer *Socket::getPlayer() @@ -115,7 +115,7 @@ INetworkPlayer *Socket::getPlayer() void Socket::setPlayer(INetworkPlayer *player) { - if(player!=NULL) + if(player!=nullptr) { networkPlayerSmallId = player->GetSmallId(); } @@ -150,7 +150,7 @@ void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHos void Socket::addIncomingSocket(Socket *socket) { - if( s_serverConnection != NULL ) + if( s_serverConnection != nullptr ) { s_serverConnection->NewIncomingSocket(socket); } @@ -243,7 +243,7 @@ bool Socket::close(bool isServerConnection) allClosed = true; m_endClosed[m_end] = true; } - if( allClosed && m_socketClosedEvent != NULL ) + if( allClosed && m_socketClosedEvent != nullptr ) { m_socketClosedEvent->Set(); } @@ -334,7 +334,7 @@ void Socket::SocketOutputStreamLocal::write(unsigned int b) return; } EnterCriticalSection(&s_hostQueueLock[m_queueIdx]); - s_hostQueue[m_queueIdx].push((byte)b); + s_hostQueue[m_queueIdx].push(static_cast(b)); LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]); } @@ -447,7 +447,7 @@ void Socket::SocketOutputStreamNetwork::write(unsigned int b) if( m_streamOpen != true ) return; byteArray barray; byte bb; - bb = (byte)b; + bb = static_cast(b); barray.data = &bb; barray.length = 1; write(barray, 0, 1); @@ -493,15 +493,15 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, unsigned int buffer.dwDataSize = length; INetworkPlayer *hostPlayer = g_NetworkManager.GetHostPlayer(); - if(hostPlayer == NULL) + if(hostPlayer == nullptr) { - app.DebugPrintf("Trying to write to network, but the hostPlayer is NULL\n"); + app.DebugPrintf("Trying to write to network, but the hostPlayer is nullptr\n"); return; } INetworkPlayer *socketPlayer = m_socket->getPlayer(); - if(socketPlayer == NULL) + if(socketPlayer == nullptr) { - app.DebugPrintf("Trying to write to network, but the socketPlayer is NULL\n"); + app.DebugPrintf("Trying to write to network, but the socketPlayer is nullptr\n"); return; } @@ -522,7 +522,7 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, unsigned int hostPlayer->SendData(socketPlayer, buffer.pbyData, buffer.dwDataSize, lowPriority, requireAck); - // DWORD queueSize = hostPlayer->GetSendQueueSize( NULL, QNET_GETSENDQUEUESIZE_BYTES ); + // DWORD queueSize = hostPlayer->GetSendQueueSize( nullptr, QNET_GETSENDQUEUESIZE_BYTES ); // if( queueSize > 24000 ) // { // //printf("Queue size is: %d, forcing doWork()\n",queueSize); -- cgit v1.2.3