chore: format Minecraft.Client

This commit is contained in:
Tropical
2026-03-13 17:10:10 -05:00
parent 33d0737d1d
commit e8424f2000
531 changed files with 67709 additions and 62690 deletions

View File

@@ -19,112 +19,108 @@
// #include "PS3/Network/NetworkPlayerSony.h"
// #endif
Random *PendingConnection::random = new Random();
Random* PendingConnection::random = new Random();
PendingConnection::PendingConnection(MinecraftServer *server, Socket *socket, const std::wstring& id)
{
// 4J - added initialisers
done = false;
PendingConnection::PendingConnection(MinecraftServer* server, Socket* socket,
const std::wstring& id) {
// 4J - added initialisers
done = false;
_tick = 0;
name = L"";
acceptedLogin = nullptr;
loginKey = L"";
loginKey = L"";
this->server = server;
connection = new Connection(socket, id, this);
connection->fakeLag = FAKE_LAG;
}
PendingConnection::~PendingConnection()
{
delete connection;
}
PendingConnection::~PendingConnection() { delete connection; }
void PendingConnection::tick()
{
if (acceptedLogin != NULL)
{
void PendingConnection::tick() {
if (acceptedLogin != NULL) {
this->handleAcceptedLogin(acceptedLogin);
acceptedLogin = nullptr;
}
if (_tick++ == MAX_TICKS_BEFORE_LOGIN)
{
if (_tick++ == MAX_TICKS_BEFORE_LOGIN) {
disconnect(DisconnectPacket::eDisconnect_LoginTooLong);
}
else
{
} else {
connection->tick();
}
}
void PendingConnection::disconnect(DisconnectPacket::eDisconnectReason reason)
{
// try { // 4J - removed try/catch
// logger.info("Disconnecting " + getName() + ": " + reason);
fprintf(stderr, "[PENDING] disconnect called with reason=%d at tick=%d\n", reason, _tick);
app.DebugPrintf("Pending connection disconnect: %d\n", reason );
connection->send( std::shared_ptr<DisconnectPacket>( new DisconnectPacket(reason) ) );
connection->sendAndQuit();
done = true;
// } catch (Exception e) {
// e.printStackTrace();
// }
void PendingConnection::disconnect(DisconnectPacket::eDisconnectReason reason) {
// try { // 4J - removed try/catch
// logger.info("Disconnecting " + getName() + ": " + reason);
fprintf(stderr, "[PENDING] disconnect called with reason=%d at tick=%d\n",
reason, _tick);
app.DebugPrintf("Pending connection disconnect: %d\n", reason);
connection->send(
std::shared_ptr<DisconnectPacket>(new DisconnectPacket(reason)));
connection->sendAndQuit();
done = true;
// } catch (Exception e) {
// e.printStackTrace();
// }
}
void PendingConnection::handlePreLogin(std::shared_ptr<PreLoginPacket> packet)
{
if (packet->m_netcodeVersion != MINECRAFT_NET_VERSION)
{
app.DebugPrintf("Netcode version is %d not equal to %d\n", packet->m_netcodeVersion, MINECRAFT_NET_VERSION);
if (packet->m_netcodeVersion > MINECRAFT_NET_VERSION)
{
void PendingConnection::handlePreLogin(std::shared_ptr<PreLoginPacket> packet) {
if (packet->m_netcodeVersion != MINECRAFT_NET_VERSION) {
app.DebugPrintf("Netcode version is %d not equal to %d\n",
packet->m_netcodeVersion, MINECRAFT_NET_VERSION);
if (packet->m_netcodeVersion > MINECRAFT_NET_VERSION) {
disconnect(DisconnectPacket::eDisconnect_OutdatedServer);
}
else
{
} else {
disconnect(DisconnectPacket::eDisconnect_OutdatedClient);
}
return;
}
// printf("Server: handlePreLogin\n");
name = packet->loginKey; // 4J Stu - Change from the login packet as we know better on client end during the pre-login packet
sendPreLoginResponse();
// printf("Server: handlePreLogin\n");
name =
packet->loginKey; // 4J Stu - Change from the login packet as we know
// better on client end during the pre-login packet
sendPreLoginResponse();
}
void PendingConnection::sendPreLoginResponse()
{
// 4J Stu - Calculate the players with UGC privileges set
PlayerUID *ugcXuids = new PlayerUID[MINECRAFT_NET_MAX_PLAYERS];
std::uint8_t ugcXuidCount = 0;
std::uint8_t hostIndex = 0;
std::uint8_t ugcFriendsOnlyBits = 0;
char szUniqueMapName[14];
void PendingConnection::sendPreLoginResponse() {
// 4J Stu - Calculate the players with UGC privileges set
PlayerUID* ugcXuids = new PlayerUID[MINECRAFT_NET_MAX_PLAYERS];
std::uint8_t ugcXuidCount = 0;
std::uint8_t hostIndex = 0;
std::uint8_t ugcFriendsOnlyBits = 0;
char szUniqueMapName[14];
StorageManager.GetSaveUniqueFilename(szUniqueMapName);
StorageManager.GetSaveUniqueFilename(szUniqueMapName);
PlayerList *playerList = MinecraftServer::getInstance()->getPlayers();
for(AUTO_VAR(it, playerList->players.begin()); it != playerList->players.end(); ++it)
{
std::shared_ptr<ServerPlayer> player = *it;
// If the offline Xuid is invalid but the online one is not then that's guest which we should ignore
// If the online Xuid is invalid but the offline one is not then we are definitely an offline game so dont care about UGC
// PADDY - this is failing when a local player with chat restrictions joins an online game
PlayerList* playerList = MinecraftServer::getInstance()->getPlayers();
for (AUTO_VAR(it, playerList->players.begin());
it != playerList->players.end(); ++it) {
std::shared_ptr<ServerPlayer> player = *it;
// If the offline Xuid is invalid but the online one is not then that's
// guest which we should ignore If the online Xuid is invalid but the
// offline one is not then we are definitely an offline game so dont
// care about UGC
if( player != NULL && player->connection->m_offlineXUID != INVALID_XUID && player->connection->m_onlineXUID != INVALID_XUID )
{
if( player->connection->m_friendsOnlyUGC )
{
ugcFriendsOnlyBits |= (1<<ugcXuidCount);
}
// Need to use the online XUID otherwise friend checks will fail on the client
ugcXuids[ugcXuidCount] = player->connection->m_onlineXUID;
// PADDY - this is failing when a local player with chat restrictions
// joins an online game
if( player->connection->getNetworkPlayer() != NULL && player->connection->getNetworkPlayer()->IsHost() ) hostIndex = ugcXuidCount;
if (player != NULL &&
player->connection->m_offlineXUID != INVALID_XUID &&
player->connection->m_onlineXUID != INVALID_XUID) {
if (player->connection->m_friendsOnlyUGC) {
ugcFriendsOnlyBits |= (1 << ugcXuidCount);
}
// Need to use the online XUID otherwise friend checks will fail on
// the client
ugcXuids[ugcXuidCount] = player->connection->m_onlineXUID;
++ugcXuidCount;
}
}
if (player->connection->getNetworkPlayer() != NULL &&
player->connection->getNetworkPlayer()->IsHost())
hostIndex = ugcXuidCount;
++ugcXuidCount;
}
}
#if 0
if (false)// server->onlineMode) // 4J - removed
@@ -134,47 +130,44 @@ void PendingConnection::sendPreLoginResponse()
}
else
#endif
{
connection->send( std::shared_ptr<PreLoginPacket>( new PreLoginPacket(L"-", ugcXuids, ugcXuidCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion,szUniqueMapName,app.GetGameHostOption(eGameHostOption_All),hostIndex, server->m_texturePackId) ) );
{
connection->send(std::shared_ptr<PreLoginPacket>(
new PreLoginPacket(L"-", ugcXuids, ugcXuidCount, ugcFriendsOnlyBits,
server->m_ugcPlayersVersion, szUniqueMapName,
app.GetGameHostOption(eGameHostOption_All),
hostIndex, server->m_texturePackId)));
}
}
void PendingConnection::handleLogin(std::shared_ptr<LoginPacket> packet)
{
fprintf(stderr, "[LOGIN-SRV] handleLogin called! clientVersion=%d\n", packet->clientVersion);
//name = packet->userName;
if (packet->clientVersion != SharedConstants::NETWORK_PROTOCOL_VERSION)
{
app.DebugPrintf("Client version is %d not equal to %d\n", packet->clientVersion, SharedConstants::NETWORK_PROTOCOL_VERSION);
if (packet->clientVersion > SharedConstants::NETWORK_PROTOCOL_VERSION)
{
void PendingConnection::handleLogin(std::shared_ptr<LoginPacket> packet) {
fprintf(stderr, "[LOGIN-SRV] handleLogin called! clientVersion=%d\n",
packet->clientVersion);
// name = packet->userName;
if (packet->clientVersion != SharedConstants::NETWORK_PROTOCOL_VERSION) {
app.DebugPrintf("Client version is %d not equal to %d\n",
packet->clientVersion,
SharedConstants::NETWORK_PROTOCOL_VERSION);
if (packet->clientVersion > SharedConstants::NETWORK_PROTOCOL_VERSION) {
disconnect(DisconnectPacket::eDisconnect_OutdatedServer);
}
else
{
} else {
disconnect(DisconnectPacket::eDisconnect_OutdatedClient);
}
return;
}
//if (true)// 4J removed !server->onlineMode)
bool sentDisconnect = false;
// if (true)// 4J removed !server->onlineMode)
bool sentDisconnect = false;
if( sentDisconnect )
{
// Do nothing
}
else if( server->getPlayers()->isXuidBanned( packet->m_onlineXuid ) )
{
disconnect(DisconnectPacket::eDisconnect_Banned);
}
else
{
if (sentDisconnect) {
// Do nothing
} else if (server->getPlayers()->isXuidBanned(packet->m_onlineXuid)) {
disconnect(DisconnectPacket::eDisconnect_Banned);
} else {
handleAcceptedLogin(packet);
}
//else
{
//4J - removed
// else
{
// 4J - removed
#if 0
new Thread() {
public void run() {
@@ -197,75 +190,71 @@ void PendingConnection::handleLogin(std::shared_ptr<LoginPacket> packet)
}.start();
#endif
}
}
void PendingConnection::handleAcceptedLogin(std::shared_ptr<LoginPacket> packet)
{
if(packet->m_ugcPlayersVersion != server->m_ugcPlayersVersion)
{
// Send the pre-login packet again with the new list of players
sendPreLoginResponse();
return;
}
void PendingConnection::handleAcceptedLogin(
std::shared_ptr<LoginPacket> packet) {
if (packet->m_ugcPlayersVersion != server->m_ugcPlayersVersion) {
// Send the pre-login packet again with the new list of players
sendPreLoginResponse();
return;
}
// Guests use the online xuid, everyone else uses the offline one
PlayerUID playerXuid = packet->m_offlineXuid;
if(playerXuid == INVALID_XUID) playerXuid = packet->m_onlineXuid;
// Guests use the online xuid, everyone else uses the offline one
PlayerUID playerXuid = packet->m_offlineXuid;
if (playerXuid == INVALID_XUID) playerXuid = packet->m_onlineXuid;
std::shared_ptr<ServerPlayer> playerEntity = server->getPlayers()->getPlayerForLogin(this, name, playerXuid,packet->m_onlineXuid);
if (playerEntity != NULL)
{
std::shared_ptr<ServerPlayer> playerEntity =
server->getPlayers()->getPlayerForLogin(this, name, playerXuid,
packet->m_onlineXuid);
if (playerEntity != NULL) {
server->getPlayers()->placeNewPlayer(connection, playerEntity, packet);
connection = NULL; // We've moved responsibility for this over to the new PlayerConnection, NULL so we don't delete our reference to it here in our dtor
connection = NULL; // We've moved responsibility for this over to the
// new PlayerConnection, NULL so we don't delete our
// reference to it here in our dtor
}
done = true;
}
void PendingConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason, void *reasonObjects)
{
// logger.info(getName() + " lost connection");
void PendingConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason,
void* reasonObjects) {
// logger.info(getName() + " lost connection");
done = true;
}
void PendingConnection::handleGetInfo(std::shared_ptr<GetInfoPacket> packet)
{
//try {
//String message = server->motd + "§" + server->players->getPlayerCount() + "§" + server->players->getMaxPlayers();
//connection->send(new DisconnectPacket(message));
connection->send(std::shared_ptr<DisconnectPacket>(new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull) ) );
connection->sendAndQuit();
server->connection->removeSpamProtection(connection->getSocket());
done = true;
//} catch (Exception e) {
// e.printStackTrace();
//}
void PendingConnection::handleGetInfo(std::shared_ptr<GetInfoPacket> packet) {
// try {
// String message = server->motd + "§" + server->players->getPlayerCount() +
// "§" + server->players->getMaxPlayers(); connection->send(new
// DisconnectPacket(message));
connection->send(std::shared_ptr<DisconnectPacket>(
new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull)));
connection->sendAndQuit();
server->connection->removeSpamProtection(connection->getSocket());
done = true;
//} catch (Exception e) {
// e.printStackTrace();
//}
}
void PendingConnection::handleKeepAlive(std::shared_ptr<KeepAlivePacket> packet)
{
// Ignore
void PendingConnection::handleKeepAlive(
std::shared_ptr<KeepAlivePacket> packet) {
// Ignore
}
void PendingConnection::onUnhandledPacket(std::shared_ptr<Packet> packet)
{
disconnect(DisconnectPacket::eDisconnect_UnexpectedPacket);
void PendingConnection::onUnhandledPacket(std::shared_ptr<Packet> packet) {
disconnect(DisconnectPacket::eDisconnect_UnexpectedPacket);
}
void PendingConnection::send(std::shared_ptr<Packet> packet)
{
connection->send(packet);
void PendingConnection::send(std::shared_ptr<Packet> packet) {
connection->send(packet);
}
std::wstring PendingConnection::getName()
{
return L"Unimplemented";
// if (name != null) return name + " [" + connection.getRemoteAddress().toString() + "]";
// return connection.getRemoteAddress().toString();
std::wstring PendingConnection::getName() {
return L"Unimplemented";
// if (name != null) return name + " [" +
// connection.getRemoteAddress().toString() + "]"; return
// connection.getRemoteAddress().toString();
}
bool PendingConnection::isServerPacketListener()
{
return true;
}
bool PendingConnection::isServerPacketListener() { return true; }