Clean this up a bit

This commit is contained in:
Andrew Steinborn
2018-07-31 13:44:10 -04:00
parent d4ee9235e6
commit 4b3675b571

View File

@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
public class LoginSessionHandler implements MinecraftSessionHandler {
private final ServerConnection connection;
private ScheduledFuture<?> modernForwardingNotice;
private ScheduledFuture<?> forwardingCheckTask;
public LoginSessionHandler(ServerConnection connection) {
this.connection = connection;
@@ -28,7 +28,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
@Override
public void activated() {
if (VelocityServer.getServer().getConfiguration().getIpForwardingMode() == IPForwardingMode.MODERN) {
modernForwardingNotice = connection.getMinecraftConnection().getChannel().eventLoop().schedule(() -> {
forwardingCheckTask = connection.getMinecraftConnection().getChannel().eventLoop().schedule(() -> {
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(),
TextComponent.of("Your server did not send the forwarding request in time. Is it set up correctly?"));
}, 1, TimeUnit.SECONDS);
@@ -49,10 +49,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
response.setData(createForwardingData(connection.getProxyPlayer().getRemoteAddress().getHostString(),
connection.getProxyPlayer().getProfile()));
connection.getMinecraftConnection().write(response);
if (modernForwardingNotice != null) {
modernForwardingNotice.cancel(false);
modernForwardingNotice = null;
}
cancelForwardingCheck();
ServerLogin login = new ServerLogin();
login.setUsername(connection.getProxyPlayer().getUsername());
@@ -90,10 +87,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
@Override
public void deactivated() {
if (modernForwardingNotice != null) {
modernForwardingNotice.cancel(false);
modernForwardingNotice = null;
}
cancelForwardingCheck();
}
@Override
@@ -101,6 +95,13 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), throwable);
}
private void cancelForwardingCheck() {
if (forwardingCheckTask != null) {
forwardingCheckTask.cancel(false);
forwardingCheckTask = null;
}
}
private static ByteBuf createForwardingData(String address, GameProfile profile) {
ByteBuf buf = Unpooled.buffer();
ProtocolUtils.writeString(buf, address);