diff --git a/pom.xml b/pom.xml index 14cb2be..83dae03 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - ${project.artifactId}-${project.version}-1.16.4 + ${project.artifactId}-${project.version}-1.16.5 diff --git a/src/main/java/com/loohp/limbo/Limbo.java b/src/main/java/com/loohp/limbo/Limbo.java index f783522..54d8988 100644 --- a/src/main/java/com/loohp/limbo/Limbo.java +++ b/src/main/java/com/loohp/limbo/Limbo.java @@ -104,7 +104,7 @@ public class Limbo { //=========================== - public final String serverImplementationVersion = "1.16.4"; + public final String serverImplementationVersion = "1.16.5"; public final int serverImplmentationProtocol = 754; public final String limboImplementationVersion; diff --git a/src/main/java/com/loohp/limbo/Server/ClientConnection.java b/src/main/java/com/loohp/limbo/Server/ClientConnection.java index cbc6b30..4505828 100644 --- a/src/main/java/com/loohp/limbo/Server/ClientConnection.java +++ b/src/main/java/com/loohp/limbo/Server/ClientConnection.java @@ -13,6 +13,7 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import com.loohp.limbo.DeclareCommands; @@ -89,16 +90,17 @@ public class ClientConnection extends Thread { private ClientState state; private Player player; - private long lastKeepAlivePayLoad; + private AtomicLong lastKeepAlivePayLoad; - protected DataOutputStream output; - protected DataInputStream input; + private DataOutputStream output; + private DataInputStream input; private InetAddress inetAddress; public ClientConnection(Socket client_socket) { this.client_socket = client_socket; this.inetAddress = client_socket.getInetAddress(); + this.lastKeepAlivePayLoad = new AtomicLong(); } public InetAddress getInetAddress() { @@ -106,11 +108,11 @@ public class ClientConnection extends Thread { } public long getLastKeepAlivePayLoad() { - return lastKeepAlivePayLoad; + return lastKeepAlivePayLoad.get(); } public void setLastKeepAlivePayLoad(long payLoad) { - this.lastKeepAlivePayLoad = payLoad; + this.lastKeepAlivePayLoad.set(payLoad); } public Player getPlayer() { @@ -129,19 +131,17 @@ public class ClientConnection extends Thread { return running; } - public void sendPacket(PacketOut packet) throws IOException { + public synchronized void sendPacket(PacketOut packet) throws IOException { byte[] packetByte = packet.serializePacket(); DataTypeIO.writeVarInt(output, packetByte.length); output.write(packetByte); + output.flush(); } public void disconnect(BaseComponent[] reason) { try { PacketPlayOutDisconnect packet = new PacketPlayOutDisconnect(ComponentSerializer.toString(reason)); - byte[] packetByte = packet.serializePacket(); - DataTypeIO.writeVarInt(output, packetByte.length); - output.write(packetByte); - output.flush(); + sendPacket(packet); } catch (IOException e) {} try { client_socket.close(); @@ -151,10 +151,7 @@ public class ClientConnection extends Thread { public void disconnectDuringLogin(BaseComponent[] reason) { try { PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(ComponentSerializer.toString(reason)); - byte[] packetByte = packet.serializePacket(); - DataTypeIO.writeVarInt(output, packetByte.length); - output.write(packetByte); - output.flush(); + sendPacket(packet); } catch (IOException e) {} try { client_socket.close(); @@ -420,7 +417,7 @@ public class ClientConnection extends Thread { } } else if (packetType.equals(PacketPlayInKeepAlive.class)) { PacketPlayInKeepAlive alive = new PacketPlayInKeepAlive(input); - if (alive.getPayload() != lastKeepAlivePayLoad) { + if (alive.getPayload() != getLastKeepAlivePayLoad()) { Limbo.getInstance().getConsole().sendMessage("Incorrect Payload recieved in KeepAlive packet for player " + player.getName()); break; } diff --git a/src/main/java/com/loohp/limbo/Server/KeepAliveSender.java b/src/main/java/com/loohp/limbo/Server/KeepAliveSender.java index 09828a5..9fdf717 100644 --- a/src/main/java/com/loohp/limbo/Server/KeepAliveSender.java +++ b/src/main/java/com/loohp/limbo/Server/KeepAliveSender.java @@ -7,7 +7,6 @@ import java.util.concurrent.TimeUnit; import com.loohp.limbo.Limbo; import com.loohp.limbo.Server.ClientConnection.ClientState; import com.loohp.limbo.Server.Packets.PacketPlayOutKeepAlive; -import com.loohp.limbo.Utils.DataTypeIO; public class KeepAliveSender extends Thread { @@ -26,10 +25,8 @@ public class KeepAliveSender extends Thread { if (client.getClientState().equals(ClientState.PLAY)) { try { PacketPlayOutKeepAlive packet = new PacketPlayOutKeepAlive(random.nextLong()); - byte[] packetByte = packet.serializePacket(); - DataTypeIO.writeVarInt(client.output, packetByte.length); - client.output.write(packetByte); client.setLastKeepAlivePayLoad(packet.getPayload()); + client.sendPacket(packet); } catch (IOException ignore) {} } }