fix client communication for carpet
This commit is contained in:
1 parent
08c5c3db31
commit
7a19bbe997
8 files changed
+68
-199
No files matched your search
@@ -1,11 +0,0 @@
|
|||||||
package carpet.fakes;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
|
|
||||||
public interface CarpetPacketPayload extends CustomPacketPayload
|
|
||||||
{
|
|
||||||
FriendlyByteBuf data();
|
|
||||||
}
|
|
||||||
@@ -7,21 +7,12 @@ import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
|
|||||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
import net.minecraft.client.multiplayer.CommonListenerCookie;
|
||||||
import net.minecraft.network.Connection;
|
import net.minecraft.network.Connection;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.protocol.common.ClientCommonPacketListener;
|
|
||||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(ClientPacketListener.class)
|
@Mixin(ClientPacketListener.class)
|
||||||
public abstract class ClientPacketListener_customPacketsMixin extends ClientCommonPacketListenerImpl
|
public abstract class ClientPacketListener_customPacketsMixin extends ClientCommonPacketListenerImpl
|
||||||
@@ -38,4 +29,16 @@ public abstract class ClientPacketListener_customPacketsMixin extends ClientComm
|
|||||||
CarpetClient.gameJoined( minecraft.player);
|
CarpetClient.gameJoined( minecraft.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "handleUnknownCustomPayload", at = @At(
|
||||||
|
value = "HEAD"
|
||||||
|
), cancellable = true)
|
||||||
|
private void onOnCustomPayload(CustomPacketPayload packet, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
if (packet instanceof CarpetClient.CarpetPayload cpp)
|
||||||
|
{
|
||||||
|
ClientNetworkHandler.handleData(cpp, minecraft.player);
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,19 +17,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
@Mixin(ClientboundCustomPayloadPacket.class)
|
@Mixin(ClientboundCustomPayloadPacket.class)
|
||||||
public class ClientboundCustomPayloadPacket_customPacketMixin
|
public class ClientboundCustomPayloadPacket_customPacketMixin
|
||||||
{
|
{
|
||||||
@Inject(method = "readPayload", at = @At("HEAD"))
|
@Inject(method = "readUnknownPayload", at = @At("HEAD"), cancellable = true)
|
||||||
private static void onOnCustomPayloadR(final ResourceLocation resourceLocation, final FriendlyByteBuf friendlyByteBuf, final CallbackInfoReturnable<CustomPacketPayload> cir)
|
private static void onOnCustomPayloadR(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||||
{
|
{
|
||||||
}
|
if (resourceLocation.equals(CarpetClient.CARPET_CHANNEL))
|
||||||
|
|
||||||
@Inject(method = "readUnknownPayload", at = @At(value = "HEAD"), cancellable = true)
|
|
||||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<DiscardedPayload> cir)
|
|
||||||
{
|
{
|
||||||
if (true) return;
|
cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf));
|
||||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation) && Minecraft.getInstance().isSameThread())
|
|
||||||
{
|
|
||||||
ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
|
||||||
cir.setReturnValue(new DiscardedPayload(resourceLocation));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.fakes.CarpetPacketPayload;
|
import carpet.network.CarpetClient;
|
||||||
import carpet.network.ServerNetworkHandler;
|
import carpet.network.ServerNetworkHandler;
|
||||||
import net.minecraft.network.protocol.PacketUtils;
|
import net.minecraft.network.protocol.PacketUtils;
|
||||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||||
@@ -18,16 +18,14 @@ public class ServerCommonPacketListenerimpl_connectionMixin
|
|||||||
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "handleCustomPayload", at = @At("HEAD"), cancellable = true)
|
||||||
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
private void onCustomCarpetPayload(ServerboundCustomPayloadPacket serverboundCustomPayloadPacket, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if (true) return;
|
|
||||||
Object thiss = this;
|
Object thiss = this;
|
||||||
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetPacketPayload cpp) {
|
if (thiss instanceof ServerGamePacketListenerImpl impl && serverboundCustomPayloadPacket.payload() instanceof CarpetClient.CarpetPayload cpp) {
|
||||||
// We should force onto the main thread here
|
// We should force onto the main thread here
|
||||||
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
// ServerNetworkHandler.handleData can possibly mutate data that isn't
|
||||||
// thread safe, and also allows for client commands to be executed
|
// thread safe, and also allows for client commands to be executed
|
||||||
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel());
|
PacketUtils.ensureRunningOnSameThread(serverboundCustomPayloadPacket, (ServerGamePacketListener) this, impl.player.serverLevel());
|
||||||
ServerNetworkHandler.handleData(cpp.data(), impl.player);
|
ServerNetworkHandler.handleData(cpp, impl.player);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
ci.cancel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,9 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.fakes.CarpetPacketPayload;
|
|
||||||
import carpet.network.CarpetClient;
|
import carpet.network.CarpetClient;
|
||||||
import carpet.network.ClientNetworkHandler;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -17,36 +13,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
@Mixin(ServerboundCustomPayloadPacket.class)
|
@Mixin(ServerboundCustomPayloadPacket.class)
|
||||||
public class ServerboundCustomPayloadPacket_mixin
|
public class ServerboundCustomPayloadPacket_mixin
|
||||||
{
|
{
|
||||||
@Inject(method = "readPayload", at = @At(
|
@Inject(method = "readUnknownPayload", at = @At(value = "HEAD"), cancellable = true)
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/network/protocol/common/ServerboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;"
|
|
||||||
), cancellable = true)
|
|
||||||
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPacketPayload> cir)
|
||||||
{
|
{
|
||||||
if (true) return;
|
|
||||||
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation))
|
if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation))
|
||||||
{
|
{
|
||||||
//ClientNetworkHandler.handleData(friendlyByteBuf, Minecraft.getInstance().player);
|
cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf));
|
||||||
cir.setReturnValue(new CarpetPacketPayload()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public FriendlyByteBuf data()
|
|
||||||
{
|
|
||||||
return friendlyByteBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(final FriendlyByteBuf friendlyByteBuf)
|
|
||||||
{
|
|
||||||
// noop - its a client side and we handle it server side only
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id()
|
|
||||||
{
|
|
||||||
return resourceLocation;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,22 +14,21 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
|
|
||||||
public class CarpetClient
|
public class CarpetClient
|
||||||
{
|
{
|
||||||
public record CarpetPayload(CompoundTag data) implements CustomPacketPayload
|
public record CarpetPayload(int command, CompoundTag data) implements CustomPacketPayload
|
||||||
{
|
{
|
||||||
public static final ResourceLocation ID = CARPET_CHANNEL;
|
public CarpetPayload(FriendlyByteBuf input) {
|
||||||
|
this(input.readInt(), input.readNbt());
|
||||||
public CarpetPayload(final FriendlyByteBuf input) {
|
|
||||||
this(input.readNbt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(final FriendlyByteBuf output) {
|
public void write(FriendlyByteBuf output) {
|
||||||
|
output.writeInt(command);
|
||||||
output.writeNbt(data);
|
output.writeNbt(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public ResourceLocation id() {
|
||||||
return ID;
|
return CARPET_CHANNEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,22 +99,18 @@ public class ClientNetworkHandler
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Ran on the Main Minecraft Thread
|
// Ran on the Main Minecraft Thread
|
||||||
public static void handleData(FriendlyByteBuf data, LocalPlayer player)
|
public static void handleData(CarpetClient.CarpetPayload data, LocalPlayer player)
|
||||||
{
|
{
|
||||||
if (data != null)
|
if (data.command() == CarpetClient.HI)
|
||||||
{
|
onHi(data.data());
|
||||||
int id = data.readVarInt();
|
if (data.command() == CarpetClient.DATA)
|
||||||
if (id == CarpetClient.HI)
|
onSyncData(data.data(), player);
|
||||||
onHi(data);
|
|
||||||
if (id == CarpetClient.DATA)
|
|
||||||
onSyncData(data, player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onHi(FriendlyByteBuf data)
|
private static void onHi(CompoundTag data)
|
||||||
{
|
{
|
||||||
CarpetClient.setCarpet();
|
CarpetClient.setCarpet();
|
||||||
CarpetClient.serverCarpetVersion = data.readUtf(64);
|
CarpetClient.serverCarpetVersion = data.getString("version");
|
||||||
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion))
|
if (CarpetSettings.carpetVersion.equals(CarpetClient.serverCarpetVersion))
|
||||||
{
|
{
|
||||||
CarpetSettings.LOG.info("Joined carpet server with matching carpet version");
|
CarpetSettings.LOG.info("Joined carpet server with matching carpet version");
|
||||||
@@ -130,28 +126,15 @@ public class ClientNetworkHandler
|
|||||||
|
|
||||||
public static void respondHello()
|
public static void respondHello()
|
||||||
{
|
{
|
||||||
|
CompoundTag data = new CompoundTag();
|
||||||
|
data.putString("version", CarpetSettings.carpetVersion);
|
||||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||||
new CustomPacketPayload()
|
new CarpetClient.CarpetPayload(CarpetClient.HELLO, data)
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void write(final FriendlyByteBuf friendlyByteBuf)
|
|
||||||
{
|
|
||||||
friendlyByteBuf.writeVarInt(CarpetClient.HELLO).writeUtf(CarpetSettings.carpetVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id()
|
|
||||||
{
|
|
||||||
return CarpetClient.CARPET_CHANNEL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onSyncData(FriendlyByteBuf data, LocalPlayer player)
|
private static void onSyncData(CompoundTag compound, LocalPlayer player)
|
||||||
{
|
{
|
||||||
CompoundTag compound = data.readNbt();
|
|
||||||
if (compound == null) return;
|
|
||||||
for (String key: compound.getAllKeys())
|
for (String key: compound.getAllKeys())
|
||||||
{
|
{
|
||||||
if (dataHandlers.containsKey(key)) {
|
if (dataHandlers.containsKey(key)) {
|
||||||
@@ -176,20 +159,7 @@ public class ClientNetworkHandler
|
|||||||
CompoundTag outer = new CompoundTag();
|
CompoundTag outer = new CompoundTag();
|
||||||
outer.put("clientCommand", tag);
|
outer.put("clientCommand", tag);
|
||||||
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
CarpetClient.getPlayer().connection.send(new ServerboundCustomPayloadPacket(
|
||||||
new CustomPacketPayload()
|
new CarpetClient.CarpetPayload(CarpetClient.DATA, outer)
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void write( FriendlyByteBuf friendlyByteBuf)
|
|
||||||
{
|
|
||||||
friendlyByteBuf.writeVarInt(CarpetClient.DATA).writeNbt(outer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id()
|
|
||||||
{
|
|
||||||
return CarpetClient.CARPET_CHANNEL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,11 @@ import carpet.CarpetServer;
|
|||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.api.settings.CarpetRule;
|
import carpet.api.settings.CarpetRule;
|
||||||
import carpet.api.settings.RuleHelper;
|
import carpet.api.settings.RuleHelper;
|
||||||
import carpet.fakes.CarpetPacketPayload;
|
|
||||||
import carpet.fakes.MinecraftServerInterface;
|
import carpet.fakes.MinecraftServerInterface;
|
||||||
import carpet.fakes.ServerGamePacketListenerImplInterface;
|
import carpet.fakes.ServerGamePacketListenerImplInterface;
|
||||||
import carpet.helpers.ServerTickRateManager;
|
import carpet.helpers.ServerTickRateManager;
|
||||||
import carpet.script.utils.SnoopyCommandSource;
|
import carpet.script.utils.SnoopyCommandSource;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -17,7 +16,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
@@ -34,22 +32,6 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
|
|
||||||
public class ServerNetworkHandler
|
public class ServerNetworkHandler
|
||||||
{
|
{
|
||||||
@FunctionalInterface
|
|
||||||
public interface CarpetCustomPayload extends CustomPacketPayload
|
|
||||||
{
|
|
||||||
void writeData(FriendlyByteBuf output);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default void write(FriendlyByteBuf output) {
|
|
||||||
writeData(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default ResourceLocation id()
|
|
||||||
{
|
|
||||||
return CarpetClient.CARPET_CHANNEL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static final Map<ServerPlayer, String> remoteCarpetPlayers = new HashMap<>();
|
private static final Map<ServerPlayer, String> remoteCarpetPlayers = new HashMap<>();
|
||||||
private static final Set<ServerPlayer> validCarpetPlayers = new HashSet<>();
|
private static final Set<ServerPlayer> validCarpetPlayers = new HashSet<>();
|
||||||
|
|
||||||
@@ -59,43 +41,31 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void handleData(FriendlyByteBuf data, ServerPlayer player)
|
public static void handleData(CarpetClient.CarpetPayload data, ServerPlayer player)
|
||||||
{
|
{
|
||||||
if (data != null)
|
int id = data.command();
|
||||||
{
|
|
||||||
int id = data.readVarInt();
|
|
||||||
if (id == CarpetClient.HELLO)
|
if (id == CarpetClient.HELLO)
|
||||||
onHello(player, data);
|
onHello(player, data.data());
|
||||||
if (id == CarpetClient.DATA)
|
if (id == CarpetClient.DATA)
|
||||||
onClientData(player, data);
|
onClientData(player, data.data());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ClientboundCustomPayloadPacket make(DataBuilder builder) {
|
||||||
|
CarpetClient.CarpetPayload carpetPayload = builder.build();
|
||||||
private static ClientboundCustomPayloadPacket make(Consumer<FriendlyByteBuf> accepter) {
|
return new ClientboundCustomPayloadPacket(carpetPayload);
|
||||||
return new ClientboundCustomPayloadPacket(
|
|
||||||
new CarpetCustomPayload()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void writeData(final FriendlyByteBuf t)
|
|
||||||
{
|
|
||||||
accepter.accept(t);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
private static ClientboundCustomPayloadPacket make(int command, CompoundTag data) {
|
||||||
|
return new ClientboundCustomPayloadPacket(new CarpetClient.CarpetPayload(command, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onPlayerJoin(ServerPlayer playerEntity)
|
public static void onPlayerJoin(ServerPlayer playerEntity)
|
||||||
{
|
{
|
||||||
if (true) return;
|
|
||||||
if (!((ServerGamePacketListenerImplInterface)playerEntity.connection).getConnection().isMemoryConnection())
|
if (!((ServerGamePacketListenerImplInterface)playerEntity.connection).getConnection().isMemoryConnection())
|
||||||
{
|
{
|
||||||
playerEntity.connection.send( make( output -> {
|
CompoundTag data = new CompoundTag();
|
||||||
output.writeVarInt(CarpetClient.HI);
|
data.putString("version", CarpetSettings.carpetVersion);
|
||||||
output.writeUtf(CarpetSettings.carpetVersion);
|
playerEntity.connection.send( make( CarpetClient.HI, data));
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -103,11 +73,10 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onHello(ServerPlayer playerEntity, FriendlyByteBuf packetData)
|
public static void onHello(ServerPlayer playerEntity, CompoundTag packetData)
|
||||||
{
|
{
|
||||||
if (true) return;
|
|
||||||
validCarpetPlayers.add(playerEntity);
|
validCarpetPlayers.add(playerEntity);
|
||||||
String clientVersion = packetData.readUtf(64);
|
String clientVersion = packetData.getString("version");
|
||||||
remoteCarpetPlayers.put(playerEntity, clientVersion);
|
remoteCarpetPlayers.put(playerEntity, clientVersion);
|
||||||
if (clientVersion.equals(CarpetSettings.carpetVersion))
|
if (clientVersion.equals(CarpetSettings.carpetVersion))
|
||||||
CarpetSettings.LOG.info("Player "+playerEntity.getName().getString()+" joined with a matching carpet client");
|
CarpetSettings.LOG.info("Player "+playerEntity.getName().getString()+" joined with a matching carpet client");
|
||||||
@@ -115,14 +84,13 @@ public class ServerNetworkHandler
|
|||||||
CarpetSettings.LOG.warn("Player "+playerEntity.getName().getString()+" joined with another carpet version: "+clientVersion);
|
CarpetSettings.LOG.warn("Player "+playerEntity.getName().getString()+" joined with another carpet version: "+clientVersion);
|
||||||
DataBuilder data = DataBuilder.create(playerEntity.server); // tickrate related settings are sent on world change
|
DataBuilder data = DataBuilder.create(playerEntity.server); // tickrate related settings are sent on world change
|
||||||
CarpetServer.forEachManager(sm -> sm.getCarpetRules().forEach(data::withRule));
|
CarpetServer.forEachManager(sm -> sm.getCarpetRules().forEach(data::withRule));
|
||||||
playerEntity.connection.send(make(data::build));
|
playerEntity.connection.send(make(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPlayerLevelData(ServerPlayer player, ServerLevel level) {
|
public static void sendPlayerLevelData(ServerPlayer player, ServerLevel level) {
|
||||||
if (CarpetSettings.superSecretSetting || !validCarpetPlayers.contains(player)) return;
|
if (CarpetSettings.superSecretSetting || !validCarpetPlayers.contains(player)) return;
|
||||||
DataBuilder data = DataBuilder.create(player.server).withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
DataBuilder data = DataBuilder.create(player.server).withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||||
player.connection.send(make(data::build));
|
player.connection.send(make(data));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleClientCommand(ServerPlayer player, CompoundTag commandData)
|
private static void handleClientCommand(ServerPlayer player, CompoundTag commandData)
|
||||||
@@ -149,17 +117,12 @@ public class ServerNetworkHandler
|
|||||||
ListTag outputResult = new ListTag();
|
ListTag outputResult = new ListTag();
|
||||||
for (Component line: output) outputResult.add(StringTag.valueOf(Component.Serializer.toJson(line)));
|
for (Component line: output) outputResult.add(StringTag.valueOf(Component.Serializer.toJson(line)));
|
||||||
if (!output.isEmpty()) result.put("output", outputResult);
|
if (!output.isEmpty()) result.put("output", outputResult);
|
||||||
player.connection.send(make( butebuf ->
|
player.connection.send(make( DataBuilder.create(player.server).withCustomNbt("clientCommand", result)));
|
||||||
DataBuilder.create(player.server).withCustomNbt("clientCommand", result).build(butebuf)
|
|
||||||
));
|
|
||||||
// run command plug to command output,
|
// run command plug to command output,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void onClientData(ServerPlayer player, CompoundTag compound)
|
||||||
private static void onClientData(ServerPlayer player, FriendlyByteBuf data)
|
|
||||||
{
|
{
|
||||||
CompoundTag compound = data.readNbt();
|
|
||||||
if (compound == null) return;
|
|
||||||
for (String key: compound.getAllKeys())
|
for (String key: compound.getAllKeys())
|
||||||
{
|
{
|
||||||
if (dataHandlers.containsKey(key))
|
if (dataHandlers.containsKey(key))
|
||||||
@@ -174,9 +137,7 @@ public class ServerNetworkHandler
|
|||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
||||||
{
|
{
|
||||||
player.connection.send(make( output ->
|
player.connection.send(make(DataBuilder.create(player.server).withRule(rule)));
|
||||||
DataBuilder.create(player.server).withRule(rule).build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,9 +146,7 @@ public class ServerNetworkHandler
|
|||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : validCarpetPlayers)
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(make( output ->
|
player.connection.send(make(DataBuilder.create(player.server).withTickRate()));
|
||||||
DataBuilder.create(player.server).withTickRate().build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,9 +155,7 @@ public class ServerNetworkHandler
|
|||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : validCarpetPlayers)
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(make( output ->
|
player.connection.send(make(DataBuilder.create(player.server).withFrozenState()));
|
||||||
DataBuilder.create(player.server).withFrozenState().build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +164,7 @@ public class ServerNetworkHandler
|
|||||||
if(CarpetSettings.superSecretSetting) return;
|
if(CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : validCarpetPlayers)
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(make(output ->
|
player.connection.send(make(DataBuilder.create(player.server).withSuperHotState()));
|
||||||
DataBuilder.create(player.server).withSuperHotState().build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,9 +173,7 @@ public class ServerNetworkHandler
|
|||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : validCarpetPlayers)
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(make(output ->
|
player.connection.send(make(DataBuilder.create(player.server).withTickPlayerActiveTimeout()));
|
||||||
DataBuilder.create(player.server).withTickPlayerActiveTimeout().build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,9 +182,7 @@ public class ServerNetworkHandler
|
|||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : validCarpetPlayers)
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(make(output ->
|
player.connection.send(make(DataBuilder.create(player.server).withCustomNbt(command, data)));
|
||||||
DataBuilder.create(player.server).withCustomNbt(command, data).build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,13 +190,10 @@ public class ServerNetworkHandler
|
|||||||
{
|
{
|
||||||
if (isValidCarpetPlayer(player))
|
if (isValidCarpetPlayer(player))
|
||||||
{
|
{
|
||||||
player.connection.send(make(output ->
|
player.connection.send(make(DataBuilder.create(player.server).withCustomNbt(command, data)));
|
||||||
DataBuilder.create(player.server).withCustomNbt(command, data).build(output)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void onPlayerLoggedOut(ServerPlayer player)
|
public static void onPlayerLoggedOut(ServerPlayer player)
|
||||||
{
|
{
|
||||||
validCarpetPlayers.remove(player);
|
validCarpetPlayers.remove(player);
|
||||||
@@ -338,12 +286,9 @@ public class ServerNetworkHandler
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build(FriendlyByteBuf packetBuf)
|
private CarpetClient.CarpetPayload build()
|
||||||
{
|
{
|
||||||
packetBuf.writeVarInt(CarpetClient.DATA);
|
return new CarpetClient.CarpetPayload(CarpetClient.DATA, tag);
|
||||||
packetBuf.writeNbt(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user