mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Cleanup
This commit is contained in:
parent
c85e866e3c
commit
b8c30d9b58
@ -6,12 +6,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class BooleanData extends DataType<Boolean> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Boolean value) {
|
||||
binaryWriter.writeBoolean(value);
|
||||
public void encode(BinaryWriter writer, Boolean value) {
|
||||
writer.writeBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readBoolean();
|
||||
public Boolean decode(BinaryReader reader) {
|
||||
return reader.readBoolean();
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class ByteData extends DataType<Byte> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Byte value) {
|
||||
binaryWriter.writeByte(value);
|
||||
public void encode(BinaryWriter writer, Byte value) {
|
||||
writer.writeByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readByte();
|
||||
public Byte decode(BinaryReader reader) {
|
||||
return reader.readByte();
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class CharacterData extends DataType<Character> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Character value) {
|
||||
binaryWriter.writeChar(value);
|
||||
public void encode(BinaryWriter writer, Character value) {
|
||||
writer.writeChar(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readChar();
|
||||
public Character decode(BinaryReader reader) {
|
||||
return reader.readChar();
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class DoubleData extends DataType<Double> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Double value) {
|
||||
binaryWriter.writeDouble(value);
|
||||
public void encode(BinaryWriter writer, Double value) {
|
||||
writer.writeDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readDouble();
|
||||
public Double decode(BinaryReader reader) {
|
||||
return reader.readDouble();
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class FloatData extends DataType<Float> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Float value) {
|
||||
binaryWriter.writeFloat(value);
|
||||
public void encode(BinaryWriter writer, Float value) {
|
||||
writer.writeFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readFloat();
|
||||
public Float decode(BinaryReader reader) {
|
||||
return reader.readFloat();
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class IntegerData extends DataType<Integer> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Integer value) {
|
||||
binaryWriter.writeVarInt(value);
|
||||
public void encode(BinaryWriter writer, Integer value) {
|
||||
writer.writeVarInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readVarInt();
|
||||
public Integer decode(BinaryReader reader) {
|
||||
return reader.readVarInt();
|
||||
}
|
||||
}
|
@ -9,31 +9,31 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class InventoryData extends DataType<Inventory> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Inventory value) {
|
||||
public void encode(BinaryWriter writer, Inventory value) {
|
||||
final InventoryType inventoryType = value.getInventoryType();
|
||||
final int size = inventoryType.getAdditionalSlot();
|
||||
|
||||
// Inventory title & type
|
||||
binaryWriter.writeSizedString(value.getTitle());
|
||||
binaryWriter.writeSizedString(inventoryType.name());
|
||||
writer.writeSizedString(value.getTitle());
|
||||
writer.writeSizedString(inventoryType.name());
|
||||
|
||||
// Write all item stacks
|
||||
for (int i = 0; i < size; i++) {
|
||||
binaryWriter.writeItemStack(value.getItemStack(i));
|
||||
writer.writeItemStack(value.getItemStack(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory decode(BinaryReader binaryReader) {
|
||||
final String title = binaryReader.readSizedString();
|
||||
final InventoryType inventoryType = InventoryType.valueOf(binaryReader.readSizedString());
|
||||
public Inventory decode(BinaryReader reader) {
|
||||
final String title = reader.readSizedString();
|
||||
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString());
|
||||
final int size = inventoryType.getAdditionalSlot();
|
||||
|
||||
Inventory inventory = new Inventory(inventoryType, title);
|
||||
|
||||
// Read all item stacks
|
||||
for (int i = 0; i < size; i++) {
|
||||
inventory.setItemStack(i, binaryReader.readSlot());
|
||||
inventory.setItemStack(i, reader.readSlot());
|
||||
}
|
||||
|
||||
return inventory;
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class ItemStackData extends DataType<ItemStack> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, ItemStack value) {
|
||||
binaryWriter.writeItemStack(value);
|
||||
public void encode(BinaryWriter writer, ItemStack value) {
|
||||
writer.writeItemStack(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readSlot();
|
||||
public ItemStack decode(BinaryReader reader) {
|
||||
return reader.readSlot();
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class LongData extends DataType<Long> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Long value) {
|
||||
binaryWriter.writeLong(value);
|
||||
public void encode(BinaryWriter writer, Long value) {
|
||||
writer.writeLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readLong();
|
||||
public Long decode(BinaryReader reader) {
|
||||
return reader.readLong();
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class SerializableDataData extends DataType<SerializableData> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, SerializableData value) {
|
||||
binaryWriter.writeBytes(value.getSerializedData());
|
||||
public void encode(BinaryWriter writer, SerializableData value) {
|
||||
writer.writeBytes(value.getSerializedData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializableData decode(BinaryReader binaryReader) {
|
||||
return DataReader.readData(binaryReader);
|
||||
public SerializableData decode(BinaryReader reader) {
|
||||
return DataReader.readData(reader);
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class ShortData extends DataType<Short> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, Short value) {
|
||||
binaryWriter.writeShort(value);
|
||||
public void encode(BinaryWriter writer, Short value) {
|
||||
writer.writeShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readShort();
|
||||
public Short decode(BinaryReader reader) {
|
||||
return reader.readShort();
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class StringData extends DataType<String> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, String value) {
|
||||
binaryWriter.writeSizedString(value);
|
||||
public void encode(BinaryWriter writer, String value) {
|
||||
writer.writeSizedString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readSizedString();
|
||||
public String decode(BinaryReader reader) {
|
||||
return reader.readSizedString();
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import java.util.UUID;
|
||||
|
||||
public class UuidType extends DataType<UUID> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, UUID value) {
|
||||
binaryWriter.writeUuid(value);
|
||||
public void encode(BinaryWriter writer, UUID value) {
|
||||
writer.writeUuid(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID decode(BinaryReader binaryReader) {
|
||||
return binaryReader.readUuid();
|
||||
public UUID decode(BinaryReader reader) {
|
||||
return reader.readUuid();
|
||||
}
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class BooleanArrayData extends DataType<boolean[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, boolean[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, boolean[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (boolean val : value) {
|
||||
binaryWriter.writeBoolean(val);
|
||||
writer.writeBoolean(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean[] decode(BinaryReader binaryReader) {
|
||||
boolean[] array = new boolean[binaryReader.readVarInt()];
|
||||
public boolean[] decode(BinaryReader reader) {
|
||||
boolean[] array = new boolean[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readBoolean();
|
||||
array[i] = reader.readBoolean();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class ByteArrayData extends DataType<byte[]> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, byte[] value) {
|
||||
encodeByteArray(binaryWriter, value);
|
||||
public void encode(BinaryWriter writer, byte[] value) {
|
||||
encodeByteArray(writer, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(BinaryReader binaryReader) {
|
||||
return decodeByteArray(binaryReader);
|
||||
public byte[] decode(BinaryReader reader) {
|
||||
return decodeByteArray(reader);
|
||||
}
|
||||
|
||||
public static void encodeByteArray(BinaryWriter binaryWriter, byte[] value) {
|
||||
|
@ -6,18 +6,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class CharacterArrayData extends DataType<char[]> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, char[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, char[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (char val : value) {
|
||||
binaryWriter.writeChar(val);
|
||||
writer.writeChar(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] decode(BinaryReader binaryReader) {
|
||||
char[] array = new char[binaryReader.readVarInt()];
|
||||
public char[] decode(BinaryReader reader) {
|
||||
char[] array = new char[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readChar();
|
||||
array[i] = reader.readChar();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class DoubleArrayData extends DataType<double[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, double[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, double[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (double val : value) {
|
||||
binaryWriter.writeDouble(val);
|
||||
writer.writeDouble(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] decode(BinaryReader binaryReader) {
|
||||
double[] array = new double[binaryReader.readVarInt()];
|
||||
public double[] decode(BinaryReader reader) {
|
||||
double[] array = new double[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readDouble();
|
||||
array[i] = reader.readDouble();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class FloatArrayData extends DataType<float[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, float[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, float[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (float val : value) {
|
||||
binaryWriter.writeFloat(val);
|
||||
writer.writeFloat(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] decode(BinaryReader binaryReader) {
|
||||
float[] array = new float[binaryReader.readVarInt()];
|
||||
public float[] decode(BinaryReader reader) {
|
||||
float[] array = new float[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readFloat();
|
||||
array[i] = reader.readFloat();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class IntegerArrayData extends DataType<int[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, int[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, int[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (int val : value) {
|
||||
binaryWriter.writeInt(val);
|
||||
writer.writeInt(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] decode(BinaryReader binaryReader) {
|
||||
int[] array = new int[binaryReader.readVarInt()];
|
||||
public int[] decode(BinaryReader reader) {
|
||||
int[] array = new int[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readInteger();
|
||||
array[i] = reader.readInteger();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public class ItemStackArrayData extends DataType<ItemStack[]> {
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, ItemStack[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, ItemStack[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (ItemStack itemStack : value) {
|
||||
binaryWriter.writeItemStack(itemStack);
|
||||
writer.writeItemStack(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] decode(BinaryReader binaryReader) {
|
||||
ItemStack[] items = new ItemStack[binaryReader.readVarInt()];
|
||||
public ItemStack[] decode(BinaryReader reader) {
|
||||
ItemStack[] items = new ItemStack[reader.readVarInt()];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = binaryReader.readSlot();
|
||||
items[i] = reader.readSlot();
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class LongArrayData extends DataType<long[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, long[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, long[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (long val : value) {
|
||||
binaryWriter.writeLong(val);
|
||||
writer.writeLong(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] decode(BinaryReader binaryReader) {
|
||||
long[] array = new long[binaryReader.readVarInt()];
|
||||
public long[] decode(BinaryReader reader) {
|
||||
long[] array = new long[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readLong();
|
||||
array[i] = reader.readLong();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class ShortArrayData extends DataType<short[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, short[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, short[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (short val : value) {
|
||||
binaryWriter.writeShort(val);
|
||||
writer.writeShort(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public short[] decode(BinaryReader binaryReader) {
|
||||
short[] array = new short[binaryReader.readVarInt()];
|
||||
public short[] decode(BinaryReader reader) {
|
||||
short[] array = new short[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readShort();
|
||||
array[i] = reader.readShort();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -7,18 +7,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
public class StringArrayData extends DataType<String[]> {
|
||||
|
||||
@Override
|
||||
public void encode(BinaryWriter binaryWriter, String[] value) {
|
||||
binaryWriter.writeVarInt(value.length);
|
||||
public void encode(BinaryWriter writer, String[] value) {
|
||||
writer.writeVarInt(value.length);
|
||||
for (String val : value) {
|
||||
binaryWriter.writeSizedString(val);
|
||||
writer.writeSizedString(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] decode(BinaryReader binaryReader) {
|
||||
String[] array = new String[binaryReader.readVarInt()];
|
||||
public String[] decode(BinaryReader reader) {
|
||||
String[] array = new String[reader.readVarInt()];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = binaryReader.readSizedString();
|
||||
array[i] = reader.readSizedString();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -22,17 +22,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PacketProcessor {
|
||||
|
||||
private Map<ChannelHandlerContext, PlayerConnection> connectionPlayerConnectionMap = new ConcurrentHashMap<>();
|
||||
|
||||
private ConnectionManager connectionManager;
|
||||
private final Map<ChannelHandlerContext, PlayerConnection> connectionPlayerConnectionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// Protocols
|
||||
private ClientStatusPacketsHandler statusPacketsHandler;
|
||||
private ClientLoginPacketsHandler loginPacketsHandler;
|
||||
private ClientPlayPacketsHandler playPacketsHandler;
|
||||
private final ClientStatusPacketsHandler statusPacketsHandler;
|
||||
private final ClientLoginPacketsHandler loginPacketsHandler;
|
||||
private final ClientPlayPacketsHandler playPacketsHandler;
|
||||
|
||||
public PacketProcessor() {
|
||||
this.connectionManager = MinecraftServer.getConnectionManager();
|
||||
|
||||
this.statusPacketsHandler = new ClientStatusPacketsHandler();
|
||||
this.loginPacketsHandler = new ClientLoginPacketsHandler();
|
||||
@ -62,7 +59,7 @@ public class PacketProcessor {
|
||||
if (packet.packetId == 0) {
|
||||
HandshakePacket handshakePacket = new HandshakePacket();
|
||||
handshakePacket.read(binaryReader);
|
||||
handshakePacket.process(playerConnection, connectionManager);
|
||||
handshakePacket.process(playerConnection);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -77,13 +74,12 @@ public class PacketProcessor {
|
||||
case LOGIN:
|
||||
final ClientPreplayPacket loginPacket = (ClientPreplayPacket) loginPacketsHandler.getPacketInstance(packet.packetId);
|
||||
loginPacket.read(binaryReader);
|
||||
loginPacket.process(playerConnection, connectionManager);
|
||||
loginPacket.process(playerConnection);
|
||||
break;
|
||||
case STATUS:
|
||||
final ClientPreplayPacket statusPacket = (ClientPreplayPacket) statusPacketsHandler.getPacketInstance(packet.packetId);
|
||||
statusPacket.read(binaryReader);
|
||||
|
||||
statusPacket.process(playerConnection, connectionManager);
|
||||
statusPacket.process(playerConnection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
package net.minestom.server.network.packet.client;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
||||
public interface ClientPreplayPacket extends ClientPacket {
|
||||
|
||||
ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
|
||||
|
||||
void process(PlayerConnection connection, ConnectionManager connectionManager);
|
||||
|
||||
/**
|
||||
* Called when this packet is received
|
||||
*
|
||||
* @param connection the connection who sent the packet
|
||||
*/
|
||||
void process(PlayerConnection connection);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package net.minestom.server.network.packet.client.handshake;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginDisconnect;
|
||||
@ -26,7 +25,7 @@ public class HandshakePacket implements ClientPreplayPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
public void process(PlayerConnection connection) {
|
||||
switch (nextState) {
|
||||
case 1:
|
||||
connection.setConnectionState(ConnectionState.STATUS);
|
||||
|
@ -5,7 +5,6 @@ import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.data.type.array.ByteArrayData;
|
||||
import net.minestom.server.extras.mojangAuth.MojangCrypt;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
|
||||
@ -20,54 +19,54 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class EncryptionResponsePacket implements ClientPreplayPacket {
|
||||
|
||||
private final static String THREAD_NAME = "Mojang Auth Thread";
|
||||
private static AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
||||
private byte[] sharedSecret;
|
||||
private byte[] verifyToken;
|
||||
private final static String THREAD_NAME = "Mojang Auth Thread";
|
||||
private static AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
||||
private byte[] sharedSecret;
|
||||
private byte[] verifyToken;
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
new Thread(THREAD_NAME + " #" + UNIQUE_THREAD_ID.incrementAndGet()) {
|
||||
@Override
|
||||
public void process(PlayerConnection connection) {
|
||||
new Thread(THREAD_NAME + " #" + UNIQUE_THREAD_ID.incrementAndGet()) {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if (!Arrays.equals(connection.getNonce(), getNonce())) {
|
||||
System.out.println(connection.getLoginUsername() + " tried to login with an invalid nonce!");
|
||||
return;
|
||||
}
|
||||
if (!connection.getLoginUsername().isEmpty()) {
|
||||
String string3 = new BigInteger(MojangCrypt.digestData("", MinecraftServer.getKeyPair().getPublic(), getSecretKey())).toString(16);
|
||||
GameProfile gameProfile = MinecraftServer.getSessionService().hasJoinedServer(new GameProfile(null, connection.getLoginUsername()), string3);
|
||||
((NettyPlayerConnection) connection).setEncryptionKey(getSecretKey());
|
||||
final int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
public void run() {
|
||||
try {
|
||||
if (!Arrays.equals(connection.getNonce(), getNonce())) {
|
||||
System.out.println(connection.getLoginUsername() + " tried to login with an invalid nonce!");
|
||||
return;
|
||||
}
|
||||
if (!connection.getLoginUsername().isEmpty()) {
|
||||
final String string3 = new BigInteger(MojangCrypt.digestData("", MinecraftServer.getKeyPair().getPublic(), getSecretKey())).toString(16);
|
||||
final GameProfile gameProfile = MinecraftServer.getSessionService().hasJoinedServer(new GameProfile(null, connection.getLoginUsername()), string3);
|
||||
((NettyPlayerConnection) connection).setEncryptionKey(getSecretKey());
|
||||
final int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
}
|
||||
LoginSuccessPacket loginSuccessPacket = new LoginSuccessPacket(gameProfile.getId(), gameProfile.getName());
|
||||
connection.sendPacket(loginSuccessPacket);
|
||||
MinecraftServer.getLOGGER().info("UUID of player {} is {}", connection.getLoginUsername(), gameProfile.getId());
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(gameProfile.getId(), gameProfile.getName(), connection);
|
||||
}
|
||||
} catch (AuthenticationUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
}
|
||||
LoginSuccessPacket loginSuccessPacket = new LoginSuccessPacket(gameProfile.getId(), gameProfile.getName());
|
||||
connection.sendPacket(loginSuccessPacket);
|
||||
MinecraftServer.getLOGGER().info("UUID of player {} is {}", connection.getLoginUsername(), gameProfile.getId());
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
CONNECTION_MANAGER.createPlayer(gameProfile.getId(), gameProfile.getName(), connection);
|
||||
}
|
||||
} catch (AuthenticationUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BinaryReader reader) {
|
||||
sharedSecret = ByteArrayData.decodeByteArray(reader);
|
||||
verifyToken = ByteArrayData.decodeByteArray(reader);
|
||||
}
|
||||
@Override
|
||||
public void read(BinaryReader reader) {
|
||||
sharedSecret = ByteArrayData.decodeByteArray(reader);
|
||||
verifyToken = ByteArrayData.decodeByteArray(reader);
|
||||
}
|
||||
|
||||
public SecretKey getSecretKey() {
|
||||
return MojangCrypt.decryptByteToSecretKey(MinecraftServer.getKeyPair().getPrivate(), sharedSecret);
|
||||
}
|
||||
public SecretKey getSecretKey() {
|
||||
return MojangCrypt.decryptByteToSecretKey(MinecraftServer.getKeyPair().getPrivate(), sharedSecret);
|
||||
}
|
||||
|
||||
public byte[] getNonce() {
|
||||
return MinecraftServer.getKeyPair().getPrivate() == null ? this.verifyToken : MojangCrypt.decryptUsingKey(MinecraftServer.getKeyPair().getPrivate(), this.verifyToken);
|
||||
}
|
||||
public byte[] getNonce() {
|
||||
return MinecraftServer.getKeyPair().getPrivate() == null ? this.verifyToken : MojangCrypt.decryptUsingKey(MinecraftServer.getKeyPair().getPrivate(), this.verifyToken);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.extras.MojangAuth;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.EncryptionRequestPacket;
|
||||
@ -23,9 +22,9 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
public String username;
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
public void process(PlayerConnection connection) {
|
||||
if (MojangAuth.isUsingMojangAuth()) {
|
||||
if (connectionManager.getPlayer(username) != null) {
|
||||
if (CONNECTION_MANAGER.getPlayer(username) != null) {
|
||||
connection.sendPacket(new LoginDisconnect(ALREADY_CONNECTED_JSON));
|
||||
connection.disconnect();
|
||||
return;
|
||||
@ -36,9 +35,9 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
EncryptionRequestPacket encryptionRequestPacket = new EncryptionRequestPacket(connection);
|
||||
connection.sendPacket(encryptionRequestPacket);
|
||||
} else {
|
||||
UUID playerUuid = connectionManager.getPlayerConnectionUuid(connection, username);
|
||||
final UUID playerUuid = CONNECTION_MANAGER.getPlayerConnectionUuid(connection, username);
|
||||
|
||||
int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
final int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
@ -48,7 +47,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
connection.sendPacket(successPacket);
|
||||
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
CONNECTION_MANAGER.createPlayer(playerUuid, username, connection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.minestom.server.network.packet.client.status;
|
||||
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
@ -10,7 +9,7 @@ public class LegacyServerListPingPacket implements ClientPreplayPacket {
|
||||
private byte payload;
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
public void process(PlayerConnection connection) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.minestom.server.network.packet.client.status;
|
||||
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.status.PongPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
@ -11,7 +10,7 @@ public class PingPacket implements ClientPreplayPacket {
|
||||
private long number;
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
public void process(PlayerConnection connection) {
|
||||
PongPacket pongPacket = new PongPacket(number);
|
||||
connection.sendPacket(pongPacket);
|
||||
connection.disconnect();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.network.packet.client.status;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.handshake.ResponsePacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
@ -12,7 +11,7 @@ import net.minestom.server.utils.binary.BinaryReader;
|
||||
public class StatusRequestPacket implements ClientPreplayPacket {
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
public void process(PlayerConnection connection) {
|
||||
ResponseDataConsumer consumer = MinecraftServer.getResponseDataConsumer();
|
||||
ResponseData responseData = new ResponseData();
|
||||
|
||||
|
@ -4,8 +4,20 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
||||
|
||||
public interface ServerPacket {
|
||||
|
||||
/**
|
||||
* Write the packet to a {@link BinaryWriter}
|
||||
*
|
||||
* @param writer the writer to write the packet to
|
||||
*/
|
||||
void write(BinaryWriter writer);
|
||||
|
||||
/**
|
||||
* Get the id of this packet
|
||||
* <p>
|
||||
* Should be a constant
|
||||
*
|
||||
* @return the id of this packet
|
||||
*/
|
||||
int getId();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user