3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Cleaned up connection code.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-04 03:18:57 -04:00
Ursprung 0ba85fe83f
Commit 06a6493605
2 geänderte Dateien mit 13 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.IPForwardingMode;
import com.velocitypowered.proxy.connection.VelocityConstants;
@ -13,6 +14,7 @@ import com.velocitypowered.proxy.protocol.packet.*;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelPipeline;
import net.kyori.text.TextComponent;
import java.util.concurrent.ScheduledFuture;
@ -68,11 +70,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
connection.disconnect();
// Do we have an outstanding notification? If so, fulfill it.
ServerConnection.ConnectionNotifier n = connection.getMinecraftConnection().getChannel()
.pipeline().get(ServerConnection.ConnectionNotifier.class);
if (n != null) {
n.getResult().complete(ConnectionRequestResults.forDisconnect(disconnect));
}
doNotify(ConnectionRequestResults.forDisconnect(disconnect));
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), disconnect);
} else if (packet instanceof SetCompression) {
@ -91,12 +89,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
}
// Do we have an outstanding notification? If so, fulfill it.
ServerConnection.ConnectionNotifier n = connection.getMinecraftConnection().getChannel()
.pipeline().get(ServerConnection.ConnectionNotifier.class);
if (n != null) {
n.onComplete();
connection.getMinecraftConnection().getChannel().pipeline().remove(n);
}
doNotify(ConnectionRequestResults.SUCCESSFUL);
connection.getMinecraftConnection().setSessionHandler(new BackendPlaySessionHandler(connection));
connection.getProxyPlayer().setConnectedServer(connection);
@ -113,6 +106,15 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), throwable);
}
private void doNotify(ConnectionRequestBuilder.Result result) {
ChannelPipeline pipeline = connection.getMinecraftConnection().getChannel().pipeline();
ServerConnection.ConnectionNotifier n = pipeline.get(ServerConnection.ConnectionNotifier.class);
if (n != null) {
n.getResult().complete(result);
pipeline.remove(ServerConnection.ConnectionNotifier.class);
}
}
private void cancelForwardingCheck() {
if (forwardingCheckTask != null) {
forwardingCheckTask.cancel(false);

Datei anzeigen

@ -191,14 +191,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return connection.connect();
}
void connect(ServerInfo info) {
Preconditions.checkNotNull(info, "info");
Preconditions.checkState(connectionInFlight == null, "A connection is already active!");
ServerConnection connection = new ServerConnection(info, this, VelocityServer.getServer());
connectionInFlight = connection;
connection.connect();
}
public void setConnectedServer(ServerConnection serverConnection) {
if (this.connectedServer != null && !serverConnection.getServerInfo().equals(connectedServer.getServerInfo())) {
this.tryIndex = 0;