3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 23:30:26 +01:00

Fix rare NPE during server transition. Fixes #87

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-15 13:37:30 -04:00
Ursprung ab568405dd
Commit 88b7407aaf

Datei anzeigen

@ -55,6 +55,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void handle(MinecraftPacket packet) { public void handle(MinecraftPacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection == null) {
// No server connection yet, probably transitioning.
return;
}
if (packet instanceof KeepAlive) { if (packet instanceof KeepAlive) {
KeepAlive keepAlive = (KeepAlive) packet; KeepAlive keepAlive = (KeepAlive) packet;
if (keepAlive.getRandomId() != lastPingID) { if (keepAlive.getRandomId() != lastPingID) {
@ -64,7 +70,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
player.setPing(System.currentTimeMillis() - lastPingSent); player.setPing(System.currentTimeMillis() - lastPingSent);
resetPingData(); resetPingData();
player.getConnectedServer().getMinecraftConnection().write(packet); serverConnection.getMinecraftConnection().write(packet);
return; return;
} }
@ -112,7 +118,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getConnection().write(response); player.getConnection().write(response);
} else { } else {
player.getConnectedServer().getMinecraftConnection().write(packet); serverConnection.getMinecraftConnection().write(packet);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to provide tab list completions for " + player.getUsername() + " for command '" + req.getCommand() + "'", e); logger.error("Unable to provide tab list completions for " + player.getUsername() + " for command '" + req.getCommand() + "'", e);
@ -127,15 +133,21 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
// If we don't want to handle this packet, just forward it on. // If we don't want to handle this packet, just forward it on.
if (player.getConnectedServer().hasCompletedJoin()) { if (serverConnection.hasCompletedJoin()) {
player.getConnectedServer().getMinecraftConnection().write(packet); serverConnection.getMinecraftConnection().write(packet);
} }
} }
@Override @Override
public void handleUnknown(ByteBuf buf) { public void handleUnknown(ByteBuf buf) {
if (player.getConnectedServer().hasCompletedJoin()) { VelocityServerConnection serverConnection = player.getConnectedServer();
player.getConnectedServer().getMinecraftConnection().write(buf.retain()); if (serverConnection == null) {
// No server connection yet, probably transitioning.
return;
}
if (serverConnection.hasCompletedJoin()) {
serverConnection.getMinecraftConnection().write(buf.retain());
} }
} }