Cleanup custom payload TODOs (#673)
This commit is contained in:
parent
876cf34761
commit
8ed4ae1b3e
|
@ -1,6 +1,5 @@
|
||||||
package io.izzel.arclight.common.mixin.core.network;
|
package io.izzel.arclight.common.mixin.core.network;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.mojang.brigadier.ParseResults;
|
import com.mojang.brigadier.ParseResults;
|
||||||
import io.izzel.arclight.common.bridge.core.entity.EntityBridge;
|
import io.izzel.arclight.common.bridge.core.entity.EntityBridge;
|
||||||
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
|
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
|
||||||
|
@ -78,6 +77,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.HitResult;
|
import net.minecraft.world.phys.HitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
|
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -138,6 +138,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -199,11 +200,9 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB
|
||||||
@Shadow protected abstract CompletableFuture<FilteredText> filterTextPacket(String p_243213_);
|
@Shadow protected abstract CompletableFuture<FilteredText> filterTextPacket(String p_243213_);
|
||||||
@Shadow protected abstract ParseResults<CommandSourceStack> parseCommand(String p_242938_);
|
@Shadow protected abstract ParseResults<CommandSourceStack> parseCommand(String p_242938_);
|
||||||
@Shadow protected abstract Map<String, PlayerChatMessage> collectSignedArguments(ServerboundChatCommandPacket p_242876_, PreviewableCommand<?> p_242848_);
|
@Shadow protected abstract Map<String, PlayerChatMessage> collectSignedArguments(ServerboundChatCommandPacket p_242876_, PreviewableCommand<?> p_242848_);
|
||||||
|
@Shadow protected abstract void detectRateSpam();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
@Shadow
|
|
||||||
protected abstract void detectRateSpam();
|
|
||||||
|
|
||||||
private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
|
private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
|
||||||
private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
|
private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
|
||||||
private CraftServer cserver;
|
private CraftServer cserver;
|
||||||
|
@ -1806,48 +1805,51 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB
|
||||||
private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register");
|
private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register");
|
||||||
private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister");
|
private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister");
|
||||||
|
|
||||||
// TODO FIXME handle custom payload on main thread
|
@Inject(method = "handleCustomPayload", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/network/ICustomPacket;Lnet/minecraft/network/Connection;)Z"))
|
||||||
@Inject(method = "handleCustomPayload", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/network/ICustomPacket;Lnet/minecraft/network/Connection;)Z"))
|
|
||||||
private void arclight$customPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci) {
|
private void arclight$customPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci) {
|
||||||
if (packet.identifier.equals(CUSTOM_REGISTER)) {
|
var readerIndex = packet.data.readerIndex();
|
||||||
try {
|
var buf = new byte[packet.data.readableBytes()];
|
||||||
String channels = packet.data.toString(Charsets.UTF_8);
|
packet.data.readBytes(buf);
|
||||||
for (String channel : channels.split("\0")) {
|
packet.data.readerIndex(readerIndex);
|
||||||
if (!StringUtil.isNullOrEmpty(channel)) {
|
ServerLifecycleHooks.getCurrentServer().executeIfPossible(() -> {
|
||||||
this.getCraftPlayer().addChannel(channel);
|
if (((MinecraftServerBridge) ServerLifecycleHooks.getCurrentServer()).bridge$hasStopped() || bridge$processedDisconnect()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.connection.isConnected()) {
|
||||||
|
if (packet.identifier.equals(CUSTOM_REGISTER)) {
|
||||||
|
try {
|
||||||
|
String channels = new String(buf, StandardCharsets.UTF_8);
|
||||||
|
for (String channel : channels.split("\0")) {
|
||||||
|
if (!StringUtil.isNullOrEmpty(channel)) {
|
||||||
|
this.getCraftPlayer().addChannel(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOGGER.error("Couldn't register custom payload", ex);
|
||||||
|
this.disconnect("Invalid payload REGISTER!");
|
||||||
|
}
|
||||||
|
} else if (packet.identifier.equals(CUSTOM_UNREGISTER)) {
|
||||||
|
try {
|
||||||
|
final String channels = new String(buf, StandardCharsets.UTF_8);
|
||||||
|
for (String channel : channels.split("\0")) {
|
||||||
|
if (!StringUtil.isNullOrEmpty(channel)) {
|
||||||
|
this.getCraftPlayer().removeChannel(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOGGER.error("Couldn't unregister custom payload", ex);
|
||||||
|
this.disconnect("Invalid payload UNREGISTER!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
this.cserver.getMessenger().dispatchIncomingMessage(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), packet.identifier.toString(), buf);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOGGER.error("Couldn't dispatch custom payload", ex);
|
||||||
|
this.disconnect("Invalid custom payload!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error("Couldn't register custom payload", ex);
|
|
||||||
this.disconnect("Invalid payload REGISTER!");
|
|
||||||
ci.cancel();
|
|
||||||
}
|
}
|
||||||
} else if (packet.identifier.equals(CUSTOM_UNREGISTER)) {
|
});
|
||||||
try {
|
|
||||||
final String channels = packet.data.toString(Charsets.UTF_8);
|
|
||||||
for (String channel : channels.split("\0")) {
|
|
||||||
if (!StringUtil.isNullOrEmpty(channel)) {
|
|
||||||
this.getCraftPlayer().removeChannel(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error("Couldn't unregister custom payload", ex);
|
|
||||||
this.disconnect("Invalid payload UNREGISTER!");
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int readerIndex = packet.data.readerIndex();
|
|
||||||
final byte[] data = new byte[packet.data.readableBytes()];
|
|
||||||
packet.data.readBytes(data);
|
|
||||||
this.cserver.getMessenger().dispatchIncomingMessage(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), packet.identifier.toString(), data);
|
|
||||||
packet.data.readerIndex(readerIndex);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error("Couldn't dispatch custom payload", ex);
|
|
||||||
this.disconnect("Invalid custom payload!");
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isDisconnected() {
|
public final boolean isDisconnected() {
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class PacketThreadUtilMixin {
|
||||||
@Overwrite
|
@Overwrite
|
||||||
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packetIn, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
|
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packetIn, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
|
||||||
if (!executor.isSameThread()) {
|
if (!executor.isSameThread()) {
|
||||||
executor.execute(() -> {
|
executor.executeIfPossible(() -> {
|
||||||
if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerGamePacketListenerImpl && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) {
|
if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerGamePacketListenerImpl && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user