MinecraftConsoles/Minecraft.World/AddPlayerPacket.cpp
MrTheShy 4f2352361a Add Mojang/Ely.by/offline authentication system
The old Windows64 port had no real player identity — it used hardcoded
fake XUIDs, so anyone could impersonate anyone. This replaces that with
proper auth supporting Mojang, Ely.by, and offline accounts.

MCAuth library (new, MCAuth/):
  Mojang auth via MSA device code flow (XBL, SISU, MC services),
  Ely.by via Yggdrasil with 2FA, offline UUID generation matching
  Java Edition (MD5 v3 from "OfflinePlayer:<name>"). Multi-account
  manager with background token refresh, per-slot sessions, and
  on-disk token persistence. Server-side session verification via
  Mojang/Ely.by hasJoined API. Skin fetching and PNG validation
  from texture servers.

Network protocol (version bumped to 80):
  Three new packets (AuthScheme, AuthResponse, AuthResult) implement
  a server-driven auth handshake before login completes. Player
  identity migrated from 64-bit XUID to 128-bit GameUUID backed by
  two uint64 fields (hi/lo). readPlayerUID/writePlayerUID now
  serialize 16 bytes on the wire. Old and new clients cannot connect
  to each other — version mismatch is rejected at PreLogin.

Save migration:
  Map data mappings auto-migrate from old format: the old 64-bit
  XUID is placed in hi, lo is set to 0 as a sentinel. On first
  access by the real player, the sentinel entry is upgraded in-place
  to the full 128-bit UUID. Format detection is by file size (2080,
  2112, or 4160 bytes). Player .dat filenames inside saveData.ms
  change from decimal XUID to dashed UUID — old saves need manual
  entry renaming in the archive.

UI:
  NativeUIRenderer: immediate-mode drawing system (quads, text,
  9-slice panels, scrollbars, focus lists) for rendering auth
  screens without Flash/Scaleform. UIScene_MSAuth handles device
  code display, Ely.by credential input with 2FA, per-account
  skin head preview, and multi-account add/remove/switch.

Server:
  online-mode and auth-provider (mojang/elyby) in server.properties.
  Whitelist and ban checks validate against the server-verified UUID.
  Incompatible auth scheme logs which provider the server expects
  vs what the client is using.

Also fixes a pre-existing exploit where any client could send a
DebugOptionsPacket to grant themselves CraftAnything and other debug
privileges on any server — now requires OP status server-side.
2026-03-23 01:14:23 +01:00

140 lines
3.6 KiB
C++

#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.item.h"
#include "PacketListener.h"
#include "AddPlayerPacket.h"
AddPlayerPacket::AddPlayerPacket()
{
id = -1;
name = L"";
x = 0;
y = 0;
z = 0;
yRot = 0;
xRot = 0;
carriedItem = 0;
xuid = INVALID_XUID;
m_playerIndex = 0;
m_skinId = 0;
m_capeId = 0;
m_uiGamePrivileges = 0;
entityData = nullptr;
unpack = nullptr;
}
AddPlayerPacket::~AddPlayerPacket()
{
if(unpack != nullptr) delete unpack;
}
AddPlayerPacket::AddPlayerPacket(shared_ptr<Player> player, PlayerUID xuid, int xp, int yp, int zp, int yRotp, int xRotp, int yHeadRotp)
{
id = player->entityId;
name = player->getName();
// 4J Stu - Send "previously sent" value of position as well so that we stay in sync
x = xp;//Mth::floor(player->x * 32);
y = yp;//Mth::floor(player->y * 32);
z = zp;//Mth::floor(player->z * 32);
// 4J - changed - send current "previously sent" value of rotations to put this in sync with other clients
yRot = yRotp;
xRot = xRotp;
yHeadRot = yHeadRotp; // 4J Added
// yRot = (byte) (player->yRot * 256 / 360);
// xRot = (byte) (player->xRot * 256 / 360);
//printf("%d: New add player (%f,%f,%f) : (%d,%d,%d) : xRot %d, yRot %d\n",id,player->x,player->y,player->z,x,y,z,xRot,yRot);
shared_ptr<ItemInstance> itemInstance = player->inventory->getSelected();
carriedItem = itemInstance == nullptr ? 0 : itemInstance->id;
this->xuid = xuid;
m_playerIndex = static_cast<BYTE>(player->getPlayerIndex());
m_skinId = player->getCustomSkin();
m_capeId = player->getCustomCape();
m_uiGamePrivileges = player->getAllPlayerGamePrivileges();
entityData = player->getEntityData();
unpack = nullptr;
}
void AddPlayerPacket::read(DataInputStream *dis) //throws IOException
{
id = dis->readInt();
name = readUtf(dis, Player::MAX_NAME_LENGTH);
x = dis->readInt();
y = dis->readInt();
z = dis->readInt();
yRot = dis->readByte();
xRot = dis->readByte();
yHeadRot = dis->readByte(); // 4J Added
carriedItem = dis->readShort();
xuid = dis->readPlayerUID();
m_playerIndex = dis->readByte();
INT skinId = dis->readInt();
m_skinId = static_cast<DWORD>(skinId);
INT capeId = dis->readInt();
m_capeId = static_cast<DWORD>(capeId);
INT privileges = dis->readInt();
m_uiGamePrivileges = static_cast<unsigned int>(privileges);
MemSect(1);
unpack = SynchedEntityData::unpack(dis);
MemSect(0);
}
void AddPlayerPacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeInt(id);
writeUtf(name, dos);
dos->writeInt(x);
dos->writeInt(y);
dos->writeInt(z);
dos->writeByte(yRot);
dos->writeByte(xRot);
dos->writeByte(yHeadRot); // 4J Added
dos->writeShort(carriedItem);
dos->writePlayerUID(xuid);
dos->writeByte(m_playerIndex);
dos->writeInt(m_skinId);
dos->writeInt(m_capeId);
dos->writeInt(m_uiGamePrivileges);
entityData->packAll(dos);
}
void AddPlayerPacket::handle(PacketListener *listener)
{
listener->handleAddPlayer(shared_from_this());
}
int AddPlayerPacket::getEstimatedSize()
{
int iSize= sizeof(int) + Player::MAX_NAME_LENGTH + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(BYTE) + sizeof(BYTE) +sizeof(short) + sizeof(PlayerUID) + sizeof(int) + sizeof(BYTE) + sizeof(unsigned int) + sizeof(byte);
if( entityData != nullptr )
{
iSize += entityData->getSizeInBytes();
}
else if( unpack != nullptr )
{
// 4J Stu - This is an incoming value which we aren't currently analysing
//iSize += unpack->get
}
return iSize;
}
vector<shared_ptr<SynchedEntityData::DataItem> > *AddPlayerPacket::getUnpackedData()
{
if (unpack == nullptr)
{
unpack = entityData->getAll();
}
return unpack;
}