Multiplayer 8 to max byte increase.

Made-with: Cursor
This commit is contained in:
lag 2026-03-06 11:20:23 -06:00
parent de46641cda
commit 6664493793
10 changed files with 63 additions and 32 deletions

View file

@ -830,8 +830,9 @@ void ClientConnection::handleAddPlayer(shared_ptr<AddPlayerPacket> packet)
// Current Win64 path: identify QNet player by name and attach packet XUID.
if (matchedQNetPlayer == NULL)
{
for (BYTE smallId = 0; smallId < MINECRAFT_NET_MAX_PLAYERS; ++smallId)
for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i)
{
BYTE smallId = static_cast<BYTE>(i);
INetworkPlayer* np = g_NetworkManager.GetPlayerBySmallId(smallId);
if (np == NULL)
continue;

View file

@ -136,7 +136,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 : static_cast<DWORD>(ugcXuidCount);
BYTE cappedHostIndex = (hostIndex >= 255u) ? 254 : static_cast<BYTE>(hostIndex);
connection->send( shared_ptr<PreLoginPacket>( new PreLoginPacket(L"-", ugcXuids, cappedCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion,szUniqueMapName,app.GetGameHostOption(eGameHostOption_All),cappedHostIndex, server->m_texturePackId) ) );
}
}

View file

@ -79,7 +79,7 @@ PlayerList::~PlayerList()
DeleteCriticalSection(&m_closePlayersCS);
}
void PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer> player, shared_ptr<LoginPacket> packet)
bool PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer> player, shared_ptr<LoginPacket> packet)
{
CompoundTag *playerTag = load(player);
@ -129,13 +129,13 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer>
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 +146,12 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer>
}
}
}
if (playerIndex >= (unsigned int)MINECRAFT_NET_MAX_PLAYERS)
{
connection->send(shared_ptr<DisconnectPacket>(new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull)));
connection->sendAndQuit();
return false;
}
player->setPlayerIndex( playerIndex );
player->setCustomSkin( packet->m_playerSkinId );
player->setCustomCape( packet->m_playerCapeId );
@ -233,8 +239,9 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer>
addPlayerToReceiving( player );
int maxPlayersForPacket = getMaxPlayers() > 255 ? 255 : getMaxPlayers();
playerConnection->send( shared_ptr<LoginPacket>( 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<SetSpawnPositionPacket>( new SetSpawnPositionPacket(spawnPos->x, spawnPos->y, spawnPos->z) ) );
@ -296,6 +303,7 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer>
}
}
}
return true;
}
void PlayerList::updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr<ServerPlayer> player)

View file

@ -64,7 +64,7 @@ public:
public:
PlayerList(MinecraftServer *server);
~PlayerList();
void placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer> player, shared_ptr<LoginPacket> packet);
bool placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer> player, shared_ptr<LoginPacket> packet);
protected:
void updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr<ServerPlayer> player);

View file

