Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions protocol/src/main/java/org/feathercore/protocol/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,26 @@ public void writeByteArray(byte[] arr) {
}
}

public UUID readUUID() {
public UUID readUuid() {
return new UUID(readLong(), readLong());
}

public void writeUUID(UUID uuid) {
public void writeUuid(UUID uuid) {
writeLong(uuid.getMostSignificantBits());
writeLong(uuid.getLeastSignificantBits());
}

public UUID readUUIDNullable() {
public UUID readUuidNullable() {
if (readBoolean()) {
return readUUID();
return readUuid();
}
return null;
}

public void writeUUIDNullable(UUID uuid) {
public void writeUuidNullable(UUID uuid) {
if (uuid != null) {
writeBoolean(true);
writeUUID(uuid);
writeUuid(uuid);
} else {
writeBoolean(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,57 @@

package org.feathercore.protocol.minecraft.packet.handshake.client;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.feathercore.protocol.packet.ConnectionState;
import org.jetbrains.annotations.NotNull;

/**
* Created by k.shandurenko on 09/04/2019
* This causes the server to switch into the target state.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
public class HandshakePacketClientHandshake implements MinecraftPacket {

public static final int ID = 0x00;

private int protocolVersion;
private String ip;
private int port;
private ConnectionState requestedState;
/**
* Protocol version number
*/
int protocolVersion;

public HandshakePacketClientHandshake(int protocolVersion, String ip, int port, ConnectionState requestedState) {
this.protocolVersion = protocolVersion;
this.ip = ip;
this.port = port;
this.requestedState = requestedState;
}

public HandshakePacketClientHandshake() {
}
/**
* Hostname that was used to connect to the server
*/
String serverAddress;

public int getProtocolVersion() {
return protocolVersion;
}
/**
* Default is 25565. The Notchian server does not use this information
*/
int serverPort;

public String getIp() {
return ip;
}

public int getPort() {
return port;
}

public ConnectionState getRequestedState() {
return requestedState;
}

@Override
public void write(@NotNull final Buffer buffer) {
buffer.writeVarInt(this.protocolVersion);
buffer.writeString(this.ip);
buffer.writeShort((short) this.port);
buffer.writeVarInt(this.requestedState.getId());
}
/**
* Next connection state
*/
ConnectionState nextState;

@Override
public void read(@NotNull final Buffer buffer) {
this.protocolVersion = buffer.readVarInt();
this.ip = buffer.readString();
this.port = buffer.readShort();
this.requestedState = ConnectionState.getByID(buffer.readVarInt());
serverAddress = buffer.readString();
serverPort = buffer.readShort();
nextState = ConnectionState.getById(buffer.readVarInt());
}

@Override
public int getId() {
return ID;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 Feather Core
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.feathercore.protocol.minecraft.packet.handshake.client;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

/**
* This packet uses a nonstandard format. It is never length-prefixed,
* and the packet ID is an Unsigned Byte instead of a VarInt.
*
* While not technically part of the current protocol, legacy clients may
* send this packet to initiate Server List Ping, and modern servers
* should handle it correctly.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
public class HandshakePacketClientLegacyServerListPing implements MinecraftPacket {

public static final int ID = 0xFE;

/**
* Always 1 ({@link 0x01})
*/
int payload;

@Override
public void read(@NotNull final Buffer buffer) {
payload = buffer.readUnsignedByte();
}

@Override
public int getId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class LoginPacketClientEncryptionResponse implements MinecraftPacket {

@Override
public void write(@NotNull final Buffer buffer) {
buffer.writeByteArray(this.secretKeyEncrypted);
buffer.writeByteArray(this.verifyTokenEncrypted);
buffer.writeByteArray(secretKeyEncrypted);
buffer.writeByteArray(verifyTokenEncrypted);
}

@Override
public void read(@NotNull final Buffer buffer) {
this.secretKeyEncrypted = buffer.readByteArray();
this.verifyTokenEncrypted = buffer.readByteArray();
secretKeyEncrypted = buffer.readByteArray();
verifyTokenEncrypted = buffer.readByteArray();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2019 Feather Core
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.feathercore.protocol.minecraft.packet.login.client;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

// FIXME: FIXME !!
// This class has optional fields. You need to write valid reader and writer.
// https://wiki.vg/Protocol#Login_Plugin_Response

@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
public class LoginPacketClientLoginPluginResponse implements MinecraftPacket {

public static final int ID = 0x02;

/**
* Should match ID from server
*/
int messageId;

/**
* {@link true} if the client understands the request, {@link false} otherwise (no payload follows)
*/
boolean successful;

/**
* Any data, depending on the channel
*
* @apiNote The length of this array must be inferred from the packet length
*/
@Nullable byte[] data;

@Override
public void read(@NotNull final Buffer buffer) {
messageId = buffer.readVarInt();
successful = buffer.readBoolean();
// Array size for data not found
// FIXME: 18.04.2019 because `The length of this array must be inferred from the packet length.`
buffer.readBytes(data);
}

@Override
public int getId() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

/**
* Created by k.shandurenko on 09/04/2019
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -37,21 +34,18 @@ public class LoginPacketClientLoginStart implements MinecraftPacket {

public static final int ID = 0x00;

/**
* Player's Username
*/
GameProfile profile;

@Override
public void write(@NotNull final Buffer buffer) {
buffer.writeString(this.profile.getName());
}

@Override
public void read(@NotNull final Buffer buffer) {
this.profile = new GameProfile(null, buffer.readString(16));
profile = new GameProfile(null, buffer.readString(16));
}

@Override
public int getId() {
return ID;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

/**
* Created by k.shandurenko on 09/04/2019
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -37,27 +34,15 @@ public class LoginPacketServerDisconnect implements MinecraftPacket {

public static final int ID = 0x00;

BaseComponent reason;
BaseComponent[] reason;

@Override
public void write(@NotNull final Buffer buffer) {
if (true) {
throw new UnsupportedOperationException("Should be recreated using Mojang API");
}
// TODO buffer.writeChatComponent(this.reason);
}

@Override
public void read(@NotNull final Buffer buffer) {
if (true) {
throw new UnsupportedOperationException("Should be recreated using Mojang API");
}
// TODO this.reason = buffer.readChatComponent();
buffer.writeBaseComponents(reason);
}

@Override
public int getId() {
return ID;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.feathercore.protocol.encrypt.CryptManager;
import org.jetbrains.annotations.NotNull;

import java.security.PublicKey;

/**
* Created by k.shandurenko on 09/04/2019
*/
// TODO: 18.04.2019 Docs
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -45,16 +42,9 @@ public class LoginPacketServerEncryptionRequest implements MinecraftPacket {

@Override
public void write(@NotNull final Buffer buffer) {
buffer.writeString(this.hashedServerID);
buffer.writeByteArray(this.publicKey.getEncoded());
buffer.writeByteArray(this.verifyToken);
}

@Override
public void read(@NotNull final Buffer buffer) {
this.hashedServerID = buffer.readString(20);
this.publicKey = CryptManager.decodePublicKey(buffer.readByteArray());
this.verifyToken = buffer.readByteArray();
buffer.writeString(hashedServerID);
buffer.writeByteArray(publicKey.getEncoded());
buffer.writeByteArray(verifyToken);
}

@Override
Expand Down
Loading