From 85091b845523ed0ded93796e4f970e01ce9a14dd Mon Sep 17 00:00:00 2001 From: deirn Date: Fri, 19 Jan 2024 21:57:46 +0700 Subject: [PATCH] split type and receiver registration for clientbound packet --- .../bai/badpackets/api/C2SPacketReceiver.java | 28 --------- .../lol/bai/badpackets/api/PacketSender.java | 8 +-- .../bai/badpackets/api/S2CPacketReceiver.java | 28 --------- .../badpackets/api/config/ConfigPackets.java | 50 ++++++++++++--- .../api/event/PacketSenderReadyCallback.java | 63 ------------------- .../bai/badpackets/api/play/PlayPackets.java | 54 ++++++++++++---- .../MixinClientboundCustomPayloadPacket.java | 2 +- .../impl/registry/ChannelRegistry.java | 34 +++++++--- src/main/resources/badpackets.mixins.json | 2 +- .../bai/badpackets/test/BadPacketTest.java | 24 ++++--- 10 files changed, 128 insertions(+), 165 deletions(-) delete mode 100644 src/main/java/lol/bai/badpackets/api/C2SPacketReceiver.java delete mode 100644 src/main/java/lol/bai/badpackets/api/S2CPacketReceiver.java delete mode 100644 src/main/java/lol/bai/badpackets/api/event/PacketSenderReadyCallback.java rename src/main/java/lol/bai/badpackets/impl/mixin/{client => }/MixinClientboundCustomPayloadPacket.java (98%) diff --git a/src/main/java/lol/bai/badpackets/api/C2SPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/C2SPacketReceiver.java deleted file mode 100644 index 204266f..0000000 --- a/src/main/java/lol/bai/badpackets/api/C2SPacketReceiver.java +++ /dev/null @@ -1,28 +0,0 @@ -package lol.bai.badpackets.api; - -import lol.bai.badpackets.api.play.PlayPackets; -import lol.bai.badpackets.api.play.ServerPlayPacketReceiver; -import lol.bai.badpackets.impl.marker.ApiSide; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; - -@Deprecated(forRemoval = true) -@ApiSide.ServerOnly -@FunctionalInterface -public interface C2SPacketReceiver extends ServerPlayPacketReceiver { - - /** - * @deprecated use {@link PlayPackets#registerServerReceiver(ResourceLocation, ServerPlayPacketReceiver)} - */ - @Deprecated(forRemoval = true) - static void register(ResourceLocation id, C2SPacketReceiver receiver) { - PlayPackets.registerServerReceiver(id, receiver); - } - - @Override - void receive(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl handler, FriendlyByteBuf buf, PacketSender responseSender); - -} diff --git a/src/main/java/lol/bai/badpackets/api/PacketSender.java b/src/main/java/lol/bai/badpackets/api/PacketSender.java index ab31660..32904c1 100644 --- a/src/main/java/lol/bai/badpackets/api/PacketSender.java +++ b/src/main/java/lol/bai/badpackets/api/PacketSender.java @@ -26,8 +26,8 @@ public interface PacketSender { *

* Only available when on game. * - * @see PlayPackets#registerServerReceiver(ResourceLocation, ServerPlayPacketReceiver) - * @see PlayPackets#registerServerReceiver(CustomPacketPayload.Type, StreamCodec, ServerPlayPacketReceiver) + * @see PlayPackets#registerServerChannel(ResourceLocation, ServerPlayPacketReceiver) + * @see PlayPackets#registerServerChannel(CustomPacketPayload.Type, StreamCodec, ServerPlayPacketReceiver) */ @ApiSide.ClientOnly static PacketSender c2s() { @@ -39,8 +39,8 @@ static PacketSender c2s() { * * @param player the player that we want to send packets to. * - * @see PlayPackets#registerClientReceiver(ResourceLocation, ClientPlayPacketReceiver) - * @see PlayPackets#registerClientReceiver(CustomPacketPayload.Type, StreamCodec, ClientPlayPacketReceiver) + * @see PlayPackets#registerClientChannel(ResourceLocation, ClientPlayPacketReceiver) + * @see PlayPackets#registerClientChannel(CustomPacketPayload.Type, StreamCodec, ClientPlayPacketReceiver) */ @ApiSide.ServerOnly static PacketSender s2c(ServerPlayer player) { diff --git a/src/main/java/lol/bai/badpackets/api/S2CPacketReceiver.java b/src/main/java/lol/bai/badpackets/api/S2CPacketReceiver.java deleted file mode 100644 index b86e9ae..0000000 --- a/src/main/java/lol/bai/badpackets/api/S2CPacketReceiver.java +++ /dev/null @@ -1,28 +0,0 @@ -package lol.bai.badpackets.api; - -import lol.bai.badpackets.api.play.ClientPlayPacketReceiver; -import lol.bai.badpackets.api.play.PlayPackets; -import lol.bai.badpackets.impl.marker.ApiSide; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; - -@Deprecated(forRemoval = true) -@ApiSide.ClientOnly -@FunctionalInterface -public interface S2CPacketReceiver extends ClientPlayPacketReceiver { - - /** - * @deprecated use {@link PlayPackets#registerClientReceiver(ResourceLocation, ClientPlayPacketReceiver)} - */ - @ApiSide.ClientOnly - @Deprecated(forRemoval = true) - static void register(ResourceLocation id, S2CPacketReceiver receiver) { - PlayPackets.registerClientReceiver(id, receiver); - } - - @Override - void receive(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender); - -} diff --git a/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java b/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java index d1a6b35..5ba375e 100644 --- a/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java +++ b/src/main/java/lol/bai/badpackets/api/config/ConfigPackets.java @@ -44,9 +44,9 @@ public static void registerTask(ResourceLocation id, ConfigTaskExecutor executor * * @see ServerConfigPacketReceiver#receive */ - public static void registerServerReceiver(ResourceLocation id, ServerConfigPacketReceiver receiver) { - registerServerReceiver(UntypedPayload.type(id), UntypedPayload.codec(id), (server, handler, payload, responseSender, taskFinisher) -> - receiver.receive(server, handler, payload.buffer(), responseSender, taskFinisher)); + public static void registerServerChannel(ResourceLocation id, ServerConfigPacketReceiver receiver) { + ChannelRegistry.CONFIG_C2S.registerCodec(id, UntypedPayload.codec(id)); + ChannelRegistry.CONFIG_C2S.registerReceiver(id, (server, handler, payload, responseSender, taskFinisher) -> receiver.receive(server, handler, ((UntypedPayload) payload).buffer(), responseSender, taskFinisher)); } /** @@ -61,8 +61,9 @@ public static void registerServerReceiver(ResourceLocation id, ServerConfigPacke * @see ServerConfigPacketReceiver#receive */ @SuppressWarnings("unchecked") - public static

void registerServerReceiver(CustomPacketPayload.Type

type, StreamCodec codec, ServerConfigPacketReceiver

receiver) { - ChannelRegistry.CONFIG_C2S.register(type, codec, (ServerConfigPacketReceiver) receiver); + public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec, ServerConfigPacketReceiver

receiver) { + ChannelRegistry.CONFIG_C2S.registerCodec(type.id(), codec); + ChannelRegistry.CONFIG_C2S.registerReceiver(type.id(), (ServerConfigPacketReceiver) receiver); } /** @@ -80,6 +81,35 @@ public static void registerServerReadyCallback(ServerConfigPacketReadyCallback c /** * Register a server-to-client packet receiver. *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, ClientConfigPacketReceiver)} + * + * @param id the packet id + */ + public static void registerClientChannel(ResourceLocation id) { + ChannelRegistry.CONFIG_S2C.registerCodec(id, UntypedPayload.codec(id)); + } + + /** + * Register a server-to-client packet receiver. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, ClientConfigPacketReceiver)} + * + * @param type the {@linkplain CustomPacketPayload#type() packet type} + * @param codec the payload codec + */ + public static

void registerClientChannel(CustomPacketPayload.Type

type, StreamCodec codec) { + ChannelRegistry.CONFIG_S2C.registerCodec(type.id(), codec); + } + + /** + * Register a server-to-client packet receiver. + *

+ * The channel needs to be {@linkplain #registerClientChannel(ResourceLocation) registered} first. + *

* Raw packet receiver is run on Netty event-loop. Read the buffer on it and run * the operation on {@linkplain Minecraft#execute(Runnable) client thread}. * @@ -91,17 +121,17 @@ public static void registerServerReadyCallback(ServerConfigPacketReadyCallback c */ @ApiSide.ClientOnly public static void registerClientReceiver(ResourceLocation id, ClientConfigPacketReceiver receiver) { - registerClientReceiver(UntypedPayload.type(id), UntypedPayload.codec(id), (client, handler, payload, responseSender) -> - receiver.receive(client, handler, payload.buffer(), responseSender)); + ChannelRegistry.CONFIG_S2C.registerReceiver(id, (client, handler, payload, responseSender) -> receiver.receive(client, handler, ((UntypedPayload) payload).buffer(), responseSender)); } /** * Register a server-to-client packet receiver. *

+ * The channel needs to be {@linkplain #registerClientChannel(CustomPacketPayload.Type, StreamCodec) registered} first. + *

* Typed packet receiver is run on the main client thread. * * @param type the {@linkplain CustomPacketPayload#type() packet type} - * @param codec the payload codec * @param receiver the receiver * * @see ClientConfigPacketReceiver#receive @@ -109,8 +139,8 @@ public static void registerClientReceiver(ResourceLocation id, ClientConfigPacke */ @ApiSide.ClientOnly @SuppressWarnings("unchecked") - public static

void registerClientReceiver(CustomPacketPayload.Type

type, StreamCodec codec, ClientConfigPacketReceiver

receiver) { - ChannelRegistry.CONFIG_S2C.register(type, codec, (ClientConfigPacketReceiver) receiver); + public static

void registerClientReceiver(CustomPacketPayload.Type

type, ClientConfigPacketReceiver

receiver) { + ChannelRegistry.CONFIG_S2C.registerReceiver(type.id(), (ClientConfigPacketReceiver) receiver); } /** diff --git a/src/main/java/lol/bai/badpackets/api/event/PacketSenderReadyCallback.java b/src/main/java/lol/bai/badpackets/api/event/PacketSenderReadyCallback.java deleted file mode 100644 index b901e21..0000000 --- a/src/main/java/lol/bai/badpackets/api/event/PacketSenderReadyCallback.java +++ /dev/null @@ -1,63 +0,0 @@ -package lol.bai.badpackets.api.event; - -import lol.bai.badpackets.api.PacketSender; -import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback; -import lol.bai.badpackets.api.play.PlayPackets; -import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback; -import lol.bai.badpackets.impl.marker.ApiSide; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; - -@Deprecated(forRemoval = true) -public final class PacketSenderReadyCallback { - - /** - * @deprecated use {@link PlayPackets#registerServerReadyCallback(ServerPlayPacketReadyCallback)} - */ - @Deprecated(forRemoval = true) - @ApiSide.ServerOnly - public static void registerServer(Server callback) { - PlayPackets.registerServerReadyCallback(callback); - } - - /** - * @deprecated use {@link PlayPackets#registerClientReadyCallback(ClientPlayPacketReadyCallback)} - */ - @Deprecated(forRemoval = true) - @ApiSide.ClientOnly - public static void registerClient(Client callback) { - PlayPackets.registerClientReadyCallback(callback); - } - - @ApiSide.ServerOnly - @FunctionalInterface - public interface Server extends ServerPlayPacketReadyCallback { - - @Override - default void onReady(ServerGamePacketListenerImpl handler, PacketSender sender, MinecraftServer server) { - onJoin(handler, sender, server); - } - - void onJoin(ServerGamePacketListenerImpl handler, PacketSender sender, MinecraftServer server); - - } - - @ApiSide.ClientOnly - @FunctionalInterface - public interface Client extends ClientPlayPacketReadyCallback { - - @Override - default void onReady(ClientPacketListener handler, PacketSender sender, Minecraft client) { - onJoin(handler, sender, client); - } - - void onJoin(ClientPacketListener handler, PacketSender sender, Minecraft client); - - } - - private PacketSenderReadyCallback() { - } - -} diff --git a/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java b/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java index 59c56d6..5e44623 100644 --- a/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java +++ b/src/main/java/lol/bai/badpackets/api/play/PlayPackets.java @@ -19,7 +19,7 @@ public final class PlayPackets { /** - * Register a client-to-server packet receiver. + * Register a client-to-server packet channel. *

* Raw packet receiver is run on Netty event-loop. Read the buffer on it and run * the operation on {@linkplain MinecraftServer#execute(Runnable) server thread}. @@ -27,13 +27,13 @@ public final class PlayPackets { * @param id the packet id * @param receiver the receiver */ - public static void registerServerReceiver(ResourceLocation id, ServerPlayPacketReceiver receiver) { - registerServerReceiver(UntypedPayload.type(id), UntypedPayload.codec(id), (server, player, handler, payload, responseSender) -> - receiver.receive(server, player, handler, payload.buffer(), responseSender)); + public static void registerServerChannel(ResourceLocation id, ServerPlayPacketReceiver receiver) { + ChannelRegistry.PLAY_C2S.registerCodec(id, UntypedPayload.codec(id)); + ChannelRegistry.PLAY_C2S.registerReceiver(id, (server, player, handler, payload, responseSender) -> receiver.receive(server, player, handler, ((UntypedPayload) payload).buffer(), responseSender)); } /** - * Register a client-to-server packet receiver. + * Register a client-to-server packet channel. *

* Typed packet receiver is run on the main server thread. * @@ -42,8 +42,9 @@ public static void registerServerReceiver(ResourceLocation id, ServerPlayPacketR * @param receiver the receiver */ @SuppressWarnings("unchecked") - public static

void registerServerReceiver(CustomPacketPayload.Type

type, StreamCodec codec, ServerPlayPacketReceiver

receiver) { - ChannelRegistry.PLAY_C2S.register(type, codec, (ServerPlayPacketReceiver) receiver); + public static

void registerServerChannel(CustomPacketPayload.Type

type, StreamCodec codec, ServerPlayPacketReceiver

receiver) { + ChannelRegistry.PLAY_C2S.registerCodec(type.id(), codec); + ChannelRegistry.PLAY_C2S.registerReceiver(type.id(), (ServerPlayPacketReceiver) receiver); } /** @@ -57,9 +58,38 @@ public static void registerServerReadyCallback(ServerPlayPacketReadyCallback cal CallbackRegistry.SERVER_PLAY.add(callback); } + /** + * Register a server-to-client packet channel. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on client side with {@link #registerClientReceiver(ResourceLocation, ClientPlayPacketReceiver)} + * + * @param id the packet id + */ + public static void registerClientChannel(ResourceLocation id) { + ChannelRegistry.PLAY_S2C.registerCodec(id, UntypedPayload.codec(id)); + } + + /** + * Register a server-to-client packet channel. + *

+ * This method needs to be called on all sides. + *

+ * Register the receiver on client side with {@link #registerClientReceiver(CustomPacketPayload.Type, ClientPlayPacketReceiver)} + * + * @param type the {@linkplain CustomPacketPayload#type() packet type} + * @param codec the payload codec + */ + public static

void registerClientChannel(CustomPacketPayload.Type

type, StreamCodec codec) { + ChannelRegistry.PLAY_S2C.registerCodec(type.id(), codec); + } + /** * Register a server-to-client packet receiver. *

+ * The channel needs to be {@linkplain #registerClientChannel(ResourceLocation) registered} first. + *

* Raw packet receiver is run on Netty event-loop. Read the buffer on it and run * the operation on {@linkplain Minecraft#execute(Runnable) client thread}. * @@ -68,23 +98,23 @@ public static void registerServerReadyCallback(ServerPlayPacketReadyCallback cal */ @ApiSide.ClientOnly public static void registerClientReceiver(ResourceLocation id, ClientPlayPacketReceiver receiver) { - registerClientReceiver(UntypedPayload.type(id), UntypedPayload.codec(id), (client, handler, payload, responseSender) -> - receiver.receive(client, handler, payload.buffer(), responseSender)); + ChannelRegistry.PLAY_S2C.registerReceiver(id, (client, handler, payload, responseSender) -> receiver.receive(client, handler, ((UntypedPayload) payload).buffer(), responseSender)); } /** * Register a server-to-client packet receiver. *

+ * The channel needs to be {@linkplain #registerClientChannel(CustomPacketPayload.Type, StreamCodec) registered} first. + *

* Typed packet receiver is run on the main client thread. * * @param type the {@linkplain CustomPacketPayload#type() packet type} - * @param codec the payload codec * @param receiver the receiver */ @ApiSide.ClientOnly @SuppressWarnings("unchecked") - public static

void registerClientReceiver(CustomPacketPayload.Type

type, StreamCodec codec, ClientPlayPacketReceiver

receiver) { - ChannelRegistry.PLAY_S2C.register(type, codec, (ClientPlayPacketReceiver) receiver); + public static

void registerClientReceiver(CustomPacketPayload.Type

type, ClientPlayPacketReceiver

receiver) { + ChannelRegistry.PLAY_S2C.registerReceiver(type.id(), (ClientPlayPacketReceiver) receiver); } /** diff --git a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientboundCustomPayloadPacket.java b/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java similarity index 98% rename from src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientboundCustomPayloadPacket.java rename to src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java index 65eb001..33f8874 100644 --- a/src/main/java/lol/bai/badpackets/impl/mixin/client/MixinClientboundCustomPayloadPacket.java +++ b/src/main/java/lol/bai/badpackets/impl/mixin/MixinClientboundCustomPayloadPacket.java @@ -1,4 +1,4 @@ -package lol.bai.badpackets.impl.mixin.client; +package lol.bai.badpackets.impl.mixin; import lol.bai.badpackets.impl.handler.AbstractPacketHandler; import lol.bai.badpackets.impl.registry.ChannelRegistry; diff --git a/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java b/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java index 45749af..17d8db0 100644 --- a/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java +++ b/src/main/java/lol/bai/badpackets/impl/registry/ChannelRegistry.java @@ -36,7 +36,7 @@ public class ChannelRegistry { private final Set reservedChannels; private final Map> codecs = new HashMap<>(); - private final Map channels = new HashMap<>(); + private final Map receivers = new HashMap<>(); private final Set> handlers = new HashSet<>(); private final ReentrantReadWriteLock locks = new ReentrantReadWriteLock(); @@ -47,19 +47,33 @@ private ChannelRegistry(Set reservedChannels) { codecs.put(Constants.CHANNEL_SYNC, UntypedPayload.codec(Constants.CHANNEL_SYNC)); } - public

void register(CustomPacketPayload.Type

type, StreamCodec codec, R receiver) { + public

void registerCodec(ResourceLocation id, StreamCodec codec) { Lock lock = locks.writeLock(); lock.lock(); try { - if (reservedChannels.contains(type.id())) { - throw new IllegalArgumentException("Reserved channel id " + type.id()); + if (reservedChannels.contains(id)) { + throw new IllegalArgumentException("Reserved channel id " + id); } - codecs.put(type.id(), codec); - channels.put(type.id(), receiver); + codecs.put(id, codec); + } finally { + lock.unlock(); + } + } + + public void registerReceiver(ResourceLocation id, R receiver) { + Lock lock = locks.writeLock(); + lock.lock(); + + try { + if (!codecs.containsKey(id)) { + throw new IllegalArgumentException("Unknown channel id " + id); + } + + receivers.put(id, receiver); for (AbstractPacketHandler handler : handlers) { - handler.onRegister(type.id()); + handler.onRegister(id); } } finally { lock.unlock(); @@ -71,7 +85,7 @@ public boolean has(ResourceLocation id) { lock.lock(); try { - return channels.containsKey(id); + return receivers.containsKey(id); } finally { lock.unlock(); } @@ -82,7 +96,7 @@ public R get(ResourceLocation id) { lock.lock(); try { - return channels.get(id); + return receivers.get(id); } finally { lock.unlock(); } @@ -105,7 +119,7 @@ public Set getChannels() { lock.lock(); try { - return new HashSet<>(channels.keySet()); + return new HashSet<>(receivers.keySet()); } finally { lock.unlock(); } diff --git a/src/main/resources/badpackets.mixins.json b/src/main/resources/badpackets.mixins.json index ffc8b5a..6fafb36 100644 --- a/src/main/resources/badpackets.mixins.json +++ b/src/main/resources/badpackets.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_16", "refmap" : "badpackets.refmap.json", "mixins" : [ + "MixinClientboundCustomPayloadPacket", "MixinPlayerList", "MixinServerboundCustomPayloadPacket", "MixinServerCommonPacketListenerImpl", @@ -13,7 +14,6 @@ ], "client" : [ "client.AccessClientCommonPacketListenerImpl", - "client.MixinClientboundCustomPayloadPacket", "client.MixinClientCommonPacketListenerImpl", "client.MixinClientConfigurationPacketListenerImpl", "client.MixinClientPacketListener" diff --git a/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java b/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java index 91c17cd..7e855c6 100644 --- a/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java +++ b/src/testmod/java/lol/bai/badpackets/test/BadPacketTest.java @@ -35,7 +35,7 @@ public static void server() { return false; }); - ConfigPackets.registerServerReceiver(TestTaskPayload.TYPE, TestTaskPayload.CODEC, (server, handler, payload, responseSender, taskFinisher) -> { + ConfigPackets.registerServerChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC, (server, handler, payload, responseSender, taskFinisher) -> { LOGGER.info("[config task] client -> server " + payload.stage().name()); switch (payload.stage()) { @@ -46,12 +46,14 @@ public static void server() { } }); + ConfigPackets.registerClientChannel(TestTaskPayload.TYPE, TestTaskPayload.CODEC); + // CONFIG ------------------------------------------------------------------------------------------------------ - ConfigPackets.registerServerReceiver(CONFIG_C2S, (server, handler, buf, responseSender, taskFinisher) -> + ConfigPackets.registerServerChannel(CONFIG_C2S, (server, handler, buf, responseSender, taskFinisher) -> LOGGER.info(buf.readUtf())); - ConfigPackets.registerServerReceiver(TestConfigPayload.TYPE, TestConfigPayload.CODEC, (server, handler, payload, responseSender, taskFinisher) -> + ConfigPackets.registerServerChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC, (server, handler, payload, responseSender, taskFinisher) -> LOGGER.info(payload.msg())); ConfigPackets.registerServerReadyCallback((handler, sender, server) -> { @@ -65,12 +67,15 @@ public static void server() { sender.send(new TestConfigPayload("[config typed] server -> client")); }); + ConfigPackets.registerClientChannel(CONFIG_S2C); + ConfigPackets.registerClientChannel(TestConfigPayload.TYPE, TestConfigPayload.CODEC); + // PLAY -------------------------------------------------------------------------------------------------------- - PlayPackets.registerServerReceiver(PLAY_C2S, (server, player, handler, buf, responseSender) -> + PlayPackets.registerServerChannel(PLAY_C2S, (server, player, handler, buf, responseSender) -> LOGGER.info(buf.readUtf())); - PlayPackets.registerServerReceiver(TestPlayPayload.TYPE, TestPlayPayload.CODEC, (server, player, handler, payload, responseSender) -> + PlayPackets.registerServerChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC, (server, player, handler, payload, responseSender) -> LOGGER.info(payload.msg())); PlayPackets.registerServerReadyCallback((handler, sender, server) -> { @@ -83,12 +88,15 @@ public static void server() { sender.send(new TestPlayPayload("[play typed] server -> client")); }); + + PlayPackets.registerClientChannel(PLAY_S2C); + PlayPackets.registerClientChannel(TestPlayPayload.TYPE, TestPlayPayload.CODEC); } public static void client() { // TASK -------------------------------------------------------------------------------------------------------- - ConfigPackets.registerClientReceiver(TestTaskPayload.TYPE, TestTaskPayload.CODEC, (client, handler, payload, responseSender) -> { + ConfigPackets.registerClientReceiver(TestTaskPayload.TYPE, (client, handler, payload, responseSender) -> { LOGGER.info("[config task] server -> client " + payload.stage().name()); switch (payload.stage()) { @@ -104,7 +112,7 @@ public static void client() { ConfigPackets.registerClientReceiver(CONFIG_S2C, (client, handler, buf, responseSender) -> LOGGER.info(buf.readUtf())); - ConfigPackets.registerClientReceiver(TestConfigPayload.TYPE, TestConfigPayload.CODEC, (client, handler, payload, responseSender) -> + ConfigPackets.registerClientReceiver(TestConfigPayload.TYPE, (client, handler, payload, responseSender) -> LOGGER.info(payload.msg())); ConfigPackets.registerClientReadyCallback((handler, sender, client) -> { @@ -123,7 +131,7 @@ public static void client() { PlayPackets.registerClientReceiver(PLAY_S2C, (client, handler, buf, responseSender) -> LOGGER.info(buf.readUtf())); - PlayPackets.registerClientReceiver(TestPlayPayload.TYPE, TestPlayPayload.CODEC, (client, handler, payload, responseSender) -> + PlayPackets.registerClientReceiver(TestPlayPayload.TYPE, (client, handler, payload, responseSender) -> LOGGER.info(payload.msg())); PlayPackets.registerClientReadyCallback((handler, sender, client) -> {