Cleaned up connection code.

This commit is contained in:
Andrew Steinborn 2018-08-04 03:18:57 -04:00
parent 0ba85fe83f
commit 06a6493605
2 changed files with 13 additions and 19 deletions

View File

@ -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);

View File

@ -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;