@ -14,19 +14,44 @@
#include "..\Minecraft.World\net.minecraft.h"
#include "..\Minecraft.World\StringHelpers.h"
const unsigned int PlayerRenderer::s_nametagColors[MINECRAFT_NET_MAX_PLAYERS] =
static unsigned int nametagColorForIndex(int index)
{
0xff000000, // WHITE (represents the "white" player, but using black as the colour)
0xff33cc33, // GREEN
0xffcc3333, // RED
0xff3333cc, // BLUE
#ifndef __PSVITA__ // only 4 player on Vita
0xffcc33cc, // PINK
0xffcc6633, // ORANGE
0xffcccc33, // YELLOW
0xff33dccc, // TURQUOISE
static const unsigned int s_firstColors[] = {
0xff000000, // WHITE (represents the "white" player, but using black as the colour)
0xff33cc33, // GREEN
0xffcc3333, // RED
0xff3333cc, // BLUE
0xffcc33cc, // PINK
0xffcc6633, // ORANGE
0xffcccc33, // YELLOW
0xff33dccc // TURQUOISE
};
#ifndef __PSVITA__
if (index >= 0 && index < 8) // Use original colors for the first 8 players
return s_firstColors[index];
if (index >= 8 && index < MINECRAFT_NET_MAX_PLAYERS)
{
float h = (float)((index * 137) % 360) / 60.f;
int i = (int)h;
float f = h - i;
float q = 1.f - f;
float t = 1.f - (1.f - f);
float r = 0.f, g = 0.f, b = 0.f;
switch (i % 6)
{
case 0: r = 1.f; g = t; b = 0.f; break;
case 1: r = q; g = 1.f; b = 0.f; break;
case 2: r = 0.f; g = 1.f; b = t; break;
case 3: r = 0.f; g = q; b = 1.f; break;
case 4: r = t; g = 0.f; b = 1.f; break;
default: r = 1.f; g = 0.f; b = q; break;
}
int ri = (int)(r * 255.f) & 0xff, gi = (int)(g * 255.f) & 0xff, bi = (int)(b * 255.f) & 0xff;
return 0xff000000u | (ri << 16) | (gi << 8) | bi;
}
#endif
};
return 0xFF000000; //Fallback if exceeds 256 somehow
}
ResourceLocation PlayerRenderer::DEFAULT_LOCATION = ResourceLocation(TN_MOB_CHAR);
@ -41,9 +66,7 @@ PlayerRenderer::PlayerRenderer() : LivingEntityRenderer( new HumanoidModel(0), 0
unsigned int PlayerRenderer::getNametagColour(int index)
{
if( index >= 0 && index < MINECRAFT_NET_MAX_PLAYERS)
{
return s_nametagColors[index];
}
return nametagColorForIndex(index);
return 0xFF000000;
}

View file

@ -13,9 +13,6 @@ public:
static ResourceLocation DEFAULT_LOCATION;
private:
// 4J Added
static const unsigned int s_nametagColors[MINECRAFT_NET_MAX_PLAYERS];
HumanoidModel *humanoidModel;
HumanoidModel *armorParts1;
HumanoidModel *armorParts2;

View file

@ -21,7 +21,7 @@ bool WinsockNetLayer::s_initialized = false;
BYTE WinsockNetLayer::s_localSmallId = 0;
BYTE WinsockNetLayer::s_hostSmallId = 0;
BYTE WinsockNetLayer::s_nextSmallId = 1;
unsigned int WinsockNetLayer::s_nextSmallId = 1;
CRITICAL_SECTION WinsockNetLayer::s_sendLock;
CRITICAL_SECTION WinsockNetLayer::s_connectionsLock;
@ -447,9 +447,9 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
assignedSmallId = s_freeSmallIds.back();
s_freeSmallIds.pop_back();
}
else if (s_nextSmallId < MINECRAFT_NET_MAX_PLAYERS)
else if (s_nextSmallId < (unsigned int)MINECRAFT_NET_MAX_PLAYERS)
{
assignedSmallId = s_nextSmallId++;
assignedSmallId = (BYTE)s_nextSmallId++;
}
else
{

View file

@ -12,7 +12,7 @@
#pragma comment(lib, "Ws2_32.lib")
#define WIN64_NET_DEFAULT_PORT 25565
#define WIN64_NET_MAX_CLIENTS 7
#define WIN64_NET_MAX_CLIENTS 255
#define WIN64_NET_RECV_BUFFER_SIZE 65536
#define WIN64_NET_MAX_PACKET_SIZE (4 * 1024 * 1024)
#define WIN64_LAN_DISCOVERY_PORT 25566
@ -116,7 +116,7 @@ private:
static BYTE s_localSmallId;
static BYTE s_hostSmallId;
static BYTE s_nextSmallId;
static unsigned int s_nextSmallId;
static CRITICAL_SECTION s_sendLock;
static CRITICAL_SECTION s_connectionsLock;

View file

@ -3,7 +3,7 @@ using namespace std;
// If we have more than MAX_PLAYER_DATA_SAVES player.dat's then we delete the oldest ones
// This value can be no higher than MAXIMUM_MAP_SAVE_DATA/3 (3 being the number of dimensions in future versions)
#define MAX_PLAYER_DATA_SAVES 80
#define MAX_PLAYER_DATA_SAVES 0x7FFFFFFF
class Player;

View file

@ -21,7 +21,7 @@ const int XUSER_MAX_COUNT = 1;
const int MINECRAFT_NET_MAX_PLAYERS = 4;
#else
const int XUSER_MAX_COUNT = 4;
const int MINECRAFT_NET_MAX_PLAYERS = 8;
const int MINECRAFT_NET_MAX_PLAYERS = 256;
#endif