Don't track fake player network addons (#3977)

* Don't track fake player network addons

* Review feedback
This commit is contained in:
modmuss 2024-08-04 13:52:41 +01:00 committed by GitHub
parent c5e2b5c62d
commit ba9dae065f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 4 deletions

View file

@ -1,3 +1,3 @@
version = getSubprojectVersion(project) version = getSubprojectVersion(project)
moduleDependencies(project, ['fabric-api-base']) moduleDependencies(project, ['fabric-api-base', 'fabric-networking-api-v1'])

View file

@ -26,7 +26,9 @@ import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
public class FakePlayerNetworkHandler extends ServerPlayNetworkHandler { import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
public final class FakePlayerNetworkHandler extends ServerPlayNetworkHandler implements UntrackedNetworkHandler {
private static final ClientConnection FAKE_CONNECTION = new FakeClientConnection(); private static final ClientConnection FAKE_CONNECTION = new FakeClientConnection();
public FakePlayerNetworkHandler(ServerPlayerEntity player) { public FakePlayerNetworkHandler(ServerPlayerEntity player) {

View file

@ -18,6 +18,7 @@
"depends": { "depends": {
"fabricloader": ">=0.15.11", "fabricloader": ">=0.15.11",
"fabric-api-base": "*", "fabric-api-base": "*",
"fabric-networking-api-v1": "*",
"minecraft": ">=1.15-alpha.19.37.a" "minecraft": ">=1.15-alpha.19.37.a"
}, },
"entrypoints": { "entrypoints": {

View file

@ -0,0 +1,21 @@
/*
* 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;
// An internal marker interface used by the fake player API to prevent the network addon from being tracked.
public interface UntrackedNetworkHandler {
}

View file

@ -30,6 +30,7 @@ import net.minecraft.server.network.ServerCommonNetworkHandler;
import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions; import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.UntrackedNetworkHandler;
import net.fabricmc.fabric.impl.networking.server.ServerPlayNetworkAddon; import net.fabricmc.fabric.impl.networking.server.ServerPlayNetworkAddon;
// We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues // We want to apply a bit earlier than other mods which may not use us in order to prevent refCount issues
@ -45,9 +46,12 @@ abstract class ServerPlayNetworkHandlerMixin extends ServerCommonNetworkHandler
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
private void initAddon(CallbackInfo ci) { private void initAddon(CallbackInfo ci) {
this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, connection, server); this.addon = new ServerPlayNetworkAddon((ServerPlayNetworkHandler) (Object) this, connection, server);
if (!(this instanceof UntrackedNetworkHandler)) {
// A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field // A bit of a hack but it allows the field above to be set in case someone registers handlers during INIT event which refers to said field
this.addon.lateInit(); this.addon.lateInit();
} }
}
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void handleCustomPayloadReceivedAsync(CustomPayloadC2SPacket packet, CallbackInfo ci) { private void handleCustomPayloadReceivedAsync(CustomPayloadC2SPacket packet, CallbackInfo ci) {