MinecraftConsoles/Minecraft.Client/PlayerList.h
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

142 lines
5.4 KiB
C++

#pragma once
#include <deque>
#include "..\Minecraft.World\ArrayWithLength.h"
class ServerPlayer;
class PlayerChunkMap;
class MinecraftServer;
class PlayerIO;
class PendingConnection;
class Packet;
class ServerLevel;
class TileEntity;
class ProgressListener;
class GameType;
class LoginPacket;
class ServerScoreboard;
using namespace std;
class PlayerList
{
private:
static const int SEND_PLAYER_INFO_INTERVAL = 20 * 10; // 4J - brought forward from 1.2.3
// public static Logger logger = Logger.getLogger("Minecraft");
public:
vector<shared_ptr<ServerPlayer> > players;
private:
MinecraftServer *server;
unsigned int maxPlayers;
// 4J Added
vector<PlayerUID> m_bannedXuids;
deque<BYTE> m_smallIdsToKick;
CRITICAL_SECTION m_kickPlayersCS;
deque<BYTE> m_smallIdsToClose;
CRITICAL_SECTION m_closePlayersCS;
/* 4J - removed
Set<String> bans = new HashSet<String>();
Set<String> ipBans = new HashSet<String>();
Set<String> ops = new HashSet<String>();
Set<String> whitelist = new HashSet<String>();
File banFile, ipBanFile, opFile, whiteListFile;
*/
PlayerIO *playerIo;
bool doWhiteList;
GameType *overrideGameMode;
bool allowCheatsForAllPlayers;
int viewDistance;
int sendAllPlayerInfoIn;
// 4J Added to maintain which players in which dimensions can receive all packet types
static const int DIMENSION_COUNT = 3; // overworld / nether / end — keep in sync with LevelData
vector<shared_ptr<ServerPlayer> > receiveAllPlayers[DIMENSION_COUNT];
private:
shared_ptr<ServerPlayer> findAlivePlayerOnSystem(shared_ptr<ServerPlayer> currentPlayer);
public:
void removePlayerFromReceiving(shared_ptr<ServerPlayer> player, bool usePlayerDimension = true, int dimension = 0);
void addPlayerToReceiving(shared_ptr<ServerPlayer> player);
bool canReceiveAllPackets(shared_ptr<ServerPlayer> player);
public:
PlayerList(MinecraftServer *server);
~PlayerList();
bool placeNewPlayer(Connection *connection, shared_ptr<ServerPlayer> player, shared_ptr<LoginPacket> packet);
protected:
void updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr<ServerPlayer> player);
public:
void setLevel(ServerLevelArray levels);
void changeDimension(shared_ptr<ServerPlayer> player, ServerLevel *from);
int getMaxRange();
CompoundTag *load(shared_ptr<ServerPlayer> player);
protected:
void save(shared_ptr<ServerPlayer> player);
public:
void validatePlayerSpawnPosition(shared_ptr<ServerPlayer> player); // 4J Added
void add(shared_ptr<ServerPlayer> player);
void move(shared_ptr<ServerPlayer> player);
void remove(shared_ptr<ServerPlayer> player);
shared_ptr<ServerPlayer> getPlayerForLogin(PendingConnection *pendingConnection, const wstring& userName, PlayerUID xuid);
shared_ptr<ServerPlayer> respawn(shared_ptr<ServerPlayer> serverPlayer, int targetDimension, bool keepAllPlayerData);
void toggleDimension(shared_ptr<ServerPlayer> player, int targetDimension);
void repositionAcrossDimension(shared_ptr<Entity> entity, int lastDimension, ServerLevel *oldLevel, ServerLevel *newLevel);
void tick();
bool isTrackingTile(int x, int y, int z, int dimension); // 4J added
void prioritiseTileChanges(int x, int y, int z, int dimension); // 4J added
void broadcastAll(shared_ptr<Packet> packet);
void broadcastAll(shared_ptr<Packet> packet, int dimension);
wstring getPlayerNames();
public:
bool isWhiteListed(const wstring& name);
bool isOp(const wstring& name);
bool isOp(shared_ptr<ServerPlayer> player); // 4J Added
shared_ptr<ServerPlayer> getPlayer(const wstring& name);
shared_ptr<ServerPlayer> getPlayer(PlayerUID uid);
shared_ptr<ServerPlayer> getNearestPlayer(Pos *position, int range);
vector<ServerPlayer> *getPlayers(Pos *position, int rangeMin, int rangeMax, int count, int mode, int levelMin, int levelMax, unordered_map<wstring, int> *scoreRequirements, const wstring &playerName, const wstring &teamName, Level *level);
private:
bool meetsScoreRequirements(shared_ptr<Player> player, unordered_map<wstring, int> scoreRequirements);
public:
void sendMessage(const wstring& name, const wstring& message);
void broadcast(double x, double y, double z, double range, int dimension, shared_ptr<Packet> packet);
void broadcast(shared_ptr<Player> except, double x, double y, double z, double range, int dimension, shared_ptr<Packet> packet);
// 4J Added ProgressListener *progressListener param and bDeleteGuestMaps param
void saveAll(ProgressListener *progressListener, bool bDeleteGuestMaps = false);
void whiteList(const wstring& playerName);
void blackList(const wstring& playerName);
// Set<String> getWhiteList(); / 4J removed
void reloadWhitelist();
void sendLevelInfo(shared_ptr<ServerPlayer> player, ServerLevel *level);
void sendAllPlayerInfo(shared_ptr<ServerPlayer> player);
int getPlayerCount();
int getPlayerCount(ServerLevel *level); // 4J Added
int getMaxPlayers();
MinecraftServer *getServer();
int getViewDistance();
void setOverrideGameMode(GameType *gameMode);
private:
void updatePlayerGameMode(shared_ptr<ServerPlayer> newPlayer, shared_ptr<ServerPlayer> oldPlayer, Level *level);
public:
void setAllowCheatsForAllPlayers(bool allowCommands);
// 4J Added
void kickPlayerByShortId(BYTE networkSmallId);
void closePlayerConnectionBySmallId(BYTE networkSmallId);
void queueSmallIdForRecycle(BYTE smallId);
bool isXuidBanned(PlayerUID xuid);
// AP added for Vita so the range can be increased once the level starts
void setViewDistance(int newViewDistance);
};