mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
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.
236 lines
6.5 KiB
C++
236 lines
6.5 KiB
C++
#include "stdafx.h"
|
|
#include "Options.h"
|
|
#include "ServerConnection.h"
|
|
|
|
#include <memory>
|
|
#include "PendingConnection.h"
|
|
#include "PlayerConnection.h"
|
|
#include "ServerPlayer.h"
|
|
#include "..\Minecraft.World\net.minecraft.network.h"
|
|
#include "..\Minecraft.World\Socket.h"
|
|
#include "..\Minecraft.World\net.minecraft.world.level.h"
|
|
#include "MultiPlayerLevel.h"
|
|
|
|
ServerConnection::ServerConnection(MinecraftServer *server)
|
|
{
|
|
// 4J - added initialiser
|
|
connectionCounter = 0;
|
|
InitializeCriticalSection(&pending_cs);
|
|
|
|
this->server = server;
|
|
}
|
|
|
|
ServerConnection::~ServerConnection()
|
|
{
|
|
DeleteCriticalSection(&pending_cs);
|
|
}
|
|
|
|
// 4J - added to handle incoming connections, to replace thread that original used to have
|
|
void ServerConnection::NewIncomingSocket(Socket *socket)
|
|
{
|
|
shared_ptr<PendingConnection> unconnectedClient = std::make_shared<PendingConnection>(server, socket, L"Connection #" + std::to_wstring(connectionCounter++));
|
|
handleConnection(unconnectedClient);
|
|
}
|
|
|
|
void ServerConnection::addPlayerConnection(shared_ptr<PlayerConnection> uc)
|
|
{
|
|
players.push_back(uc);
|
|
}
|
|
|
|
void ServerConnection::handleConnection(shared_ptr<PendingConnection> uc)
|
|
{
|
|
EnterCriticalSection(&pending_cs);
|
|
pending.push_back(uc);
|
|
LeaveCriticalSection(&pending_cs);
|
|
}
|
|
|
|
void ServerConnection::closePendingConnectionsBySmallId(BYTE smallId)
|
|
{
|
|
EnterCriticalSection(&pending_cs);
|
|
for (auto& pc : pending)
|
|
{
|
|
if (pc && !pc->done && pc->connection != nullptr)
|
|
{
|
|
Socket *pcSocket = pc->connection->getSocket();
|
|
if (pcSocket != nullptr && pcSocket->getSmallId() == smallId)
|
|
{
|
|
pc->done = true;
|
|
}
|
|
}
|
|
}
|
|
LeaveCriticalSection(&pending_cs);
|
|
}
|
|
|
|
void ServerConnection::stop()
|
|
{
|
|
std::vector<shared_ptr<PendingConnection> > pendingSnapshot;
|
|
EnterCriticalSection(&pending_cs);
|
|
pendingSnapshot = pending;
|
|
LeaveCriticalSection(&pending_cs);
|
|
|
|
for (unsigned int i = 0; i < pendingSnapshot.size(); i++)
|
|
{
|
|
shared_ptr<PendingConnection> uc = pendingSnapshot[i];
|
|
if (uc != NULL && !uc->done)
|
|
{
|
|
uc->disconnect(DisconnectPacket::eDisconnect_Closed);
|
|
}
|
|
}
|
|
|
|
// Snapshot to avoid iterator invalidation if disconnect modifies the vector.
|
|
std::vector<shared_ptr<PlayerConnection> > playerSnapshot = players;
|
|
for (unsigned int i = 0; i < playerSnapshot.size(); i++)
|
|
{
|
|
shared_ptr<PlayerConnection> player = playerSnapshot[i];
|
|
if (player != NULL && !player->done)
|
|
{
|
|
player->disconnect(DisconnectPacket::eDisconnect_Quitting);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ServerConnection::tick()
|
|
{
|
|
{
|
|
// MGH - changed this so that the the CS lock doesn't cover the tick (was causing a lockup when 2 players tried to join)
|
|
EnterCriticalSection(&pending_cs);
|
|
vector< shared_ptr<PendingConnection> > tempPending = pending;
|
|
LeaveCriticalSection(&pending_cs);
|
|
|
|
for (unsigned int i = 0; i < tempPending.size(); i++)
|
|
{
|
|
shared_ptr<PendingConnection> uc = tempPending[i];
|
|
// try { // 4J - removed try/catch
|
|
uc->tick();
|
|
// } catch (Exception e) {
|
|
// uc.disconnect("Internal server error");
|
|
// logger.log(Level.WARNING, "Failed to handle packet: " + e, e);
|
|
// }
|
|
if(uc->connection != nullptr) uc->connection->flush();
|
|
}
|
|
}
|
|
|
|
// now remove from the pending list
|
|
EnterCriticalSection(&pending_cs);
|
|
for (unsigned int i = 0; i < pending.size(); i++)
|
|
if (pending[i]->done)
|
|
{
|
|
pending.erase(pending.begin()+i);
|
|
i--;
|
|
}
|
|
LeaveCriticalSection(&pending_cs);
|
|
|
|
for (unsigned int i = 0; i < players.size(); i++)
|
|
{
|
|
shared_ptr<PlayerConnection> player = players[i];
|
|
shared_ptr<ServerPlayer> serverPlayer = player->getPlayer();
|
|
if( serverPlayer )
|
|
{
|
|
serverPlayer->updateFrameTick();
|
|
serverPlayer->doChunkSendingTick(false);
|
|
}
|
|
player->tick();
|
|
if (player->done)
|
|
{
|
|
players.erase(players.begin()+i);
|
|
i--;
|
|
}
|
|
else
|
|
{
|
|
player->connection->flush();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
bool ServerConnection::addPendingTextureRequest(const wstring &textureName)
|
|
{
|
|
auto it = find(m_pendingTextureRequests.begin(), m_pendingTextureRequests.end(), textureName);
|
|
if( it == m_pendingTextureRequests.end() )
|
|
{
|
|
m_pendingTextureRequests.push_back(textureName);
|
|
return true;
|
|
}
|
|
|
|
// 4J Stu - We want to request this texture from everyone, if we have a duplicate it's most likely because the first person we asked for it didn't have it
|
|
// eg They selected a skin then deleted the skin pack. The side effect of this change is that in certain cases we can send a few more requests, and receive
|
|
// a few more responses if people join with the same skin in a short space of time
|
|
return true;
|
|
}
|
|
|
|
void ServerConnection::handleTextureReceived(const wstring &textureName)
|
|
{
|
|
auto it = find(m_pendingTextureRequests.begin(), m_pendingTextureRequests.end(), textureName);
|
|
if( it != m_pendingTextureRequests.end() )
|
|
{
|
|
m_pendingTextureRequests.erase(it);
|
|
}
|
|
for (auto& player : players)
|
|
{
|
|
if (!player->done)
|
|
{
|
|
player->handleTextureReceived(textureName);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ServerConnection::handleTextureAndGeometryReceived(const wstring &textureName)
|
|
{
|
|
auto it = find(m_pendingTextureRequests.begin(), m_pendingTextureRequests.end(), textureName);
|
|
if( it != m_pendingTextureRequests.end() )
|
|
{
|
|
m_pendingTextureRequests.erase(it);
|
|
}
|
|
for (auto& player : players)
|
|
{
|
|
if (!player->done)
|
|
{
|
|
player->handleTextureAndGeometryReceived(textureName);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ServerConnection::handleServerSettingsChanged(shared_ptr<ServerSettingsChangedPacket> packet)
|
|
{
|
|
Minecraft *pMinecraft = Minecraft::GetInstance();
|
|
|
|
if(packet->action==ServerSettingsChangedPacket::HOST_DIFFICULTY)
|
|
{
|
|
for(unsigned int i = 0; i < pMinecraft->levels.length; ++i)
|
|
{
|
|
if( pMinecraft->levels[i] != nullptr )
|
|
{
|
|
app.DebugPrintf("ClientConnection::handleServerSettingsChanged - Difficulty = %d",packet->data);
|
|
pMinecraft->levels[i]->difficulty = packet->data;
|
|
}
|
|
}
|
|
}
|
|
// else if(packet->action==ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS)// options
|
|
// {
|
|
// app.SetGameHostOption(eGameHostOption_All,packet->m_serverSettings)
|
|
// }
|
|
// else
|
|
// {
|
|
// unsigned char ucData=(unsigned char)packet->data;
|
|
// if(ucData&1)
|
|
// {
|
|
// // hide gamertags
|
|
// pMinecraft->options->SetGamertagSetting(true);
|
|
// }
|
|
// else
|
|
// {
|
|
// pMinecraft->options->SetGamertagSetting(false);
|
|
// }
|
|
//
|
|
// for (unsigned int i = 0; i < players.size(); i++)
|
|
// {
|
|
// shared_ptr<PlayerConnection> playerconnection = players[i];
|
|
// playerconnection->setShowOnMaps(pMinecraft->options->GetGamertagSetting());
|
|
// }
|
|
// }
|
|
}
|
|
|
|
vector< shared_ptr<PlayerConnection> > * ServerConnection::getPlayers()
|
|
{
|
|
return &players;
|
|
} |