3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 14:40:21 +02:00

Clean this up a bit

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-07-31 13:44:10 -04:00
Ursprung d4ee9235e6
Commit 4b3675b571

Datei anzeigen

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