mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-31 04:21:27 +01:00
Cleanup
This commit is contained in:
parent
c6c8f6b9d6
commit
68bb479f4a
@ -70,7 +70,7 @@ import java.util.Collection;
|
|||||||
* The server needs to be initialized with {@link #init()} and started with {@link #start(String, int)}.
|
* The server needs to be initialized with {@link #init()} and started with {@link #start(String, int)}.
|
||||||
* You should register all of your dimensions, biomes, commands, events, etc... in-between.
|
* You should register all of your dimensions, biomes, commands, events, etc... in-between.
|
||||||
*/
|
*/
|
||||||
public class MinecraftServer {
|
public final class MinecraftServer {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(MinecraftServer.class);
|
private final static Logger LOGGER = LoggerFactory.getLogger(MinecraftServer.class);
|
||||||
@ -289,7 +289,7 @@ public class MinecraftServer {
|
|||||||
// The difficulty packet
|
// The difficulty packet
|
||||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||||
serverDifficultyPacket.difficulty = difficulty;
|
serverDifficultyPacket.difficulty = difficulty;
|
||||||
serverDifficultyPacket.locked = true; // Can only be modified on singleplayer
|
serverDifficultyPacket.locked = true; // Can only be modified on single-player
|
||||||
// Send the packet to all online players
|
// Send the packet to all online players
|
||||||
PacketWriterUtils.writeAndSend(connectionManager.getOnlinePlayers(), serverDifficultyPacket);
|
PacketWriterUtils.writeAndSend(connectionManager.getOnlinePlayers(), serverDifficultyPacket);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package net.minestom.server.extras;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
|
||||||
public class MojangAuth {
|
public final class MojangAuth {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean usingMojangAuth = false;
|
private static boolean usingMojangAuth = false;
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.instance.block.rule.vanilla.AxisPlacementRule;
|
|||||||
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
|
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
|
||||||
import net.minestom.server.instance.block.rule.vanilla.WallPlacementRule;
|
import net.minestom.server.instance.block.rule.vanilla.WallPlacementRule;
|
||||||
|
|
||||||
public class PlacementRules {
|
public final class PlacementRules {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||||
|
@ -10,7 +10,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
|
|
||||||
public class MojangCrypt {
|
public final class MojangCrypt {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -14,31 +14,28 @@ import net.minestom.server.network.packet.client.handshake.HandshakePacket;
|
|||||||
import net.minestom.server.network.player.NettyPlayerConnection;
|
import net.minestom.server.network.player.NettyPlayerConnection;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PacketProcessor {
|
public final class PacketProcessor {
|
||||||
|
|
||||||
private final Map<ChannelHandlerContext, PlayerConnection> connectionPlayerConnectionMap = new ConcurrentHashMap<>();
|
private final Map<ChannelHandlerContext, PlayerConnection> connectionPlayerConnectionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// Protocols
|
// Protocols state
|
||||||
private final ClientStatusPacketsHandler statusPacketsHandler;
|
private final ClientStatusPacketsHandler statusPacketsHandler;
|
||||||
private final ClientLoginPacketsHandler loginPacketsHandler;
|
private final ClientLoginPacketsHandler loginPacketsHandler;
|
||||||
private final ClientPlayPacketsHandler playPacketsHandler;
|
private final ClientPlayPacketsHandler playPacketsHandler;
|
||||||
|
|
||||||
public PacketProcessor() {
|
public PacketProcessor() {
|
||||||
|
|
||||||
this.statusPacketsHandler = new ClientStatusPacketsHandler();
|
this.statusPacketsHandler = new ClientStatusPacketsHandler();
|
||||||
this.loginPacketsHandler = new ClientLoginPacketsHandler();
|
this.loginPacketsHandler = new ClientLoginPacketsHandler();
|
||||||
this.playPacketsHandler = new ClientPlayPacketsHandler();
|
this.playPacketsHandler = new ClientPlayPacketsHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> printBlackList = Arrays.asList(17, 18, 19);
|
|
||||||
|
|
||||||
public void process(ChannelHandlerContext channel, InboundPacket packet) {
|
public void process(ChannelHandlerContext channel, InboundPacket packet) {
|
||||||
|
// Create the netty player connection object if not existing
|
||||||
PlayerConnection playerConnection = connectionPlayerConnectionMap.computeIfAbsent(
|
PlayerConnection playerConnection = connectionPlayerConnectionMap.computeIfAbsent(
|
||||||
channel, c -> new NettyPlayerConnection((SocketChannel) channel.channel())
|
channel, c -> new NettyPlayerConnection((SocketChannel) channel.channel())
|
||||||
);
|
);
|
||||||
@ -48,10 +45,6 @@ public class PacketProcessor {
|
|||||||
|
|
||||||
final ConnectionState connectionState = playerConnection.getConnectionState();
|
final ConnectionState connectionState = playerConnection.getConnectionState();
|
||||||
|
|
||||||
//if (!printBlackList.contains(id)) {
|
|
||||||
//System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
|
|
||||||
//}
|
|
||||||
|
|
||||||
BinaryReader binaryReader = new BinaryReader(packet.body);
|
BinaryReader binaryReader = new BinaryReader(packet.body);
|
||||||
|
|
||||||
if (connectionState == ConnectionState.UNKNOWN) {
|
if (connectionState == ConnectionState.UNKNOWN) {
|
||||||
@ -84,6 +77,13 @@ public class PacketProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a player connection from its channel.
|
||||||
|
*
|
||||||
|
* @param channel the connection channel
|
||||||
|
* @return the connection of this channel, null if not found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
public PlayerConnection getPlayerConnection(ChannelHandlerContext channel) {
|
public PlayerConnection getPlayerConnection(ChannelHandlerContext channel) {
|
||||||
return connectionPlayerConnectionMap.get(channel);
|
return connectionPlayerConnectionMap.get(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.minestom.server.network.packet.client;
|
package net.minestom.server.network.packet.client;
|
||||||
|
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.Readable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public interface ClientPacket {
|
/**
|
||||||
|
* Represents a packet received from a client.
|
||||||
void read(@NotNull BinaryReader reader);
|
*/
|
||||||
|
public interface ClientPacket extends Readable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.network.packet.client.handler;
|
package net.minestom.server.network.packet.client.handler;
|
||||||
|
|
||||||
import net.minestom.server.network.packet.client.ClientPacket;
|
import net.minestom.server.network.packet.client.ClientPacket;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@ -9,17 +10,30 @@ public class ClientPacketsHandler {
|
|||||||
// Max packet id
|
// Max packet id
|
||||||
private static final int SIZE = 0x30;
|
private static final int SIZE = 0x30;
|
||||||
|
|
||||||
private final Supplier<ClientPacket>[] supplierAccesses = new Supplier[SIZE];
|
private final ClientPacketSupplier[] supplierAccesses = new ClientPacketSupplier[SIZE];
|
||||||
|
|
||||||
public void register(int id, Supplier<ClientPacket> packetSupplier) {
|
/**
|
||||||
supplierAccesses[id] = packetSupplier;
|
* Registers a client packet which can be retrieved later using {@link #getPacketInstance(int)}.
|
||||||
|
*
|
||||||
|
* @param id the packet id
|
||||||
|
* @param packetSupplier the supplier of the packet
|
||||||
|
*/
|
||||||
|
public void register(int id, @NotNull ClientPacketSupplier packetSupplier) {
|
||||||
|
this.supplierAccesses[id] = packetSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link net.minestom.server.network.packet.client.ClientPlayPacket} from its id.
|
||||||
|
*
|
||||||
|
* @param id the packet id
|
||||||
|
* @return the associated client packet
|
||||||
|
* @throws IllegalStateException if {@code id} is not a valid packet id, or unregistered
|
||||||
|
*/
|
||||||
public ClientPacket getPacketInstance(int id) {
|
public ClientPacket getPacketInstance(int id) {
|
||||||
if (id > SIZE)
|
if (id > SIZE)
|
||||||
throw new IllegalStateException("Packet ID 0x" + Integer.toHexString(id) + " has been tried to be parsed, debug needed");
|
throw new IllegalStateException("Packet ID 0x" + Integer.toHexString(id) + " has been tried to be parsed, debug needed");
|
||||||
|
|
||||||
Supplier<ClientPacket> supplier = supplierAccesses[id];
|
ClientPacketSupplier supplier = supplierAccesses[id];
|
||||||
if (supplierAccesses[id] == null)
|
if (supplierAccesses[id] == null)
|
||||||
throw new IllegalStateException("Packet id 0x" + Integer.toHexString(id) + " isn't registered!");
|
throw new IllegalStateException("Packet id 0x" + Integer.toHexString(id) + " isn't registered!");
|
||||||
|
|
||||||
@ -28,4 +42,10 @@ public class ClientPacketsHandler {
|
|||||||
return supplier.get();
|
return supplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenient interface to supply a {@link ClientPacket}.
|
||||||
|
*/
|
||||||
|
protected interface ClientPacketSupplier extends Supplier<ClientPacket> {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
|||||||
final int messageId = ThreadLocalRandom.current().nextInt();
|
final int messageId = ThreadLocalRandom.current().nextInt();
|
||||||
final String channel = VelocityProxy.PLAYER_INFO_CHANNEL;
|
final String channel = VelocityProxy.PLAYER_INFO_CHANNEL;
|
||||||
|
|
||||||
// Important to retrieve the channel in the response packet
|
// Important in order to retrieve the channel in the response packet
|
||||||
nettyPlayerConnection.addPluginRequestEntry(messageId, channel);
|
nettyPlayerConnection.addPluginRequestEntry(messageId, channel);
|
||||||
|
|
||||||
LoginPluginRequestPacket loginPluginRequestPacket = new LoginPluginRequestPacket();
|
LoginPluginRequestPacket loginPluginRequestPacket = new LoginPluginRequestPacket();
|
||||||
|
@ -43,7 +43,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
private String serverAddress;
|
private String serverAddress;
|
||||||
private int serverPort;
|
private int serverPort;
|
||||||
|
|
||||||
// Used for the login plugin request packet, to retrive the channel from a message id,
|
// Used for the login plugin request packet, to retrieve the channel from a message id,
|
||||||
// cleared once the player enters the play state
|
// cleared once the player enters the play state
|
||||||
private Map<Integer, String> pluginRequestMap = new ConcurrentHashMap<>();
|
private Map<Integer, String> pluginRequestMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user