mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 10:46:05 +03:00
64 lines
3.0 KiB
Diff
64 lines
3.0 KiB
Diff
From b620c5729a02c8618fef8a512d6e504a0413ca86 Mon Sep 17 00:00:00 2001
|
|
From: Jonas Konrad <me@yawk.at>
|
|
Date: Fri, 25 Apr 2014 23:46:46 +0200
|
|
Subject: [PATCH] Fix race condition that could kill connections before they
|
|
were initiated
|
|
|
|
Because NetworkManagers are registered before they get their channel in
|
|
channelActive, the ServerConnection would remove them sometimes because
|
|
it thought they were disconnected. This commit fixes this by introducing
|
|
a 'preparing' variable that is true while the NetworkManager is not
|
|
initialized. The ServerConnection does not remove NetworkManagers with
|
|
this flag.
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/NetworkManager.java b/src/main/java/net/minecraft/network/NetworkManager.java
|
|
index 9d942f125..927b59532 100644
|
|
--- a/src/main/java/net/minecraft/network/NetworkManager.java
|
|
+++ b/src/main/java/net/minecraft/network/NetworkManager.java
|
|
@@ -81,6 +81,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
|
// Spigot Start
|
|
public java.util.UUID spoofedUUID;
|
|
public com.mojang.authlib.properties.Property[] spoofedProfile;
|
|
+ public boolean preparing = true;
|
|
// Spigot End
|
|
private PacketListener packetListener;
|
|
private IChatBaseComponent disconnectedReason;
|
|
@@ -101,6 +102,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
|
super.channelActive(channelhandlercontext);
|
|
this.channel = channelhandlercontext.channel();
|
|
this.address = this.channel.remoteAddress();
|
|
+ // Spigot Start
|
|
+ this.preparing = false;
|
|
+ // Spigot End
|
|
|
|
try {
|
|
this.setProtocol(EnumProtocol.HANDSHAKING);
|
|
@@ -284,6 +288,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
|
}
|
|
|
|
public void disconnect(IChatBaseComponent ichatbasecomponent) {
|
|
+ // Spigot Start
|
|
+ this.preparing = false;
|
|
+ // Spigot End
|
|
if (this.channel.isOpen()) {
|
|
this.channel.close(); // We can't wait as this may be called from an event loop.
|
|
this.disconnectedReason = ichatbasecomponent;
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerConnection.java b/src/main/java/net/minecraft/server/network/ServerConnection.java
|
|
index a2a2d1fa4..609dc7c5f 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerConnection.java
|
|
@@ -184,6 +184,10 @@ public class ServerConnection {
|
|
networkmanager.setReadOnly();
|
|
}
|
|
} else {
|
|
+ // Spigot Start
|
|
+ // Fix a race condition where a NetworkManager could be unregistered just before connection.
|
|
+ if (networkmanager.preparing) continue;
|
|
+ // Spigot End
|
|
iterator.remove();
|
|
networkmanager.handleDisconnection();
|
|
}
|
|
--
|
|
2.25.1
|
|
|