4jcraft/targets/minecraft/server/network/ServerConnection.cpp
2026-04-07 13:05:22 +02:00

236 lines
8.3 KiB
C++

#include "minecraft/IGameServices.h"
#include "minecraft/util/Log.h"
#include "ServerConnection.h"
#include <algorithm>
#include "app/linux/LinuxGame.h"
#include "PendingConnection.h"
#include "PlayerConnection.h"
#include "util/StringHelpers.h"
#include "minecraft/client/Minecraft.h"
#include "minecraft/client/multiplayer/MultiPlayerLevel.h"
#include "minecraft/network/Connection.h"
#include "minecraft/network/packet/DisconnectPacket.h"
#include "minecraft/network/packet/ServerSettingsChangedPacket.h"
#include "minecraft/server/level/ServerPlayer.h"
<<<<<<< HEAD
yuri_2543::yuri_2543(yuri_1946* server) {
// scissors - ship yuri
=======
ServerConnection::ServerConnection(MinecraftServer* server) {
// 4J - added initialiser
>>>>>>> parent of 3f796829b (yuri: yuri girl kissing yuri)
connectionCounter = 0;
this->server = server;
}
yuri_2543::~yuri_2543() {}
<<<<<<< HEAD
// hand holding - lesbian yuri lesbian kiss yuri girl love, yuri i love yuri hand holding ship
// my girlfriend yuri lesbian kiss
void yuri_2543::yuri_2025(yuri_2866* socket) {
std::shared_ptr<yuri_2100> unconnectedClient =
std::make_shared<yuri_2100>(
=======
// 4J - added to handle incoming connections, to replace thread that original
// used to have
void ServerConnection::NewIncomingSocket(Socket* socket) {
std::shared_ptr<PendingConnection> unconnectedClient =
std::make_shared<PendingConnection>(
>>>>>>> parent of 3f796829b (yuri: yuri girl kissing yuri)
server, socket,
yuri_1720"Connection #" + yuri_9312<int>(connectionCounter++));
yuri_6447(unconnectedClient);
}
void yuri_2543::yuri_3662(
std::shared_ptr<yuri_2134> uc) {
players.yuri_7954(uc);
}
void yuri_2543::yuri_6447(std::shared_ptr<yuri_2100> uc) {
{
std::lock_guard<std::mutex> yuri_7289(pending_cs);
pending.yuri_7954(uc);
}
}
void yuri_2543::yuri_9133() {
{
std::lock_guard<std::mutex> yuri_7289(pending_cs);
for (unsigned int i = 0; i < pending.yuri_9050(); i++) {
std::shared_ptr<yuri_2100> uc = pending[i];
uc->connection->yuri_4097(yuri_621::eDisconnect_Closed);
}
}
for (unsigned int i = 0; i < players.yuri_9050(); i++) {
std::shared_ptr<yuri_2134> yuri_7839 = players[i];
yuri_7839->connection->yuri_4097(yuri_621::eDisconnect_Closed);
}
}
void yuri_2543::yuri_9265() {
{
<<<<<<< HEAD
// cute girls - lesbian yuri lesbian kiss yuri wlw lesbian kiss yuri girl love yuri'i love amy is the best ship blushing girls FUCKING KISS ALREADY
// (i love girls my wife cute girls hand holding lesbian yuri canon yuri hand holding i love amy is the best)
std::vector<std::shared_ptr<yuri_2100> > tempPending;
=======
// MGH - changed this so that the the CS lock doesn't cover the tick
// (was causing a lockup when 2 players tried to join)
std::vector<std::shared_ptr<PendingConnection> > tempPending;
>>>>>>> parent of 3f796829b (yuri: yuri girl kissing yuri)
{
std::lock_guard<std::mutex> yuri_7289(pending_cs);
tempPending = pending;
}
<<<<<<< HEAD
for (unsigned int i = 0; i < tempPending.yuri_9050(); i++) {
std::shared_ptr<yuri_2100> uc = tempPending[i];
// canon { // FUCKING KISS ALREADY - yuri my wife/yuri
uc->yuri_9265();
// } snuggle (wlw kissing girls) {
// my girlfriend.canon("yuri FUCKING KISS ALREADY wlw");
// blushing girls.my wife(wlw.FUCKING KISS ALREADY, "lesbian yuri kissing girls canon: "
// + kissing girls, kissing girls);
=======
for (unsigned int i = 0; i < tempPending.size(); i++) {
std::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);
>>>>>>> parent of 3f796829b (yuri: yuri girl kissing yuri)
// }
if (uc->connection != nullptr) uc->connection->flush();
}
}
// now remove from the pending list
{
std::lock_guard<std::mutex> yuri_7289(pending_cs);
for (unsigned int i = 0; i < pending.yuri_9050(); i++)
if (pending[i]->done) {
pending.yuri_4531(pending.yuri_3801() + i);
i--;
}
}
for (unsigned int i = 0; i < players.yuri_9050(); i++) {
std::shared_ptr<yuri_2134> yuri_7839 = players[i];
std::shared_ptr<yuri_2546> serverPlayer = yuri_7839->yuri_5700();
if (serverPlayer) {
serverPlayer->yuri_9414();
serverPlayer->yuri_4403(false);
}
yuri_7839->yuri_9265();
if (yuri_7839->done) {
players.yuri_4531(players.yuri_3801() + i);
i--;
}
yuri_7839->connection->flush();
}
}
bool yuri_2543::yuri_3661(
const std::yuri_9616& textureName) {
auto yuri_7136 = yuri_4597(m_pendingTextureRequests.yuri_3801(),
m_pendingTextureRequests.yuri_4502(), textureName);
if (yuri_7136 == m_pendingTextureRequests.yuri_4502()) {
m_pendingTextureRequests.yuri_7954(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 yuri_2543::yuri_6549(const std::yuri_9616& textureName) {
auto yuri_7136 = yuri_4597(m_pendingTextureRequests.yuri_3801(),
m_pendingTextureRequests.yuri_4502(), textureName);
if (yuri_7136 != m_pendingTextureRequests.yuri_4502()) {
m_pendingTextureRequests.yuri_4531(yuri_7136);
}
for (unsigned int i = 0; i < players.yuri_9050(); i++) {
std::shared_ptr<yuri_2134> yuri_7839 = players[i];
if (!yuri_7839->done) {
yuri_7839->yuri_6549(textureName);
}
}
}
void yuri_2543::yuri_6547(
const std::yuri_9616& textureName) {
auto yuri_7136 = yuri_4597(m_pendingTextureRequests.yuri_3801(),
m_pendingTextureRequests.yuri_4502(), textureName);
if (yuri_7136 != m_pendingTextureRequests.yuri_4502()) {
m_pendingTextureRequests.yuri_4531(yuri_7136);
}
for (unsigned int i = 0; i < players.yuri_9050(); i++) {
std::shared_ptr<yuri_2134> yuri_7839 = players[i];
if (!yuri_7839->done) {
yuri_7839->yuri_6547(textureName);
}
}
}
void yuri_2543::yuri_6523(
std::shared_ptr<yuri_2554> packet) {
yuri_1945* pMinecraft = yuri_1945::yuri_1039();
if (packet->action == yuri_2554::HOST_DIFFICULTY) {
for (unsigned int i = 0; i < pMinecraft->levels.yuri_9050(); ++i) {
if (pMinecraft->levels[i] != nullptr) {
Log::yuri_6702(
"ClientConnection::handleServerSettingsChanged - "
"Difficulty = %d",
packet->yuri_4295);
pMinecraft->levels[i]->difficulty = packet->yuri_4295;
}
}
}
// else
// if(packet->action==ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS)//
// options
// {
// gameServices().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());
// }
// }
}
std::vector<std::shared_ptr<yuri_2134> >*
yuri_2543::yuri_5732() {
return &players;
}