Skip to content

Commit

Permalink
Denied custom packages from C2S to disable clients' any possible inte…
Browse files Browse the repository at this point in the history
…raction with 3rd party mods. Such as FTB Teams/Claims.
  • Loading branch information
TheDoctorOne committed Sep 3, 2024
1 parent eff5b5f commit f1cadd1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bin/
# fabric

run/
runClient/

# java

Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ loom {
}
}

runs {
client {
runDir = "runClient"
}
}

}

dependencies {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/net/mahmutkocas/mixin/ClientConnectionMixin.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
package net.mahmutkocas.mixin;

import net.mahmutkocas.PlayerStateHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfo;

@Mixin(ClientConnection.class)
public class ClientConnectionMixin {

@Shadow @Final private static Logger LOGGER;

@Inject(at = @At("HEAD"), method = "handlePacket", cancellable = true)
private static <T extends PacketListener> void handlePacket(Packet<T> packet, PacketListener listener, CallbackInfo ci) {
if(!(listener instanceof ServerPlayNetworkHandler)) {
return;
}
ServerPlayNetworkHandler handler = (ServerPlayNetworkHandler) listener;

LOGGER.info("Packet class" + packet.getClass().getName());
if(packet instanceof CustomPayloadC2SPacket) {
checkLock(handler.getPlayer().getUuidAsString(), ci);
if(ci.isCancelled()) {
CustomPayloadC2SPacket pack = (CustomPayloadC2SPacket) packet;
LOGGER.info("Denied packet: " + pack.getChannel() + " for Player: " + handler.getPlayer().getUuidAsString());
}
}
}


@Unique
private static void checkLock(String uuid, CallbackInfo ci) {
if (!PlayerStateHandler.INSTANCE.isLocked(uuid)) {
return;
}
ci.cancel();
}
}

0 comments on commit f1cadd1

Please sign in to comment.