aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Socket.cpp
diff options
context:
space:
mode:
authorqwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com>2026-03-16 21:44:26 -0500
committerGitHub <noreply@github.com>2026-03-16 21:44:26 -0500
commitce739f6045ec72127491286ea3f3f21e537c1b55 (patch)
treef33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /Minecraft.World/Socket.cpp
parent255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff)
parent5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff)
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.World/Socket.cpp')
-rw-r--r--Minecraft.World/Socket.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/Minecraft.World/Socket.cpp b/Minecraft.World/Socket.cpp
index bd0c2032..41ac3702 100644
--- a/Minecraft.World/Socket.cpp
+++ b/Minecraft.World/Socket.cpp
@@ -14,7 +14,7 @@ CRITICAL_SECTION Socket::s_hostQueueLock[2];
std::queue<byte> 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();
}
@@ -137,7 +137,15 @@ void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHos
return;
}
+ //app.DebugPrintf("SOCKET PUSH: %u bytes to queue[%d] firstByte=0x%02X smallId=%d\n",
+ // dwDataSize, queueIdx, dwDataSize > 0 ? pbData[0] : 0, networkPlayerSmallId);
+
EnterCriticalSection(&m_queueLockNetwork[queueIdx]);
+ if (m_queueNetwork[queueIdx].size() + dwDataSize > 2 * 1024 * 1024)
+ {
+ LeaveCriticalSection(&m_queueLockNetwork[queueIdx]);
+ return;
+ }
for( unsigned int i = 0; i < dwDataSize; i++ )
{
m_queueNetwork[queueIdx].push(*pbData++);
@@ -147,7 +155,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);
}
@@ -240,7 +248,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();
}
@@ -311,7 +319,8 @@ void Socket::SocketInputStreamLocal::close()
{
m_streamOpen = false;
EnterCriticalSection(&s_hostQueueLock[m_queueIdx]);
- s_hostQueue[m_queueIdx].empty();
+ std::queue<byte> empty;
+ std::swap(s_hostQueue[m_queueIdx], empty);
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
}
@@ -330,7 +339,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<byte>(b));
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
}
@@ -359,7 +368,8 @@ void Socket::SocketOutputStreamLocal::close()
{
m_streamOpen = false;
EnterCriticalSection(&s_hostQueueLock[m_queueIdx]);
- s_hostQueue[m_queueIdx].empty();
+ std::queue<byte> empty;
+ std::swap(s_hostQueue[m_queueIdx], empty);
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
}
@@ -442,7 +452,7 @@ void Socket::SocketOutputStreamNetwork::write(unsigned int b)
if( m_streamOpen != true ) return;
byteArray barray;
byte bb;
- bb = (byte)b;
+ bb = static_cast<byte>(b);
barray.data = &bb;
barray.length = 1;
write(barray, 0, 1);
@@ -488,15 +498,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;
}
@@ -517,7 +527,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);