3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-06 00:00:47 +01:00

Make sure the client has time to respond to the player info packet.

Apparently, Minecraft 1.13 can take a little too long to respond to
Velocity's player info forwarding packet. This especially noticeable in
offline mode: by the time the client does respond, Velocity has already
completed the login process and tried connecting to the server (it is
very quick under offline mode).

Noticed by Leymooo.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-10 23:40:26 -04:00
Ursprung 7130942032
Commit 8bf3b99b10

Datei anzeigen

@ -42,7 +42,23 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public void activated() { public void handle(MinecraftPacket packet) {
if (packet instanceof LoginPluginResponse) {
LoginPluginResponse lpr = (LoginPluginResponse) packet;
if (lpr.getId() == playerInfoId) {
if (lpr.isSuccess()) {
// Uh oh, someone's trying to run Velocity behind Velocity. We don't want that happening.
inbound.closeWith(Disconnect.create(
TextComponent.of("Running Velocity behind Velocity isn't supported.", TextColor.RED)
));
} else {
// Proceed with the regular login process.
initiateLogin();
}
}
} else if (packet instanceof ServerLogin) {
this.login = (ServerLogin) packet;
if (inbound.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { if (inbound.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) {
LoginPluginMessage message = new LoginPluginMessage(); LoginPluginMessage message = new LoginPluginMessage();
playerInfoId = ThreadLocalRandom.current().nextInt(); playerInfoId = ThreadLocalRandom.current().nextInt();
@ -50,30 +66,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
message.setChannel(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL); message.setChannel(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL);
message.setData(Unpooled.EMPTY_BUFFER); message.setData(Unpooled.EMPTY_BUFFER);
inbound.write(message); inbound.write(message);
}
}
@Override
public void handle(MinecraftPacket packet) {
if (packet instanceof LoginPluginResponse) {
LoginPluginResponse lpr = (LoginPluginResponse) packet;
if (lpr.getId() == playerInfoId && lpr.isSuccess()) {
// Uh oh, someone's trying to run Velocity behind Velocity. We don't want that happening.
inbound.closeWith(Disconnect.create(
TextComponent.of("Running Velocity behind Velocity isn't supported.", TextColor.RED)
));
}
} else if (packet instanceof ServerLogin) {
this.login = (ServerLogin) packet;
if (VelocityServer.getServer().getConfiguration().isOnlineMode()) {
// Request encryption.
EncryptionRequest request = generateRequest();
this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
inbound.write(request);
} else { } else {
// Offline-mode, don't try to request encryption. initiateLogin();
handleSuccessfulLogin(GameProfile.forOfflinePlayer(login.getUsername()));
} }
} else if (packet instanceof EncryptionResponse) { } else if (packet instanceof EncryptionResponse) {
try { try {
@ -119,6 +113,18 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
} }
private void initiateLogin() {
if (VelocityServer.getServer().getConfiguration().isOnlineMode()) {
// Request encryption.
EncryptionRequest request = generateRequest();
this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
inbound.write(request);
} else {
// Offline-mode, don't try to request encryption.
handleSuccessfulLogin(GameProfile.forOfflinePlayer(login.getUsername()));
}
}
private EncryptionRequest generateRequest() { private EncryptionRequest generateRequest() {
byte[] verify = new byte[4]; byte[] verify = new byte[4];
ThreadLocalRandom.current().nextBytes(verify); ThreadLocalRandom.current().nextBytes(verify);