3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +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 {
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);