From 13960a93b2a7c114446c109de059db305db4555d Mon Sep 17 00:00:00 2001 From: Kevin <115616336+lag@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:23:32 -0600 Subject: Max players from 8 -> 255 + small connection optimizations (#722) * Multiplayer 8 to max byte increase. Made-with: Cursor * Server chunk optimizations for large player counts, server full notification fix, added to server.properties. --- Minecraft.Client/PlayerList.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'Minecraft.Client/PlayerList.cpp') diff --git a/Minecraft.Client/PlayerList.cpp b/Minecraft.Client/PlayerList.cpp index 42724a4f..1742756e 100644 --- a/Minecraft.Client/PlayerList.cpp +++ b/Minecraft.Client/PlayerList.cpp @@ -56,11 +56,8 @@ PlayerList::PlayerList(MinecraftServer *server) //int viewDistance = server->settings->getInt(L"view-distance", 10); -#ifdef _WINDOWS64 - maxPlayers = MINECRAFT_NET_MAX_PLAYERS; -#else - maxPlayers = server->settings->getInt(L"max-players", 20); -#endif + int rawMax = server->settings->getInt(L"max-players", 8); + maxPlayers = (unsigned int)Mth::clamp(rawMax, 1, MINECRAFT_NET_MAX_PLAYERS); doWhiteList = false; InitializeCriticalSection(&m_kickPlayersCS); InitializeCriticalSection(&m_closePlayersCS); @@ -79,7 +76,7 @@ PlayerList::~PlayerList() DeleteCriticalSection(&m_closePlayersCS); } -void PlayerList::placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet) +bool PlayerList::placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet) { CompoundTag *playerTag = load(player); @@ -129,13 +126,13 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr ServerLevel *level = server->getLevel(player->dimension); - DWORD playerIndex = 0; + DWORD playerIndex = (DWORD)MINECRAFT_NET_MAX_PLAYERS; { bool usedIndexes[MINECRAFT_NET_MAX_PLAYERS]; ZeroMemory( &usedIndexes, MINECRAFT_NET_MAX_PLAYERS * sizeof(bool) ); - for (auto& player : players ) + for (auto& p : players ) { - usedIndexes[player->getPlayerIndex()] = true; + usedIndexes[p->getPlayerIndex()] = true; } for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { @@ -146,6 +143,12 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr } } } + if (playerIndex >= (unsigned int)MINECRAFT_NET_MAX_PLAYERS) + { + connection->send(shared_ptr(new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull))); + connection->sendAndQuit(); + return false; + } player->setPlayerIndex( playerIndex ); player->setCustomSkin( packet->m_playerSkinId ); player->setCustomCape( packet->m_playerCapeId ); @@ -233,8 +236,9 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr addPlayerToReceiving( player ); + int maxPlayersForPacket = getMaxPlayers() > 255 ? 255 : getMaxPlayers(); playerConnection->send( shared_ptr( new LoginPacket(L"", player->entityId, level->getLevelData()->getGenerator(), level->getSeed(), player->gameMode->getGameModeForPlayer()->getId(), - (byte) level->dimension->id, (byte) level->getMaxBuildHeight(), (byte) getMaxPlayers(), + (byte) level->dimension->id, (byte) level->getMaxBuildHeight(), (byte) maxPlayersForPacket, level->difficulty, TelemetryManager->GetMultiplayerInstanceID(), (BYTE)playerIndex, level->useNewSeaLevel(), player->getAllPlayerGamePrivileges(), level->getLevelData()->getXZSize(), level->getLevelData()->getHellScale() ) ) ); playerConnection->send( shared_ptr( new SetSpawnPositionPacket(spawnPos->x, spawnPos->y, spawnPos->z) ) ); @@ -296,6 +300,7 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr } } } + return true; } void PlayerList::updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr player) @@ -513,11 +518,7 @@ if (player->riding != NULL) shared_ptr PlayerList::getPlayerForLogin(PendingConnection *pendingConnection, const wstring& userName, PlayerUID xuid, PlayerUID onlineXuid) { -#ifdef _WINDOWS64 - if (players.size() >= (unsigned int)MINECRAFT_NET_MAX_PLAYERS) -#else if (players.size() >= (unsigned int)maxPlayers) -#endif { pendingConnection->disconnect(DisconnectPacket::eDisconnect_ServerFull); return shared_ptr(); -- cgit v1.2.3