aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PendingConnection.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.Client/PendingConnection.cpp
parent255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff)
parent5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff)
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/PendingConnection.cpp')
-rw-r--r--Minecraft.Client/PendingConnection.cpp115
1 files changed, 105 insertions, 10 deletions
diff --git a/Minecraft.Client/PendingConnection.cpp b/Minecraft.Client/PendingConnection.cpp
index b50669e5..f24086c1 100644
--- a/Minecraft.Client/PendingConnection.cpp
+++ b/Minecraft.Client/PendingConnection.cpp
@@ -14,6 +14,11 @@
#include "..\Minecraft.World\net.minecraft.world.item.h"
#include "..\Minecraft.World\SharedConstants.h"
#include "Settings.h"
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+#include "..\Minecraft.Server\ServerLogManager.h"
+#include "..\Minecraft.Server\Access\Access.h"
+#include "..\Minecraft.World\Socket.h"
+#endif
// #ifdef __PS3__
// #include "PS3\Network\NetworkPlayerSony.h"
// #endif
@@ -24,6 +29,24 @@ Random *PendingConnection::random = new Random();
bool g_bRejectDuplicateNames = true;
#endif
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+namespace
+{
+ static unsigned char GetPendingConnectionSmallId(Connection *connection)
+ {
+ if (connection != nullptr)
+ {
+ Socket *socket = connection->getSocket();
+ if (socket != nullptr)
+ {
+ return socket->getSmallId();
+ }
+ }
+ return 0;
+ }
+}
+#endif
+
PendingConnection::PendingConnection(MinecraftServer *server, Socket *socket, const wstring& id)
{
// 4J - added initialisers
@@ -45,7 +68,7 @@ PendingConnection::~PendingConnection()
void PendingConnection::tick()
{
- if (acceptedLogin != NULL)
+ if (acceptedLogin != nullptr)
{
this->handleAcceptedLogin(acceptedLogin);
acceptedLogin = nullptr;
@@ -65,7 +88,7 @@ void PendingConnection::disconnect(DisconnectPacket::eDisconnectReason reason)
// try { // 4J - removed try/catch
// logger.info("Disconnecting " + getName() + ": " + reason);
app.DebugPrintf("Pending connection disconnect: %d\n", reason );
- connection->send( shared_ptr<DisconnectPacket>( new DisconnectPacket(reason) ) );
+ connection->send(std::make_shared<DisconnectPacket>(reason));
connection->sendAndQuit();
done = true;
// } catch (Exception e) {
@@ -121,7 +144,7 @@ void PendingConnection::sendPreLoginResponse()
// Need to use the online XUID otherwise friend checks will fail on the client
ugcXuids[ugcXuidCount] = player->connection->m_onlineXUID;
- if( player->connection->getNetworkPlayer() != NULL && player->connection->getNetworkPlayer()->IsHost() ) hostIndex = ugcXuidCount;
+ if( player->connection->getNetworkPlayer() != nullptr && player->connection->getNetworkPlayer()->IsHost() ) hostIndex = ugcXuidCount;
++ugcXuidCount;
}
@@ -136,7 +159,9 @@ void PendingConnection::sendPreLoginResponse()
else
#endif
{
- connection->send( shared_ptr<PreLoginPacket>( new PreLoginPacket(L"-", ugcXuids, ugcXuidCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion,szUniqueMapName,app.GetGameHostOption(eGameHostOption_All),hostIndex, server->m_texturePackId) ) );
+ DWORD cappedCount = (ugcXuidCount > 255u) ? 255u : ugcXuidCount;
+ BYTE cappedHostIndex = (hostIndex >= 255u) ? 254 : static_cast<BYTE>(hostIndex);
+ connection->send(std::make_shared<PreLoginPacket>(L"-", ugcXuids, cappedCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion, szUniqueMapName, app.GetGameHostOption(eGameHostOption_All), cappedHostIndex, server->m_texturePackId));
}
}
@@ -161,12 +186,76 @@ void PendingConnection::handleLogin(shared_ptr<LoginPacket> packet)
//if (true)// 4J removed !server->onlineMode)
bool sentDisconnect = false;
+ // Use the same Xuid choice as handleAcceptedLogin (offline first, online fallback).
+ //
+ PlayerUID loginXuid = packet->m_offlineXuid;
+ if (loginXuid == INVALID_XUID) loginXuid = packet->m_onlineXuid;
+
+ bool duplicateXuid = false;
+ if (loginXuid != INVALID_XUID && server->getPlayers()->getPlayer(loginXuid) != nullptr)
+ {
+ duplicateXuid = true;
+ }
+ else if (packet->m_onlineXuid != INVALID_XUID &&
+ packet->m_onlineXuid != loginXuid &&
+ server->getPlayers()->getPlayer(packet->m_onlineXuid) != nullptr)
+ {
+ duplicateXuid = true;
+ }
+
+ bool bannedXuid = false;
+ if (loginXuid != INVALID_XUID)
+ {
+ bannedXuid = server->getPlayers()->isXuidBanned(loginXuid);
+ }
+ if (!bannedXuid && packet->m_onlineXuid != INVALID_XUID && packet->m_onlineXuid != loginXuid)
+ {
+ bannedXuid = server->getPlayers()->isXuidBanned(packet->m_onlineXuid);
+ }
+
+ bool whitelistSatisfied = true;
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ if (ServerRuntime::Access::IsWhitelistEnabled())
+ {
+ whitelistSatisfied = false;
+ if (loginXuid != INVALID_XUID)
+ {
+ whitelistSatisfied = ServerRuntime::Access::IsPlayerWhitelisted(loginXuid);
+ }
+ if (!whitelistSatisfied && packet->m_onlineXuid != INVALID_XUID && packet->m_onlineXuid != loginXuid)
+ {
+ whitelistSatisfied = ServerRuntime::Access::IsPlayerWhitelisted(packet->m_onlineXuid);
+ }
+ }
+#endif
+
if( sentDisconnect )
{
// Do nothing
}
- else if( server->getPlayers()->isXuidBanned( packet->m_onlineXuid ) )
+ else if (bannedXuid)
{
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ ServerRuntime::ServerLogManager::OnRejectedPlayerLogin(GetPendingConnectionSmallId(connection), name, ServerRuntime::ServerLogManager::eLoginRejectReason_BannedXuid);
+#endif
+ disconnect(DisconnectPacket::eDisconnect_Banned);
+ }
+ else if (!whitelistSatisfied)
+ {
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ ServerRuntime::ServerLogManager::OnRejectedPlayerLogin(GetPendingConnectionSmallId(connection), name, ServerRuntime::ServerLogManager::eLoginRejectReason_NotWhitelisted);
+#endif
+ disconnect(DisconnectPacket::eDisconnect_Banned);
+ }
+ else if (duplicateXuid)
+ {
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ ServerRuntime::ServerLogManager::OnRejectedPlayerLogin(GetPendingConnectionSmallId(connection), name, ServerRuntime::ServerLogManager::eLoginRejectReason_DuplicateXuid);
+#endif
+ // Reject the incoming connection — a player with this UID is already
+ // on the server. Allowing duplicates causes invisible players and
+ // other undefined behaviour.
+ app.DebugPrintf("LOGIN: Rejecting duplicate xuid for name: %ls\n", name.c_str());
disconnect(DisconnectPacket::eDisconnect_Banned);
}
#ifdef _WINDOWS64
@@ -176,7 +265,7 @@ void PendingConnection::handleLogin(shared_ptr<LoginPacket> packet)
vector<shared_ptr<ServerPlayer> >& pl = server->getPlayers()->players;
for (const auto& i : pl)
{
- if (i != NULL && i->name == name)
+ if (i != nullptr && i->name == name)
{
nameTaken = true;
break;
@@ -184,6 +273,9 @@ void PendingConnection::handleLogin(shared_ptr<LoginPacket> packet)
}
if (nameTaken)
{
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ ServerRuntime::ServerLogManager::OnRejectedPlayerLogin(GetPendingConnectionSmallId(connection), name, ServerRuntime::ServerLogManager::eLoginRejectReason_DuplicateName);
+#endif
app.DebugPrintf("Rejecting duplicate name: %ls\n", name.c_str());
disconnect(DisconnectPacket::eDisconnect_Banned);
}
@@ -239,10 +331,13 @@ void PendingConnection::handleAcceptedLogin(shared_ptr<LoginPacket> packet)
if(playerXuid == INVALID_XUID) playerXuid = packet->m_onlineXuid;
shared_ptr<ServerPlayer> playerEntity = server->getPlayers()->getPlayerForLogin(this, name, playerXuid,packet->m_onlineXuid);
- if (playerEntity != NULL)
+ if (playerEntity != nullptr)
{
+#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
+ ServerRuntime::ServerLogManager::OnAcceptedPlayerLogin(GetPendingConnectionSmallId(connection), name);
+#endif
server->getPlayers()->placeNewPlayer(connection, playerEntity, packet);
- connection = NULL; // We've moved responsibility for this over to the new PlayerConnection, NULL so we don't delete our reference to it here in our dtor
+ connection = nullptr; // We've moved responsibility for this over to the new PlayerConnection, nullptr so we don't delete our reference to it here in our dtor
}
done = true;
@@ -259,7 +354,7 @@ void PendingConnection::handleGetInfo(shared_ptr<GetInfoPacket> packet)
//try {
//String message = server->motd + "�" + server->players->getPlayerCount() + "�" + server->players->getMaxPlayers();
//connection->send(new DisconnectPacket(message));
- connection->send(shared_ptr<DisconnectPacket>(new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull) ) );
+ connection->send(std::make_shared<DisconnectPacket>(DisconnectPacket::eDisconnect_ServerFull));
connection->sendAndQuit();
server->connection->removeSpamProtection(connection->getSocket());
done = true;
@@ -298,4 +393,4 @@ bool PendingConnection::isServerPacketListener()
bool PendingConnection::isDisconnected()
{
return done;
-} \ No newline at end of file
+}