Updated to 1.16.5

This commit is contained in:
LOOHP 2021-01-16 11:08:43 +08:00
parent 1040e75ca9
commit aeac3730ac
4 changed files with 15 additions and 21 deletions

View File

@ -51,7 +51,7 @@
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
<finalName>${project.artifactId}-${project.version}-1.16.4</finalName> <finalName>${project.artifactId}-${project.version}-1.16.5</finalName>
</build> </build>
<repositories> <repositories>

View File

@ -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 int serverImplmentationProtocol = 754;
public final String limboImplementationVersion; public final String limboImplementationVersion;

View File

@ -13,6 +13,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.loohp.limbo.DeclareCommands; import com.loohp.limbo.DeclareCommands;
@ -89,16 +90,17 @@ public class ClientConnection extends Thread {
private ClientState state; private ClientState state;
private Player player; private Player player;
private long lastKeepAlivePayLoad; private AtomicLong lastKeepAlivePayLoad;
protected DataOutputStream output; private DataOutputStream output;
protected DataInputStream input; private DataInputStream input;
private InetAddress inetAddress; private InetAddress inetAddress;
public ClientConnection(Socket client_socket) { public ClientConnection(Socket client_socket) {
this.client_socket = client_socket; this.client_socket = client_socket;
this.inetAddress = client_socket.getInetAddress(); this.inetAddress = client_socket.getInetAddress();
this.lastKeepAlivePayLoad = new AtomicLong();
} }
public InetAddress getInetAddress() { public InetAddress getInetAddress() {
@ -106,11 +108,11 @@ public class ClientConnection extends Thread {
} }
public long getLastKeepAlivePayLoad() { public long getLastKeepAlivePayLoad() {
return lastKeepAlivePayLoad; return lastKeepAlivePayLoad.get();
} }
public void setLastKeepAlivePayLoad(long payLoad) { public void setLastKeepAlivePayLoad(long payLoad) {
this.lastKeepAlivePayLoad = payLoad; this.lastKeepAlivePayLoad.set(payLoad);
} }
public Player getPlayer() { public Player getPlayer() {
@ -129,19 +131,17 @@ public class ClientConnection extends Thread {
return running; return running;
} }
public void sendPacket(PacketOut packet) throws IOException { public synchronized void sendPacket(PacketOut packet) throws IOException {
byte[] packetByte = packet.serializePacket(); byte[] packetByte = packet.serializePacket();
DataTypeIO.writeVarInt(output, packetByte.length); DataTypeIO.writeVarInt(output, packetByte.length);
output.write(packetByte); output.write(packetByte);
output.flush();
} }
public void disconnect(BaseComponent[] reason) { public void disconnect(BaseComponent[] reason) {
try { try {
PacketPlayOutDisconnect packet = new PacketPlayOutDisconnect(ComponentSerializer.toString(reason)); PacketPlayOutDisconnect packet = new PacketPlayOutDisconnect(ComponentSerializer.toString(reason));
byte[] packetByte = packet.serializePacket(); sendPacket(packet);
DataTypeIO.writeVarInt(output, packetByte.length);
output.write(packetByte);
output.flush();
} catch (IOException e) {} } catch (IOException e) {}
try { try {
client_socket.close(); client_socket.close();
@ -151,10 +151,7 @@ public class ClientConnection extends Thread {
public void disconnectDuringLogin(BaseComponent[] reason) { public void disconnectDuringLogin(BaseComponent[] reason) {
try { try {
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(ComponentSerializer.toString(reason)); PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(ComponentSerializer.toString(reason));
byte[] packetByte = packet.serializePacket(); sendPacket(packet);
DataTypeIO.writeVarInt(output, packetByte.length);
output.write(packetByte);
output.flush();
} catch (IOException e) {} } catch (IOException e) {}
try { try {
client_socket.close(); client_socket.close();
@ -420,7 +417,7 @@ public class ClientConnection extends Thread {
} }
} else if (packetType.equals(PacketPlayInKeepAlive.class)) { } else if (packetType.equals(PacketPlayInKeepAlive.class)) {
PacketPlayInKeepAlive alive = new PacketPlayInKeepAlive(input); 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()); Limbo.getInstance().getConsole().sendMessage("Incorrect Payload recieved in KeepAlive packet for player " + player.getName());
break; break;
} }

View File

@ -7,7 +7,6 @@ import java.util.concurrent.TimeUnit;
import com.loohp.limbo.Limbo; import com.loohp.limbo.Limbo;
import com.loohp.limbo.Server.ClientConnection.ClientState; import com.loohp.limbo.Server.ClientConnection.ClientState;
import com.loohp.limbo.Server.Packets.PacketPlayOutKeepAlive; import com.loohp.limbo.Server.Packets.PacketPlayOutKeepAlive;
import com.loohp.limbo.Utils.DataTypeIO;
public class KeepAliveSender extends Thread { public class KeepAliveSender extends Thread {
@ -26,10 +25,8 @@ public class KeepAliveSender extends Thread {
if (client.getClientState().equals(ClientState.PLAY)) { if (client.getClientState().equals(ClientState.PLAY)) {
try { try {
PacketPlayOutKeepAlive packet = new PacketPlayOutKeepAlive(random.nextLong()); 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.setLastKeepAlivePayLoad(packet.getPayload());
client.sendPacket(packet);
} catch (IOException ignore) {} } catch (IOException ignore) {}
} }
} }