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:
Ursprung
7130942032
Commit
8bf3b99b10
@ -41,39 +41,33 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
this.inbound = Preconditions.checkNotNull(inbound, "inbound");
|
this.inbound = Preconditions.checkNotNull(inbound, "inbound");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void activated() {
|
|
||||||
if (inbound.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) {
|
|
||||||
LoginPluginMessage message = new LoginPluginMessage();
|
|
||||||
playerInfoId = ThreadLocalRandom.current().nextInt();
|
|
||||||
message.setId(playerInfoId);
|
|
||||||
message.setChannel(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL);
|
|
||||||
message.setData(Unpooled.EMPTY_BUFFER);
|
|
||||||
inbound.write(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MinecraftPacket packet) {
|
public void handle(MinecraftPacket packet) {
|
||||||
if (packet instanceof LoginPluginResponse) {
|
if (packet instanceof LoginPluginResponse) {
|
||||||
LoginPluginResponse lpr = (LoginPluginResponse) packet;
|
LoginPluginResponse lpr = (LoginPluginResponse) packet;
|
||||||
if (lpr.getId() == playerInfoId && lpr.isSuccess()) {
|
if (lpr.getId() == playerInfoId) {
|
||||||
// Uh oh, someone's trying to run Velocity behind Velocity. We don't want that happening.
|
if (lpr.isSuccess()) {
|
||||||
inbound.closeWith(Disconnect.create(
|
// Uh oh, someone's trying to run Velocity behind Velocity. We don't want that happening.
|
||||||
TextComponent.of("Running Velocity behind Velocity isn't supported.", TextColor.RED)
|
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) {
|
} else if (packet instanceof ServerLogin) {
|
||||||
this.login = (ServerLogin) packet;
|
this.login = (ServerLogin) packet;
|
||||||
|
|
||||||
if (VelocityServer.getServer().getConfiguration().isOnlineMode()) {
|
if (inbound.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) {
|
||||||
// Request encryption.
|
LoginPluginMessage message = new LoginPluginMessage();
|
||||||
EncryptionRequest request = generateRequest();
|
playerInfoId = ThreadLocalRandom.current().nextInt();
|
||||||
this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
|
message.setId(playerInfoId);
|
||||||
inbound.write(request);
|
message.setChannel(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL);
|
||||||
|
message.setData(Unpooled.EMPTY_BUFFER);
|
||||||
|
inbound.write(message);
|
||||||
} 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);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren