1.20.2-pre1

This commit is contained in:
LexManos committed 2023-09-08 10:56:10 -07:00
1 parent 12d24df4f6
commit 3edefbe33e
368 files changed
+3555 -6356

No files matched your search

@@ -7,30 +7,28 @@ package net.minecraftforge.network;
import java.util.function.Function;
public enum ConnectionType
{
MODDED(s->Integer.valueOf(s.substring(NetworkConstants.FMLNETMARKER.length()))), VANILLA(s->0);
import org.jetbrains.annotations.ApiStatus;
@SuppressWarnings("unused")
public enum ConnectionType {
MODDED(s -> Integer.valueOf(s.substring(NetworkConstants.FMLNETMARKER.length()))),
VANILLA(s ->0);
private final Function<String, Integer> versionExtractor;
ConnectionType(Function<String, Integer> versionExtractor)
{
ConnectionType(Function<String, Integer> versionExtractor) {
this.versionExtractor = versionExtractor;
}
public static ConnectionType forVersionFlag(String vers)
{
public static ConnectionType forVersionFlag(String vers) {
return vers.startsWith(NetworkConstants.FMLNETMARKER) ? MODDED : VANILLA;
}
public int getFMLVersionNumber(final String fmlVersion)
{
public int getFMLVersionNumber(final String fmlVersion) {
return versionExtractor.apply(fmlVersion);
}
public boolean isVanilla()
{
public boolean isVanilla() {
return this == VANILLA;
}
}
@@ -13,7 +13,6 @@ import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
@@ -341,7 +340,7 @@ public class HandshakeHandler
public boolean tickServer()
{
if (!negotiationStarted) {
GameProfile profile = ((ServerLoginPacketListenerImpl) manager.getPacketListener()).gameProfile;
GameProfile profile = ((ServerLoginPacketListenerImpl) manager.getPacketListener()).getAuthenticatedProfile();
PlayerNegotiationEvent event = new PlayerNegotiationEvent(manager, profile, pendingFutures);
MinecraftForge.EVENT_BUS.post(event);
negotiationStarted = true;
@@ -7,11 +7,14 @@ package net.minecraftforge.network;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceArrayMap;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket;
import net.minecraft.network.protocol.login.custom.DiscardedQueryAnswerPayload;
import net.minecraft.network.protocol.login.custom.DiscardedQueryPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.LogicalSide;
import org.apache.commons.lang3.tuple.Pair;
@@ -22,12 +25,11 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public enum NetworkDirection
{
PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT, ServerboundCustomPayloadPacket.class, 1, (d, i, n) -> new ServerboundCustomPayloadPacket(n, d)),
PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER, ClientboundCustomPayloadPacket.class, 0, (d, i, n) -> new ClientboundCustomPayloadPacket(n, d)),
LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadLoginEvent::new, LogicalSide.CLIENT, ServerboundCustomQueryPacket.class, 3, (d, i, n) -> new ServerboundCustomQueryPacket(i, d)),
LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadLoginEvent::new, LogicalSide.SERVER, ClientboundCustomQueryPacket.class, 2, (d, i, n) -> new ClientboundCustomQueryPacket(i, n, d));
public enum NetworkDirection {
PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT, ServerboundCustomPayloadPacket.class, 1, NetworkDirection::playServerbound),
PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER, ClientboundCustomPayloadPacket.class, 0, NetworkDirection::playClientbound),
LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadLoginEvent::new, LogicalSide.CLIENT, ServerboundCustomQueryAnswerPacket.class, 3, NetworkDirection::loginServerbound),
LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadLoginEvent::new, LogicalSide.SERVER, ClientboundCustomQueryPacket.class, 2, NetworkDirection::loginClientbound);
private final BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier;
private final LogicalSide logicalSide;
@@ -42,8 +44,7 @@ public enum NetworkDirection
collect(Collectors.toMap(NetworkDirection::getPacketClass, Function.identity(), (m1,m2)->m1, Reference2ReferenceArrayMap::new));
}
private NetworkDirection(BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier, LogicalSide logicalSide, Class<? extends Packet> clazz, int i, Factory factory)
{
private NetworkDirection(BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier, LogicalSide logicalSide, Class<? extends Packet> clazz, int i, Factory factory) {
this.eventSupplier = eventSupplier;
this.logicalSide = logicalSide;
this.packetClass = clazz;
@@ -54,32 +55,47 @@ public enum NetworkDirection
private Class<? extends Packet> getPacketClass() {
return packetClass;
}
public static <T extends ICustomPacket<?>> NetworkDirection directionFor(Class<T> customPacket)
{
public static <T extends ICustomPacket<?>> NetworkDirection directionFor(Class<T> customPacket) {
return packetLookup.get(customPacket);
}
public NetworkDirection reply() {
return NetworkDirection.values()[this.otherWay];
}
public NetworkEvent getEvent(final ICustomPacket<?> buffer, final Supplier<NetworkEvent.Context> manager) {
return this.eventSupplier.apply(buffer, manager);
}
public LogicalSide getOriginationSide()
{
public LogicalSide getOriginationSide() {
return logicalSide;
}
public LogicalSide getReceptionSide() { return reply().logicalSide; };
@SuppressWarnings("unchecked")
public <T extends Packet<?>> ICustomPacket<T> buildPacket(Pair<FriendlyByteBuf,Integer> packetData, ResourceLocation channelName)
{
public <T extends Packet<?>> ICustomPacket<T> buildPacket(Pair<FriendlyByteBuf,Integer> packetData, ResourceLocation channelName) {
return this.factory.create(packetData.getLeft(), packetData.getRight(), channelName);
}
private interface Factory<T extends Packet<?>> {
ICustomPacket<T> create(FriendlyByteBuf data, Integer index, ResourceLocation channelName);
}
private static ServerboundCustomPayloadPacket playServerbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(channelName, data));
}
private static ClientboundCustomPayloadPacket playClientbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(channelName, data));
}
private static ServerboundCustomQueryAnswerPacket loginServerbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
return new ServerboundCustomQueryAnswerPacket(index, new DiscardedQueryAnswerPayload(data));
}
private static ClientboundCustomQueryPacket loginClientbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
return new ClientboundCustomQueryPacket(index, new DiscardedQueryPayload(channelName, data));
}
}
@@ -41,35 +41,41 @@ import net.minecraft.core.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.fml.config.ConfigTracker;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
public class NetworkHooks
{
@ApiStatus.Internal
public class NetworkHooks {
private static final Logger LOGGER = LogManager.getLogger();
public static String getFMLVersion(final String ip)
{
return ip.contains("\0") ? Objects.equals(ip.split("\0")[1], NetworkConstants.NETVERSION) ? NetworkConstants.NETVERSION : ip.split("\0")[1] : NetworkConstants.NOVERSION;
public static String getFMLVersion(final String ip) {
int idx = ip.indexOf('\0');
if (idx == -1)
return NetworkConstants.NOVERSION;
for (var pt : ip.split("\0")) {
if (pt.startsWith("FML"))
return pt;
}
return NetworkConstants.NOVERSION;
}
public static ConnectionType getConnectionType(final Supplier<Connection> connection)
{
public static ConnectionType getConnectionType(final Supplier<Connection> connection) {
return getConnectionType(connection.get().channel());
}
public static ConnectionType getConnectionType(ChannelHandlerContext context)
{
public static ConnectionType getConnectionType(ChannelHandlerContext context) {
return getConnectionType(context.channel());
}
private static ConnectionType getConnectionType(Channel channel)
{
private static ConnectionType getConnectionType(Channel channel) {
return ConnectionType.forVersionFlag(channel.attr(NetworkConstants.FML_NETVERSION).get());
}
@SuppressWarnings("unchecked")
public static Packet<ClientGamePacketListener> getEntitySpawningPacket(Entity entity)
{
public static Packet<ClientGamePacketListener> getEntitySpawningPacket(Entity entity) {
// ClientboundCustomPayloadPacket is an instance of Packet<ClientGamePacketListener>
return (Packet<ClientGamePacketListener>) NetworkConstants.playChannel.toVanillaPacket(new PlayMessages.SpawnEntity(entity), NetworkDirection.PLAY_TO_CLIENT);
}
@@ -94,14 +100,13 @@ public class NetworkHooks
throw new IllegalStateException("Invalid packet received, aborting connection");
}
}
public static void registerServerLoginChannel(Connection manager, ClientIntentionPacket packet)
{
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(packet.getFMLVersion());
public static void registerServerLoginChannel(Connection manager, ClientIntentionPacket packet) {
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(NetworkHooks.getFMLVersion(packet.hostName()));
HandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_CLIENT);
}
public synchronized static void registerClientLoginChannel(Connection manager)
{
public synchronized static void registerClientLoginChannel(Connection manager) {
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(NetworkConstants.NOVERSION);
HandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_SERVER);
}
@@ -115,17 +120,7 @@ public class NetworkHooks
MCRegisterPacketHandler.INSTANCE.sendRegistry(manager, NetworkDirection.valueOf(direction));
}
//TODO Dimensions..
/* public synchronized static void sendDimensionDataPacket(NetworkManager manager, ServerPlayerEntity player) {
// don't send vanilla dims
if (player.dimension.isVanilla()) return;
// don't sent to local - we already have a valid dim registry locally
if (manager.isLocalChannel()) return;
FMLNetworkConstants.playChannel.sendTo(new FMLPlayMessages.DimensionInfoMessage(player.dimension), manager, NetworkDirection.PLAY_TO_CLIENT);
}*/
public static boolean isVanillaConnection(Connection manager)
{
public static boolean isVanillaConnection(Connection manager) {
if (manager == null || manager.channel() == null) throw new NullPointerException("ARGH! Network Manager is null (" + manager != null ? "CHANNEL" : "MANAGER"+")" );
return getConnectionType(() -> manager) == ConnectionType.VANILLA;
}
@@ -139,9 +134,8 @@ public class NetworkHooks
}
}
public static boolean tickNegotiation(ServerLoginPacketListenerImpl netHandlerLoginServer, Connection networkManager, ServerPlayer player)
{
return HandshakeHandler.tickLogin(networkManager);
public static boolean tickNegotiation(Connection manager) {
return HandshakeHandler.tickLogin(manager);
}
/**
@@ -153,8 +147,7 @@ public class NetworkHooks
* @param player The player to open the GUI for
* @param containerSupplier A supplier of container properties including the registry name of the container
*/
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier)
{
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier) {
openScreen(player, containerSupplier, buf -> {});
}
@@ -168,10 +161,10 @@ public class NetworkHooks
* @param containerSupplier A supplier of container properties including the registry name of the container
* @param pos A block pos, which will be encoded into the auxillary data for this request
*/
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, BlockPos pos)
{
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, BlockPos pos) {
openScreen(player, containerSupplier, buf -> buf.writeBlockPos(pos));
}
/**
* Request to open a GUI on the client, from the server
*
@@ -184,8 +177,7 @@ public class NetworkHooks
* @param containerSupplier A supplier of container properties including the registry name of the container
* @param extraDataWriter Consumer to write any additional data the GUI needs
*/
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, Consumer<FriendlyByteBuf> extraDataWriter)
{
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, Consumer<FriendlyByteBuf> extraDataWriter) {
if (player.level().isClientSide) return;
player.doCloseContainer();
player.nextContainerCounter();
@@ -206,7 +198,7 @@ public class NetworkHooks
return;
MenuType<?> type = c.getType();
PlayMessages.OpenContainer msg = new PlayMessages.OpenContainer(type, openContainerId, containerSupplier.getDisplayName(), output);
NetworkConstants.playChannel.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
NetworkConstants.playChannel.sendTo(msg, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
player.containerMenu = c;
player.initMenu(player.containerMenu);
@@ -217,8 +209,7 @@ public class NetworkHooks
* Updates the current ConnectionData instance with new mod or channel data if the old instance did not have either of these yet,
* or creates a new ConnectionData instance with the new data if the current ConnectionData instance doesn't exist yet.
*/
static void appendConnectionData(Connection mgr, Map<String, Pair<String, String>> modData, Map<ResourceLocation, String> channels)
{
static void appendConnectionData(Connection mgr, Map<String, Pair<String, String>> modData, Map<ResourceLocation, String> channels) {
ConnectionData oldData = mgr.channel().attr(NetworkConstants.FML_CONNECTION_DATA).get();
oldData = oldData != null ? new ConnectionData(oldData.getModData().isEmpty() ? modData : oldData.getModData(), oldData.getChannels().isEmpty() ? channels : oldData.getChannels()) : new ConnectionData(modData, channels);
@@ -226,20 +217,17 @@ public class NetworkHooks
}
@Nullable
public static ConnectionData getConnectionData(Connection mgr)
{
public static ConnectionData getConnectionData(Connection mgr) {
return mgr.channel().attr(NetworkConstants.FML_CONNECTION_DATA).get();
}
@Nullable
public static ModMismatchData getModMismatchData(Connection mgr)
{
public static ModMismatchData getModMismatchData(Connection mgr) {
return mgr.channel().attr(NetworkConstants.FML_MOD_MISMATCH_DATA).get();
}
@Nullable
public static MCRegisterPacketHandler.ChannelList getChannelList(Connection mgr)
{
public static MCRegisterPacketHandler.ChannelList getChannelList(Connection mgr) {
return mgr.channel().attr(NetworkConstants.FML_MC_REGISTRY).get();
}
}
@@ -200,7 +200,7 @@ public class PacketDistributor<T> {
}
private Consumer<Packet<?>> playerConsumer(final Supplier<ServerPlayer> entityPlayerMPSupplier) {
return p -> entityPlayerMPSupplier.get().connection.connection.send(p);
return p -> entityPlayerMPSupplier.get().connection.getConnection().send(p);
}
private Consumer<Packet<?>> playerListDimConsumer(final Supplier<ResourceKey<Level>> dimensionTypeSupplier) {
return p->getServer().getPlayerList().broadcastAll(p, dimensionTypeSupplier.get());
@@ -5,6 +5,7 @@
package net.minecraftforge.network.filters;
/*
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
@@ -24,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Network filter for forge-forge connections.
*/
* /
@ChannelHandler.Sharable
public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
{
@@ -65,3 +66,4 @@ public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
}
}
*/
@@ -22,8 +22,8 @@ public class NetworkFilters
private static final Logger LOGGER = LogManager.getLogger();
private static final Map<String, Function<Connection, VanillaPacketFilter>> instances = ImmutableMap.of(
"forge:vanilla_filter", manager -> new VanillaConnectionNetworkFilter(),
"forge:forge_fixes", ForgeConnectionNetworkFilter::new
"forge:vanilla_filter", manager -> new VanillaConnectionNetworkFilter()/*,
"forge:forge_fixes", ForgeConnectionNetworkFilter::new*/
);
public static void injectIfNecessary(Connection manager)
@@ -7,18 +7,13 @@ package net.minecraftforge.network.filters;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import io.netty.channel.ChannelHandler;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.gametest.framework.TestClassNameArgument;
@@ -27,18 +22,11 @@ import net.minecraft.network.protocol.Packet;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tags.TagNetworkSerialization;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryManager;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@@ -61,7 +49,8 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
ImmutableMap.<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>>builder()
.put(handler(ClientboundUpdateAttributesPacket.class, VanillaConnectionNetworkFilter::filterEntityProperties))
.put(handler(ClientboundCommandsPacket.class, VanillaConnectionNetworkFilter::filterCommandList))
.put(handler(ClientboundUpdateTagsPacket.class, VanillaConnectionNetworkFilter::filterCustomTagTypes))
// TODO Filter tags
//.put(handler(ClientboundUpdateTagsPacket.class, VanillaConnectionNetworkFilter::filterCustomTagTypes))
.build()
);
}
@@ -113,12 +102,14 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
* Filters out custom tag types that the vanilla client won't recognize.
* It prevents a rare error from logging and reduces the packet size
*/
/*
private static ClientboundUpdateTagsPacket filterCustomTagTypes(ClientboundUpdateTagsPacket packet) {
Map<ResourceKey<? extends Registry<?>>, TagNetworkSerialization.NetworkPayload> tags = packet.getTags()
.entrySet().stream().filter(e -> isVanillaRegistry(e.getKey().location()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return new ClientboundUpdateTagsPacket(tags);
}
*/
private static boolean isVanillaRegistry(ResourceLocation location)
{
@@ -4,7 +4,7 @@
*/
package net.minecraftforge.network.filters;
/*
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
@@ -14,7 +14,6 @@ import io.netty.buffer.Unpooled;
import net.minecraft.network.*;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.*;
import net.minecraftforge.network.event.EventNetworkChannel;
@@ -25,9 +24,8 @@ import org.apache.logging.log4j.Logger;
/**
* A custom payload channel that allows sending vanilla server-to-client packets, even if they would normally
* be too large for the vanilla protocol. This is achieved by splitting them into multiple custom payload packets.
*/
public class VanillaPacketSplitter
{
* /
public class VanillaPacketSplitter {
private static final Logger LOGGER = LogManager.getLogger();
@@ -43,8 +41,7 @@ public class VanillaPacketSplitter
private static final byte STATE_FIRST = 1;
private static final byte STATE_LAST = 2;
public static void register()
{
public static void register() {
Predicate<String> versionCheck = NetworkRegistry.acceptMissingOr(VERSION);
EventNetworkChannel channel = NetworkRegistry.newEventChannel(CHANNEL, () -> VERSION, versionCheck, versionCheck);
channel.addListener(VanillaPacketSplitter::onClientPacket);
@@ -53,43 +50,29 @@ public class VanillaPacketSplitter
/**
* Append the given packet to the given list. If the packet needs to be split, multiple packets will be appened.
* Otherwise only the packet itself.
*/
public static void appendPackets(ConnectionProtocol protocol, PacketFlow direction, Packet<?> packet, List<? super Packet<?>> out)
{
if (heuristicIsDefinitelySmallEnough(packet))
{
* /
public static void appendPackets(ConnectionProtocol protocol, PacketFlow direction, Packet<?> packet, List<? super Packet<?>> out) {
if (heuristicIsDefinitelySmallEnough(packet)) {
out.add(packet);
}
else
{
} else {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
packet.write(buf);
if (buf.readableBytes() <= PROTOCOL_MAX)
{
if (buf.readableBytes() <= PROTOCOL_MAX) {
buf.release();
out.add(packet);
}
else
{
} else {
int parts = (int)Math.ceil(((double)buf.readableBytes()) / PART_SIZE);
if (parts == 1)
{
if (parts == 1) {
buf.release();
out.add(packet);
}
else
{
for (int part = 0; part < parts; part++)
{
} else {
for (int part = 0; part < parts; part++) {
ByteBuf partPrefix;
if (part == 0)
{
if (part == 0) {
partPrefix = Unpooled.buffer(5);
partPrefix.writeByte(STATE_FIRST);
new FriendlyByteBuf(partPrefix).writeVarInt(protocol.getPacketId(direction, packet));
}
else
{
} else {
partPrefix = Unpooled.buffer(1);
partPrefix.writeByte(part == parts - 1 ? STATE_LAST : 0);
}
@@ -108,15 +91,13 @@ public class VanillaPacketSplitter
}
}
private static boolean heuristicIsDefinitelySmallEnough(Packet<?> packet)
{
private static boolean heuristicIsDefinitelySmallEnough(Packet<?> packet) {
return false;
}
private static final List<FriendlyByteBuf> receivedBuffers = new ArrayList<>();
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event)
{
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event) {
NetworkEvent.Context ctx = event.getSource().get();
PacketFlow direction = ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT ? PacketFlow.CLIENTBOUND : PacketFlow.SERVERBOUND;
ConnectionProtocol protocol = ConnectionProtocol.PLAY;
@@ -126,27 +107,21 @@ public class VanillaPacketSplitter
FriendlyByteBuf buf = event.getPayload();
byte state = buf.readByte();
if (state == STATE_FIRST)
{
if (!receivedBuffers.isEmpty())
{
if (state == STATE_FIRST) {
if (!receivedBuffers.isEmpty()) {
LOGGER.warn("forge:split received out of order - inbound buffer not empty when receiving first");
receivedBuffers.clear();
}
}
buf.retain(); // retain the buffer, it is released after this handler otherwise
receivedBuffers.add(buf);
if (state == STATE_LAST)
{
if (state == STATE_LAST) {
FriendlyByteBuf full = new FriendlyByteBuf(Unpooled.wrappedBuffer(receivedBuffers.toArray(new FriendlyByteBuf[0])));
int packetId = full.readVarInt();
Packet<?> packet = protocol.createPacket(direction, packetId, full);
if (packet == null)
{
if (packet == null) {
LOGGER.error("Received invalid packet ID {} in forge:split", packetId);
}
else
{
} else {
receivedBuffers.clear();
full.release();
ctx.enqueueWork(() -> genericsFtw(packet, event.getSource().get().getNetworkManager().getPacketListener()));
@@ -155,32 +130,25 @@ public class VanillaPacketSplitter
}
@SuppressWarnings("unchecked")
private static <T extends PacketListener> void genericsFtw(Packet<T> pkt, Object listener)
{
private static <T extends PacketListener> void genericsFtw(Packet<T> pkt, Object listener) {
pkt.handle((T) listener);
}
public enum RemoteCompatibility
{
public enum RemoteCompatibility {
ABSENT,
PRESENT
}
public static RemoteCompatibility getRemoteCompatibility(Connection manager)
{
public static RemoteCompatibility getRemoteCompatibility(Connection manager) {
ConnectionData connectionData = NetworkHooks.getConnectionData(manager);
if (connectionData != null && connectionData.getChannels().containsKey(CHANNEL))
{
return RemoteCompatibility.PRESENT;
}
else
{
return RemoteCompatibility.ABSENT;
}
}
public static boolean isRemoteCompatible(Connection manager)
{
public static boolean isRemoteCompatible(Connection manager) {
return getRemoteCompatibility(manager) != RemoteCompatibility.ABSENT;
}
}
*/