mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Misc networking API cleanup + fixes (#3265)
This commit is contained in:
parent
11da534fdc
commit
839aeb4e2c
10 changed files with 15 additions and 153 deletions
|
@ -38,7 +38,6 @@ import net.fabricmc.fabric.impl.networking.NetworkingImpl;
|
|||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
|
||||
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientCommonNetworkHandlerAccessor;
|
||||
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientConfigurationNetworkHandlerAccessor;
|
||||
import net.fabricmc.fabric.mixin.networking.client.accessor.ClientLoginNetworkHandlerAccessor;
|
||||
|
||||
public final class ClientConfigurationNetworkAddon extends AbstractChanneledNetworkAddon<ClientConfigurationNetworking.ConfigurationChannelHandler> {
|
||||
private final ClientConfigurationNetworkHandler handler;
|
||||
|
@ -167,6 +166,6 @@ public final class ClientConfigurationNetworkAddon extends AbstractChanneledNetw
|
|||
}
|
||||
|
||||
public ChannelInfoHolder getChannelInfoHolder() {
|
||||
return (ChannelInfoHolder) ((ClientLoginNetworkHandlerAccessor) handler).getConnection();
|
||||
return (ChannelInfoHolder) ((ClientCommonNetworkHandlerAccessor) handler).getConnection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ import net.fabricmc.fabric.impl.networking.CommonVersionPayload;
|
|||
import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry;
|
||||
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
|
||||
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
|
||||
import net.fabricmc.fabric.impl.networking.payload.FabricPacketPayload;
|
||||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
|
||||
import net.fabricmc.fabric.mixin.networking.client.accessor.ConnectScreenAccessor;
|
||||
import net.fabricmc.fabric.mixin.networking.client.accessor.MinecraftClientAccessor;
|
||||
|
@ -79,13 +78,9 @@ public final class ClientNetworkingImpl {
|
|||
Objects.requireNonNull(packet, "Packet cannot be null");
|
||||
Objects.requireNonNull(packet.getType(), "Packet#getType cannot return null");
|
||||
|
||||
if (NetworkingImpl.WRITE_FABRIC_PACKET_CALLING_THREAD) {
|
||||
PacketByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
return createC2SPacket(packet.getType().getId(), buf);
|
||||
}
|
||||
|
||||
return new CustomPayloadC2SPacket(new FabricPacketPayload(packet));
|
||||
PacketByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
return createC2SPacket(packet.getType().getId(), buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.networking;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.login.LoginQueryRequestPayload;
|
||||
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufLoginQueryRequestPayload;
|
||||
import net.fabricmc.fabric.impl.networking.payload.PayloadHelper;
|
||||
|
||||
public class LoginQueryRequestS2CPacketFactory {
|
||||
public static LoginQueryRequestS2CPacket create(PacketByteBuf buf) {
|
||||
int queryId = buf.readVarInt();
|
||||
Identifier identifier = buf.readIdentifier();
|
||||
return new LoginQueryRequestS2CPacket(queryId, readPayload(identifier, buf));
|
||||
}
|
||||
|
||||
private static LoginQueryRequestPayload readPayload(Identifier id, PacketByteBuf buf) {
|
||||
return new PacketByteBufLoginQueryRequestPayload(id, PayloadHelper.read(buf));
|
||||
}
|
||||
}
|
|
@ -25,12 +25,6 @@ public final class NetworkingImpl {
|
|||
public static final String MOD_ID = "fabric-networking-api-v1";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
/**
|
||||
* When enabled the fabric packet is written to the {@link net.minecraft.network.PacketByteBuf} on the calling thread.
|
||||
* This is not enabled by default as it currently causes issues in single player.
|
||||
*/
|
||||
public static final boolean WRITE_FABRIC_PACKET_CALLING_THREAD = Boolean.parseBoolean(System.getProperty("fabric-api.networking.write-fabric-packet-calling-thread", "true"));
|
||||
|
||||
/**
|
||||
* Id of packet used to register supported channels.
|
||||
*/
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.networking.payload;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
|
||||
|
||||
public record FabricPacketPayload(FabricPacket fabricPacket) implements CustomPayload {
|
||||
@Override
|
||||
public void write(PacketByteBuf buf) {
|
||||
fabricPacket.write(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier id() {
|
||||
return fabricPacket.getType().getId();
|
||||
}
|
||||
}
|
|
@ -39,7 +39,6 @@ import net.fabricmc.fabric.impl.networking.ChannelInfoHolder;
|
|||
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
|
||||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
|
||||
import net.fabricmc.fabric.mixin.networking.accessor.ServerCommonNetworkHandlerAccessor;
|
||||
import net.fabricmc.fabric.mixin.networking.accessor.ServerLoginNetworkHandlerAccessor;
|
||||
|
||||
public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetworkAddon<ServerConfigurationNetworking.ConfigurationChannelHandler> {
|
||||
private final ServerConfigurationNetworkHandler handler;
|
||||
|
@ -199,6 +198,6 @@ public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetw
|
|||
}
|
||||
|
||||
public ChannelInfoHolder getChannelInfoHolder() {
|
||||
return (ChannelInfoHolder) ((ServerLoginNetworkHandlerAccessor) handler).getConnection();
|
||||
return (ChannelInfoHolder) ((ServerCommonNetworkHandlerAccessor) handler).getConnection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
|
|||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.fabric.impl.networking.GlobalReceiverRegistry;
|
||||
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
|
||||
import net.fabricmc.fabric.impl.networking.NetworkingImpl;
|
||||
import net.fabricmc.fabric.impl.networking.payload.FabricPacketPayload;
|
||||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufPayload;
|
||||
|
||||
public final class ServerNetworkingImpl {
|
||||
|
@ -64,12 +62,8 @@ public final class ServerNetworkingImpl {
|
|||
Objects.requireNonNull(packet, "Packet cannot be null");
|
||||
Objects.requireNonNull(packet.getType(), "Packet#getType cannot return null");
|
||||
|
||||
if (NetworkingImpl.WRITE_FABRIC_PACKET_CALLING_THREAD) {
|
||||
PacketByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
return createC2SPacket(packet.getType().getId(), buf);
|
||||
}
|
||||
|
||||
return new CustomPayloadS2CPacket(new FabricPacketPayload(packet));
|
||||
PacketByteBuf buf = PacketByteBufs.create();
|
||||
packet.write(buf);
|
||||
return createC2SPacket(packet.getType().getId(), buf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,17 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.login.LoginQueryRequestPayload;
|
||||
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.login.UnknownLoginQueryRequestPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.impl.networking.payload.PacketByteBufLoginQueryRequestPayload;
|
||||
import net.fabricmc.fabric.impl.networking.payload.PayloadHelper;
|
||||
|
||||
@Mixin(LoginQueryRequestS2CPacket.class)
|
||||
public class LoginQueryRequestS2CPacketMixin {
|
||||
@Inject(method = "readPayload", at = @At("HEAD"))
|
||||
private static void readPayload(Identifier id, PacketByteBuf buf, CallbackInfoReturnable<UnknownLoginQueryRequestPayload> cir) {
|
||||
throw new IllegalStateException("Must use LoginQueryRequestS2CPacketFactory");
|
||||
@Inject(method = "readPayload", at = @At("HEAD"), cancellable = true)
|
||||
private static void readPayload(Identifier id, PacketByteBuf buf, CallbackInfoReturnable<LoginQueryRequestPayload> cir) {
|
||||
cir.setReturnValue(new PacketByteBufLoginQueryRequestPayload(id, PayloadHelper.read(buf)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.networking;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.network.NetworkState;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.listener.ClientLoginPacketListener;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket;
|
||||
|
||||
import net.fabricmc.fabric.impl.networking.LoginQueryRequestS2CPacketFactory;
|
||||
|
||||
@Mixin(NetworkState.InternalPacketHandler.class)
|
||||
public abstract class NetworkStateInternalPacketHandlerMixin<T extends ClientLoginPacketListener> {
|
||||
@Unique
|
||||
private static final Function<PacketByteBuf, LoginQueryRequestS2CPacket> LOGIN_QUERY_REQUEST_FACTORY = LoginQueryRequestS2CPacketFactory::create;
|
||||
|
||||
@Shadow public abstract <P extends Packet<? super T>> NetworkState.InternalPacketHandler<T> register(Class<P> type, Function<PacketByteBuf, P> packetFactory);
|
||||
|
||||
@Inject(method = "register", at = @At("HEAD"), cancellable = true)
|
||||
private <P extends Packet<? super T>> void register(Class<P> type, Function<PacketByteBuf, P> packetFactory, CallbackInfoReturnable<NetworkState.InternalPacketHandler<T>> cir) {
|
||||
if (type == LoginQueryRequestS2CPacket.class && packetFactory != LOGIN_QUERY_REQUEST_FACTORY) {
|
||||
cir.setReturnValue(register(LoginQueryRequestS2CPacket.class, LOGIN_QUERY_REQUEST_FACTORY));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
"EntityTrackerEntryMixin",
|
||||
"LoginQueryRequestS2CPacketMixin",
|
||||
"LoginQueryResponseC2SPacketMixin",
|
||||
"NetworkStateInternalPacketHandlerMixin",
|
||||
"PlayerManagerMixin",
|
||||
"ServerCommonNetworkHandlerMixin",
|
||||
"ServerConfigurationNetworkHandlerMixin",
|
||||
|
|
Loading…
Reference in a new issue