mirror of https://github.com/LOOHP/Limbo.git
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>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<name>Limbo</name>
|
||||
<version>0.7.0-ALPHA</version>
|
||||
<version>0.7.1-ALPHA</version>
|
||||
|
||||
<description>Standalone Limbo Minecraft Server.</description>
|
||||
<url>https://github.com/LOOHP/Limbo</url>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class PacketPlayInChat extends PacketIn {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -48,18 +48,14 @@ public class ArgumentSignatures {
|
|||
}
|
||||
}
|
||||
|
||||
public List<a> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public MessageSignature get(String s) {
|
||||
Iterator<ArgumentSignatures.a> iterator = this.entries.iterator();
|
||||
Iterator<a> iterator = this.entries.iterator();
|
||||
|
||||
ArgumentSignatures.a argumentsignatures_a;
|
||||
|
||||
do {
|
||||
if (!iterator.hasNext()) {
|
||||
return MessageSignature.EMPTY;
|
||||
return null;
|
||||
}
|
||||
|
||||
argumentsignatures_a = iterator.next();
|
||||
|
|
@ -69,44 +65,37 @@ public class ArgumentSignatures {
|
|||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
DataTypeIO.writeVarInt(out, entries.size());
|
||||
for (ArgumentSignatures.a argumentsignatures_a : entries) {
|
||||
DataTypeIO.writeVarInt(out, this.entries.size());
|
||||
for (a argumentsignatures_a : this.entries) {
|
||||
argumentsignatures_a.write(out);
|
||||
}
|
||||
}
|
||||
|
||||
public static class a {
|
||||
|
||||
private String name;
|
||||
private MessageSignature signature;
|
||||
private final String name;
|
||||
private final MessageSignature signature;
|
||||
|
||||
public a(String name, MessageSignature signature) {
|
||||
this.name = name;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MessageSignature getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
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 {
|
||||
DataTypeIO.writeString(out, name, StandardCharsets.UTF_8);
|
||||
this.signature.write(out);
|
||||
DataTypeIO.writeString(out, this.name, StandardCharsets.UTF_8);
|
||||
MessageSignature.write(out, this.signature);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
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.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LastSeenMessages {
|
||||
|
||||
public static LastSeenMessages EMPTY = new LastSeenMessages(Collections.emptyList());
|
||||
public static final int LAST_SEEN_MESSAGES_MAX_LENGTH = 5;
|
||||
public static final ArgumentSignatures EMPTY = new ArgumentSignatures(Collections.emptyList());
|
||||
private static final int MAX_ARGUMENT_COUNT = 8;
|
||||
private static final int MAX_ARGUMENT_NAME_LENGTH = 16;
|
||||
|
||||
private List<a> 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());
|
||||
}
|
||||
|
||||
}
|
||||
private List<MessageSignature> entries;
|
||||
|
||||
public static class a {
|
||||
|
||||
private UUID profileId;
|
||||
private MessageSignature lastSignature;
|
||||
public static final LastSeenMessages.a EMPTY = new LastSeenMessages.a(Collections.emptyList());
|
||||
|
||||
public UUID getProfileId() {
|
||||
return profileId;
|
||||
}
|
||||
private final List<MessageSignature.a> entries;
|
||||
|
||||
public MessageSignature getLastSignature() {
|
||||
return lastSignature;
|
||||
}
|
||||
|
||||
public a(UUID profileId, MessageSignature lastSignature) {
|
||||
this.profileId = profileId;
|
||||
this.lastSignature = lastSignature;
|
||||
public a(List<MessageSignature.a> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
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 {
|
||||
DataTypeIO.writeUUID(out, this.profileId);
|
||||
this.lastSignature.write(out);
|
||||
DataTypeIO.writeVarInt(out, this.entries.size());
|
||||
for (MessageSignature.a entry : this.entries) {
|
||||
MessageSignature.a.write(out, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class b {
|
||||
|
||||
private LastSeenMessages lastSeen;
|
||||
private Optional<a> lastReceived;
|
||||
private final int offset;
|
||||
private final BitSet acknowledged;
|
||||
|
||||
public b(LastSeenMessages lastSeen, Optional<LastSeenMessages.a> lastReceived) {
|
||||
this.lastSeen = lastSeen;
|
||||
this.lastReceived = lastReceived;
|
||||
public b(int offset, BitSet acknowledged) {
|
||||
this.offset = offset;
|
||||
this.acknowledged = acknowledged;
|
||||
}
|
||||
|
||||
public b(DataInputStream in) throws IOException {
|
||||
this.lastSeen = new LastSeenMessages(in);
|
||||
if (in.readBoolean()) {
|
||||
this.lastReceived = Optional.of(new LastSeenMessages.a(in));
|
||||
} else {
|
||||
this.lastReceived = Optional.empty();
|
||||
}
|
||||
this(DataTypeIO.readVarInt(in), DataTypeIO.readFixedBitSet(in, 20));
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
this.lastSeen.write(out);
|
||||
if (lastReceived.isPresent()) {
|
||||
out.writeBoolean(true);
|
||||
lastReceived.get().write(out);
|
||||
} else {
|
||||
out.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
|
||||
public LastSeenMessages getLastSeen() {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
public Optional<a> getLastReceived() {
|
||||
return lastReceived;
|
||||
DataTypeIO.writeVarInt(out, this.offset);
|
||||
DataTypeIO.writeFixedBitSet(out, this.acknowledged, 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,34 +28,25 @@ import java.util.Base64;
|
|||
|
||||
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) {
|
||||
this.bytes = bytes;
|
||||
public MessageSignature(byte[] abyte) {
|
||||
this.bytes = abyte;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
public static MessageSignature read(DataInputStream in) throws IOException {
|
||||
byte[] abyte = new byte[256];
|
||||
in.readFully(abyte);
|
||||
return new MessageSignature(abyte);
|
||||
}
|
||||
|
||||
public MessageSignature(DataInputStream in) throws IOException {
|
||||
this.bytes = new byte[DataTypeIO.readVarInt(in)];
|
||||
in.readFully(bytes);
|
||||
public static void write(DataOutputStream out, MessageSignature messagesignature) throws IOException {
|
||||
out.write(messagesignature.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() {
|
||||
return !this.isEmpty() ? ByteBuffer.wrap(this.bytes) : null;
|
||||
return ByteBuffer.wrap(this.bytes);
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
|
|
@ -86,7 +77,48 @@ public class MessageSignature {
|
|||
}
|
||||
|
||||
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