Files
itsRevela 20229fc07b fix: dedicated server thread safety, disconnect deadlock, and console freeze
- Protect PlayerList and ServerConnection players vectors with critical
  sections; all iterations use copy-on-read snapshots to prevent iterator
  invalidation during concurrent join/leave
- Add null check on player bounding box in movement validation to prevent
  crash when player is removed mid-tick
- Re-validate socket player pointer immediately before SendData to narrow
  the TOCTOU race window on disconnect
- Replace inline disconnect cleanup with a queued system drained on the
  main tick thread, eliminating the done_cs -> m_playersCS lock inversion
  that caused deadlocks under load
- Disable Windows QuickEdit mode at server startup to prevent console
  input selection from freezing the process
- Move chunk priority sort behind ServerConnection::sortPlayersByChunkPriority()
  to keep the players vector lock-protected
2026-04-10 01:12:59 -05:00

54 lines
1.6 KiB
C++

#pragma once
class PendingConnection;
class PlayerConnection;
class MinecraftServer;
class Socket;
class ServerSettingsChangedPacket;
using namespace std;
class ServerConnection
{
// public static Logger logger = Logger.getLogger("Minecraft");
private:
// ServerSocket serverSocket;
// private Thread listenThread;
public:
volatile bool running;
private:
int connectionCounter;
private:
CRITICAL_SECTION pending_cs; // 4J added
CRITICAL_SECTION players_cs; // Protects players vector for concurrent access
vector< shared_ptr<PendingConnection> > pending;
vector< shared_ptr<PlayerConnection> > players;
// 4J - When the server requests a texture, it should add it to here while we are waiting for it
vector<wstring> m_pendingTextureRequests;
public:
MinecraftServer *server;
public:
ServerConnection(MinecraftServer *server); // 4J - removed params InetAddress address, int port);
~ServerConnection();
void NewIncomingSocket(Socket *socket); // 4J - added
void removeSpamProtection(Socket *socket) { }// 4J Stu - Not implemented as not required
void addPlayerConnection(shared_ptr<PlayerConnection> uc);
private:
void handleConnection(shared_ptr<PendingConnection> uc);
public:
void stop();
void tick();
// 4J Added
bool addPendingTextureRequest(const wstring &textureName);
void handleTextureReceived(const wstring &textureName);
void handleTextureAndGeometryReceived(const wstring &textureName);
void handleServerSettingsChanged(shared_ptr<ServerSettingsChangedPacket> packet);
vector< shared_ptr<PlayerConnection> > *getPlayers();
vector< shared_ptr<PlayerConnection> > getPlayersSnapshot();
void sortPlayersByChunkPriority();
};