Skip to content

Commit

Permalink
Revert "Optimize imports and delete command declaration packet"
Browse files Browse the repository at this point in the history
This reverts commit 6d2ff1a.
  • Loading branch information
MiGoYAm committed Dec 11, 2021
1 parent b882633 commit 63ebb4e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/main/java/ru/nanit/limbo/configuration/LimboConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import ru.nanit.limbo.server.data.*;
import ru.nanit.limbo.util.Colors;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.SocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.timeout.ReadTimeoutHandler;
import ru.nanit.limbo.connection.pipeline.VarIntFrameDecoder;
import ru.nanit.limbo.connection.pipeline.PacketDecoder;
import ru.nanit.limbo.connection.pipeline.PacketEncoder;
import ru.nanit.limbo.connection.pipeline.VarIntFrameDecoder;
import ru.nanit.limbo.connection.pipeline.VarIntLengthEncoder;
import ru.nanit.limbo.server.LimboServer;

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/ru/nanit/limbo/connection/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import ru.nanit.limbo.LimboConstants;
import ru.nanit.limbo.connection.pipeline.PacketDecoder;
import ru.nanit.limbo.connection.pipeline.PacketEncoder;
import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PreEncodedPacket;
import ru.nanit.limbo.protocol.packets.PacketHandshake;
import ru.nanit.limbo.protocol.packets.login.*;
import ru.nanit.limbo.protocol.packets.play.*;
import ru.nanit.limbo.connection.pipeline.PacketDecoder;
import ru.nanit.limbo.connection.pipeline.PacketEncoder;
import ru.nanit.limbo.protocol.packets.PacketHandshake;
import ru.nanit.limbo.protocol.packets.status.PacketStatusPing;
import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
Expand All @@ -33,6 +33,7 @@
import java.net.SocketAddress;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -399,11 +400,15 @@ public static void initPackets(LimboServer server) {
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);

PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.singletonList("limbo"));

PACKET_LOGIN_SUCCESS = PreEncodedPacket.of(loginSuccess);
PACKET_JOIN_GAME = PreEncodedPacket.of(joinGame);
PACKET_PLAYER_ABILITIES = PreEncodedPacket.of(playerAbilities);
PACKET_PLAYER_POS = PreEncodedPacket.of(positionAndLook);
PACKET_PLAYER_INFO = PreEncodedPacket.of(info);
PACKET_DECLARE_COMMANDS = PreEncodedPacket.of(declareCommands);

if (server.getConfig().isUseBrandName()){
PacketPluginMessage pluginMessage = new PacketPluginMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.Packet;
import ru.nanit.limbo.protocol.*;
import ru.nanit.limbo.protocol.registry.State;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.util.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.nanit.limbo.protocol.packets.play;

import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketOut;
import ru.nanit.limbo.protocol.registry.Version;

import java.util.List;

/**
* Packet for 1.13+
*/
public class PacketDeclareCommands implements PacketOut {

private List<String> commands;

public void setCommands(List<String> commands) {
this.commands = commands;
}

@Override
public void encode(ByteMessage msg, Version version) {
msg.writeVarInt(commands.size() * 2 + 1); // +1 because declaring root node

// Declare root node

msg.writeByte(0);
msg.writeVarInt(commands.size());

for (int i = 1; i <= commands.size() * 2; i++) {
msg.writeVarInt(i++);
}

// Declare other commands

int i = 1;
for (String cmd : commands) {
msg.writeByte(1 | 0x04);
msg.writeVarInt(1);
msg.writeVarInt(i + 1);
msg.writeString(cmd);
i++;

msg.writeByte(2 | 0x04 | 0x10);
msg.writeVarInt(1);
msg.writeVarInt(i);
msg.writeString("arg");
msg.writeString("brigadier:string");
msg.writeVarInt(0);
msg.writeString("minecraft:ask_server");
i++;
}

msg.writeVarInt(0);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.nanit.limbo.protocol.packets.status;

import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketIn;
import ru.nanit.limbo.protocol.*;
import ru.nanit.limbo.protocol.registry.Version;

public class PacketStatusRequest implements PacketIn {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.nanit.limbo.protocol.packets.status;

import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketOut;
import ru.nanit.limbo.protocol.*;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.server.LimboServer;

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/ru/nanit/limbo/protocol/registry/State.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package ru.nanit.limbo.protocol.registry;

import ru.nanit.limbo.protocol.Packet;
import ru.nanit.limbo.protocol.packets.PacketHandshake;
import ru.nanit.limbo.protocol.packets.*;
import ru.nanit.limbo.protocol.packets.login.*;
import ru.nanit.limbo.protocol.packets.play.*;
import ru.nanit.limbo.protocol.packets.status.PacketStatusPing;
import ru.nanit.limbo.protocol.packets.status.PacketStatusRequest;
import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;

import static ru.nanit.limbo.protocol.registry.Version.*;

import java.util.*;
import java.util.function.Supplier;

import static ru.nanit.limbo.protocol.registry.Version.*;

public enum State {

HANDSHAKING(0) {
Expand Down Expand Up @@ -70,6 +70,13 @@ public enum State {
map(0x0F, V1_17, V1_18)
);

clientBound.register(PacketDeclareCommands::new,
map(0x11, V1_13, V1_14_4),
map(0x12, V1_15, V1_15_2),
map(0x11, V1_16, V1_16_1),
map(0x10, V1_16_2, V1_16_4),
map(0x12, V1_17, V1_18)
);
clientBound.register(PacketJoinGame::new,
map(0x01, V1_8, V1_8),
map(0x23, V1_9, V1_12_2),
Expand Down

0 comments on commit 63ebb4e

Please sign in to comment.