13
0
geforkt von Mirrors/Velocity

Merge branch 'dev/1.1.0' into decode-multiple

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-06-19 05:23:20 -04:00
Commit d1cbc7028a
3 geänderte Dateien mit 31 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -104,6 +104,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null;
private boolean explicitlyDisconnected = false;
ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
@ -281,9 +282,25 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Override
public void disconnect(Component reason) {
if (connection.eventLoop().inEventLoop()) {
disconnect0(reason, false);
} else {
connection.eventLoop().execute(() -> disconnect0(reason, false));
}
}
/**
* Disconnects the player from the proxy.
* @param reason the reason for disconnecting the player
* @param duringLogin whether the disconnect happened during login
*/
public void disconnect0(Component reason, boolean duringLogin) {
logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacy().serialize(reason));
this.explicitlyDisconnected = true;
connection.closeWith(Disconnect.create(reason));
server.getEventManager().fireAndForget(new DisconnectEvent(this, duringLogin));
}
@Override
@ -574,10 +591,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connectedServer.disconnect();
}
boolean isConnected = server.getPlayer(this.getUniqueId()).isPresent();
server.unregisterConnection(this);
server.getEventManager().fire(new DisconnectEvent(this, !isConnected))
.thenRun(() -> this.teardownFuture.complete(null));
if (!this.explicitlyDisconnected) {
server.getEventManager().fire(new DisconnectEvent(this, !isConnected))
.thenRun(() -> this.teardownFuture.complete(null));
} else {
this.teardownFuture.complete(null);
}
}
public CompletableFuture<Void> getTeardownFuture() {

Datei anzeigen

@ -204,7 +204,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
inbound.getVirtualHost().orElse(null), onlineMode);
this.connectedPlayer = player;
if (!server.canRegisterConnection(player)) {
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true);
return CompletableFuture.completedFuture(null);
}
@ -246,10 +246,10 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
Optional<Component> reason = event.getResult().getReason();
if (reason.isPresent()) {
player.disconnect(reason.get());
player.disconnect0(reason.get(), true);
} else {
if (!server.registerConnection(player)) {
player.disconnect(VelocityMessages.ALREADY_CONNECTED);
player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true);
return;
}
@ -269,7 +269,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
.thenRunAsync(() -> {
Optional<RegisteredServer> toTry = event.getInitialServer();
if (!toTry.isPresent()) {
player.disconnect(VelocityMessages.NO_AVAILABLE_SERVERS);
player.disconnect0(VelocityMessages.NO_AVAILABLE_SERVERS, true);
return;
}
player.createConnectionRequest(toTry.get()).fireAndForget();

Datei anzeigen

@ -14,6 +14,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteRequest implements MinecraftPacket {
private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;
private @Nullable String command;
private int transactionId;
private boolean assumeCommand;
@ -78,9 +80,9 @@ public class TabCompleteRequest implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) {
this.transactionId = ProtocolUtils.readVarInt(buf);
this.command = ProtocolUtils.readString(buf, Chat.MAX_SERVERBOUND_MESSAGE_LENGTH);
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
} else {
this.command = ProtocolUtils.readString(buf, Chat.MAX_SERVERBOUND_MESSAGE_LENGTH);
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
if (version.compareTo(MINECRAFT_1_9) >= 0) {
this.assumeCommand = buf.readBoolean();
}