forked from BLOCKFANTASY/LOOHP-Limbo
Fixed receiving signed chat
This commit is contained in:
parent
35c6b748c9
commit
69bd4a8f6f
2
pom.xml
2
pom.xml
|
|
@ -24,7 +24,7 @@
|
||||||
<groupId>com.loohp</groupId>
|
<groupId>com.loohp</groupId>
|
||||||
<artifactId>Limbo</artifactId>
|
<artifactId>Limbo</artifactId>
|
||||||
<name>Limbo</name>
|
<name>Limbo</name>
|
||||||
<version>0.7.0-ALPHA</version>
|
<version>0.7.1-ALPHA</version>
|
||||||
|
|
||||||
<description>Standalone Limbo Minecraft Server.</description>
|
<description>Standalone Limbo Minecraft Server.</description>
|
||||||
<url>https://github.com/LOOHP/Limbo</url>
|
<url>https://github.com/LOOHP/Limbo</url>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ public class PacketPlayInChat extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketPlayInChat(DataInputStream in) throws IOException {
|
public PacketPlayInChat(DataInputStream in) throws IOException {
|
||||||
this(DataTypeIO.readString(in, StandardCharsets.UTF_8), Instant.ofEpochMilli(in.readLong()), in.readLong(), in.readBoolean() ? new MessageSignature(in) : null, new LastSeenMessages.b(in));
|
this(DataTypeIO.readString(in, StandardCharsets.UTF_8), Instant.ofEpochMilli(in.readLong()), in.readLong(), in.readBoolean() ? MessageSignature.read(in) : null, new LastSeenMessages.b(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
|
|
|
||||||
|
|
@ -48,18 +48,14 @@ public class ArgumentSignatures {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<a> getEntries() {
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageSignature get(String s) {
|
public MessageSignature get(String s) {
|
||||||
Iterator<ArgumentSignatures.a> iterator = this.entries.iterator();
|
Iterator<a> iterator = this.entries.iterator();
|
||||||
|
|
||||||
ArgumentSignatures.a argumentsignatures_a;
|
ArgumentSignatures.a argumentsignatures_a;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!iterator.hasNext()) {
|
if (!iterator.hasNext()) {
|
||||||
return MessageSignature.EMPTY;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
argumentsignatures_a = iterator.next();
|
argumentsignatures_a = iterator.next();
|
||||||
|
|
@ -69,44 +65,37 @@ public class ArgumentSignatures {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
public void write(DataOutputStream out) throws IOException {
|
||||||
DataTypeIO.writeVarInt(out, entries.size());
|
DataTypeIO.writeVarInt(out, this.entries.size());
|
||||||
for (ArgumentSignatures.a argumentsignatures_a : entries) {
|
for (a argumentsignatures_a : this.entries) {
|
||||||
argumentsignatures_a.write(out);
|
argumentsignatures_a.write(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class a {
|
public static class a {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
private MessageSignature signature;
|
private final MessageSignature signature;
|
||||||
|
|
||||||
public a(String name, MessageSignature signature) {
|
public a(String name, MessageSignature signature) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageSignature getSignature() {
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public a(DataInputStream in) throws IOException {
|
public a(DataInputStream in) throws IOException {
|
||||||
this(DataTypeIO.readString(in, StandardCharsets.UTF_8), new MessageSignature(in));
|
this(DataTypeIO.readString(in, StandardCharsets.UTF_8), MessageSignature.read(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
public void write(DataOutputStream out) throws IOException {
|
||||||
DataTypeIO.writeString(out, name, StandardCharsets.UTF_8);
|
DataTypeIO.writeString(out, this.name, StandardCharsets.UTF_8);
|
||||||
this.signature.write(out);
|
MessageSignature.write(out, this.signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface b {
|
public interface b {
|
||||||
|
|
||||||
MessageSignature sign(String s, String s1);
|
MessageSignature sign(String s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,117 +23,61 @@ import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class LastSeenMessages {
|
public class LastSeenMessages {
|
||||||
|
|
||||||
public static LastSeenMessages EMPTY = new LastSeenMessages(Collections.emptyList());
|
public static final ArgumentSignatures EMPTY = new ArgumentSignatures(Collections.emptyList());
|
||||||
public static final int LAST_SEEN_MESSAGES_MAX_LENGTH = 5;
|
private static final int MAX_ARGUMENT_COUNT = 8;
|
||||||
|
private static final int MAX_ARGUMENT_NAME_LENGTH = 16;
|
||||||
|
|
||||||
private List<a> entries;
|
private List<MessageSignature> entries;
|
||||||
|
|
||||||
public LastSeenMessages(List<LastSeenMessages.a> entries) {
|
|
||||||
this.entries = entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LastSeenMessages(DataInputStream in) throws IOException {
|
|
||||||
int size = DataTypeIO.readVarInt(in);
|
|
||||||
entries = new ArrayList<>(size);
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
entries.add(new LastSeenMessages.a(in));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
|
||||||
DataTypeIO.writeVarInt(out, entries.size());
|
|
||||||
for (LastSeenMessages.a lastseenmessages_a : entries) {
|
|
||||||
lastseenmessages_a.write(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateHash(DataOutputStream dataoutput) throws IOException {
|
|
||||||
Iterator<a> iterator = this.entries.iterator();
|
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
LastSeenMessages.a lastseenmessages_a = iterator.next();
|
|
||||||
UUID uuid = lastseenmessages_a.getProfileId();
|
|
||||||
MessageSignature messagesignature = lastseenmessages_a.getLastSignature();
|
|
||||||
|
|
||||||
dataoutput.writeByte(70);
|
|
||||||
dataoutput.writeLong(uuid.getMostSignificantBits());
|
|
||||||
dataoutput.writeLong(uuid.getLeastSignificantBits());
|
|
||||||
dataoutput.write(messagesignature.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class a {
|
public static class a {
|
||||||
|
|
||||||
private UUID profileId;
|
public static final LastSeenMessages.a EMPTY = new LastSeenMessages.a(Collections.emptyList());
|
||||||
private MessageSignature lastSignature;
|
|
||||||
|
|
||||||
public UUID getProfileId() {
|
private final List<MessageSignature.a> entries;
|
||||||
return profileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageSignature getLastSignature() {
|
public a(List<MessageSignature.a> entries) {
|
||||||
return lastSignature;
|
this.entries = entries;
|
||||||
}
|
|
||||||
|
|
||||||
public a(UUID profileId, MessageSignature lastSignature) {
|
|
||||||
this.profileId = profileId;
|
|
||||||
this.lastSignature = lastSignature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public a(DataInputStream in) throws IOException {
|
public a(DataInputStream in) throws IOException {
|
||||||
this(DataTypeIO.readUUID(in), new MessageSignature(in));
|
int size = DataTypeIO.readVarInt(in);
|
||||||
|
entries = new ArrayList<>(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
entries.add(MessageSignature.a.read(in));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
public void write(DataOutputStream out) throws IOException {
|
||||||
DataTypeIO.writeUUID(out, this.profileId);
|
DataTypeIO.writeVarInt(out, this.entries.size());
|
||||||
this.lastSignature.write(out);
|
for (MessageSignature.a entry : this.entries) {
|
||||||
|
MessageSignature.a.write(out, entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class b {
|
public static class b {
|
||||||
|
|
||||||
private LastSeenMessages lastSeen;
|
private final int offset;
|
||||||
private Optional<a> lastReceived;
|
private final BitSet acknowledged;
|
||||||
|
|
||||||
public b(LastSeenMessages lastSeen, Optional<LastSeenMessages.a> lastReceived) {
|
public b(int offset, BitSet acknowledged) {
|
||||||
this.lastSeen = lastSeen;
|
this.offset = offset;
|
||||||
this.lastReceived = lastReceived;
|
this.acknowledged = acknowledged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public b(DataInputStream in) throws IOException {
|
public b(DataInputStream in) throws IOException {
|
||||||
this.lastSeen = new LastSeenMessages(in);
|
this(DataTypeIO.readVarInt(in), DataTypeIO.readFixedBitSet(in, 20));
|
||||||
if (in.readBoolean()) {
|
|
||||||
this.lastReceived = Optional.of(new LastSeenMessages.a(in));
|
|
||||||
} else {
|
|
||||||
this.lastReceived = Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
public void write(DataOutputStream out) throws IOException {
|
||||||
this.lastSeen.write(out);
|
DataTypeIO.writeVarInt(out, this.offset);
|
||||||
if (lastReceived.isPresent()) {
|
DataTypeIO.writeFixedBitSet(out, this.acknowledged, 20);
|
||||||
out.writeBoolean(true);
|
|
||||||
lastReceived.get().write(out);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LastSeenMessages getLastSeen() {
|
|
||||||
return lastSeen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<a> getLastReceived() {
|
|
||||||
return lastReceived;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,34 +28,25 @@ import java.util.Base64;
|
||||||
|
|
||||||
public class MessageSignature {
|
public class MessageSignature {
|
||||||
|
|
||||||
public static final MessageSignature EMPTY = new MessageSignature(new byte[0]);
|
public static final int BYTES = 256;
|
||||||
|
|
||||||
private byte[] bytes;
|
private final byte[] bytes;
|
||||||
|
|
||||||
public MessageSignature(byte[] bytes) {
|
public MessageSignature(byte[] abyte) {
|
||||||
this.bytes = bytes;
|
this.bytes = abyte;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public static MessageSignature read(DataInputStream in) throws IOException {
|
||||||
return bytes;
|
byte[] abyte = new byte[256];
|
||||||
|
in.readFully(abyte);
|
||||||
|
return new MessageSignature(abyte);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageSignature(DataInputStream in) throws IOException {
|
public static void write(DataOutputStream out, MessageSignature messagesignature) throws IOException {
|
||||||
this.bytes = new byte[DataTypeIO.readVarInt(in)];
|
out.write(messagesignature.bytes);
|
||||||
in.readFully(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
|
||||||
out.write(this.bytes.length);
|
|
||||||
out.write(this.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return this.bytes.length == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ByteBuffer asByteBuffer() {
|
public ByteBuffer asByteBuffer() {
|
||||||
return !this.isEmpty() ? ByteBuffer.wrap(this.bytes) : null;
|
return ByteBuffer.wrap(this.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
|
|
@ -86,7 +77,48 @@ public class MessageSignature {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return !this.isEmpty() ? Base64.getEncoder().encodeToString(this.bytes) : "empty";
|
return Base64.getEncoder().encodeToString(this.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class a {
|
||||||
|
|
||||||
|
public static final int FULL_SIGNATURE = -1;
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final MessageSignature fullSignature;
|
||||||
|
|
||||||
|
public a(int id, MessageSignature messagesignature) {
|
||||||
|
this.id = id;
|
||||||
|
this.fullSignature = messagesignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public a(MessageSignature messagesignature) {
|
||||||
|
this(-1, messagesignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public a(int i) {
|
||||||
|
this(i, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageSignature fullSignature() {
|
||||||
|
return fullSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageSignature.a read(DataInputStream in) throws IOException {
|
||||||
|
int i = DataTypeIO.readVarInt(in) - 1;
|
||||||
|
return i == -1 ? new MessageSignature.a(MessageSignature.read(in)) : new MessageSignature.a(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(DataOutputStream out, MessageSignature.a messagesignature_a) throws IOException {
|
||||||
|
DataTypeIO.writeVarInt(out, messagesignature_a.id() + 1);
|
||||||
|
if (messagesignature_a.fullSignature() != null) {
|
||||||
|
MessageSignature.write(out, messagesignature_a.fullSignature());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue