13
0
geforkt von Mirrors/Velocity

Handle unexpected disconnects without a reason.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-15 01:46:28 -04:00
Ursprung 871319d679
Commit 84947564e4
4 geänderte Dateien mit 31 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -6,6 +6,7 @@ import com.velocitypowered.api.proxy.messages.MessageHandler;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.VelocityConstants;
import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.packet.*;
@ -44,6 +45,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
connection.getPlayer().getConnection().write(packet);
} else if (packet instanceof Disconnect) {
Disconnect original = (Disconnect) packet;
connection.disconnect();
connection.getPlayer().handleConnectionException(connection.getServerInfo(), original);
} else if (packet instanceof JoinGame) {
playerHandler.handleBackendJoinGame((JoinGame) packet);
@ -113,6 +115,18 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
connection.getPlayer().handleConnectionException(connection.getServerInfo(), throwable);
}
public VelocityServer getServer() {
return server;
}
@Override
public void disconnected() {
if (connection.isGracefulDisconnect()) {
return;
}
connection.getPlayer().handleConnectionException(connection.getServerInfo(), Disconnect.create(ConnectionMessages.UNEXPECTED_DISCONNECT));
}
private boolean canForwardPluginMessage(PluginMessage message) {
ClientPlaySessionHandler playerHandler =
(ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler();

Datei anzeigen

@ -44,6 +44,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
private MinecraftConnection minecraftConnection;
private boolean legacyForge = false;
private boolean hasCompletedJoin = false;
private boolean gracefulDisconnect = false;
public VelocityServerConnection(ServerInfo target, ConnectedPlayer proxyPlayer, VelocityServer server) {
this.serverInfo = target;
@ -148,6 +149,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
if (minecraftConnection != null) {
minecraftConnection.close();
minecraftConnection = null;
gracefulDisconnect = true;
}
}
@ -181,4 +183,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
public void setHasCompletedJoin(boolean hasCompletedJoin) {
this.hasCompletedJoin = hasCompletedJoin;
}
public boolean isGracefulDisconnect() {
return gracefulDisconnect;
}
}

Datei anzeigen

@ -205,14 +205,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
if (connectedServer != null && connectedServer.getServerInfo().equals(info)) {
logger.error("{}: kicked from server {}: {}", this, info.getName(), plainTextReason);
handleConnectionException(info, disconnectReason, TextComponent.builder()
.content("Kicked from " + info.getName() + ": ")
.color(TextColor.RED)
.append(disconnectReason)
.build());
} else {
logger.error("{}: disconnected while connecting to {}: {}", this, info.getName(), plainTextReason);
handleConnectionException(info, disconnectReason, TextComponent.builder()
.content("Unable to connect to " + info.getName() + ": ")
.color(TextColor.RED)
.append(disconnectReason)
.build());
}
handleConnectionException(info, disconnectReason, TextComponent.builder()
.content("Unable to connect to " + info.getName() + ": ")
.color(TextColor.RED)
.append(disconnectReason)
.build());
}
private void handleConnectionException(ServerInfo info, @Nullable Component kickReason, Component friendlyReason) {

Datei anzeigen

@ -7,6 +7,7 @@ public class ConnectionMessages {
public static final TextComponent ALREADY_CONNECTED = TextComponent.of("You are already connected to this server!", TextColor.RED);
public static final TextComponent IN_PROGRESS = TextComponent.of("You are already connecting to a server!", TextColor.RED);
public static final TextComponent INTERNAL_SERVER_CONNECTION_ERROR = TextComponent.of("Internal server connection error");
public static final TextComponent UNEXPECTED_DISCONNECT = TextComponent.of("Unexpectedly disconnected from server - crash?");
private ConnectionMessages() {
throw new AssertionError();