Skip to content

Commit

Permalink
Nuke networking channel
Browse files Browse the repository at this point in the history
Closes #297, closes #255
  • Loading branch information
Aizistral committed Nov 17, 2022
1 parent e7b601d commit 82d46ed
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 105 deletions.
15 changes: 0 additions & 15 deletions src/main/java/com/aizistral/nochatreports/NoChatReports.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aizistral.nochatreports;

import com.aizistral.nochatreports.config.NCRConfig;
import com.aizistral.nochatreports.network.ServerChannelHandler;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
Expand All @@ -22,27 +21,13 @@

public final class NoChatReports implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger();
public static final ResourceLocation CHANNEL = new ResourceLocation("nochatreports", "sync");

@Override
public void onInitialize() {
LOGGER.info("KONNICHIWA ZA WARUDO!");
LOGGER.info("Default JVM text encoding is: " + Charset.defaultCharset().displayName());

ServerPlayNetworking.registerGlobalReceiver(CHANNEL, ServerChannelHandler.INSTANCE);
ServerPlayConnectionEvents.JOIN.register(this::onPlayReady);
NCRConfig.load();
}

private void onPlayReady(ServerGamePacketListenerImpl handler, PacketSender sender, MinecraftServer server) {
server.execute(() -> {
if (server.isSingleplayerOwner(handler.player.getGameProfile()))
return;

if (NCRConfig.getCommon().demandOnClient() && !ServerPlayNetworking.canSend(handler, CHANNEL)) {
handler.disconnect(Component.literal(NCRConfig.getCommon().demandOnClientMessage()));
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.aizistral.nochatreports.core.ServerDataExtension;
import com.aizistral.nochatreports.core.ServerSafetyLevel;
import com.aizistral.nochatreports.core.ServerSafetyState;
import com.aizistral.nochatreports.network.ClientChannelHandler;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -27,10 +26,6 @@ public final class NoChatReportsClient implements ClientModInitializer {
public void onInitializeClient() {
NoChatReports.LOGGER.info("Client initialization...");

if (NCRConfig.getClient().enableMod()) {
ClientChannelHandler.INSTANCE.register();
}

ClientPlayConnectionEvents.JOIN.register(this::onPlayReady);
ClientPlayConnectionEvents.DISCONNECT.register(this::onDisconnect);
}
Expand All @@ -52,12 +47,9 @@ private void onPlayReady(ClientPacketListener handler, PacketSender sender, Mine

client.execute(() -> {
if (!client.isLocalServer()) {
boolean canSend = ClientPlayNetworking.canSend(NoChatReports.CHANNEL);

if (ServerSafetyState.isOnRealms()) {
// NO-OP
} else if (canSend) {
ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
} else if (client.getCurrentServer() instanceof ServerDataExtension ext &&
ext.preventsChatReports()) {
ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
Expand All @@ -76,7 +68,7 @@ private void onPlayReady(ClientPacketListener handler, PacketSender sender, Mine
NoChatReports.LOGGER.info("Sucessfully connected to server, safety state: {}", ServerSafetyState.getCurrent());
}

if (NCRConfig.getClient().demandOnServer() && !ClientPlayNetworking.canSend(NoChatReports.CHANNEL)) {
if (NCRConfig.getClient().demandOnServer() && ServerSafetyState.getCurrent() != ServerSafetyLevel.SECURE) {
handler.getConnection().disconnect(Component.translatable("disconnect.nochatreports.client"));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.aizistral.nochatreports.core.ServerSafetyState;
import com.aizistral.nochatreports.gui.AdvancedImageButton;
import com.aizistral.nochatreports.gui.AdvancedTooltip;
import com.aizistral.nochatreports.network.ClientChannelHandler;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
Expand Down Expand Up @@ -70,10 +69,8 @@ private void onInit(CallbackInfo info) {

if (enabled) {
((ImageButton)btn).xTexStart = 0;
ClientChannelHandler.INSTANCE.register();
} else {
((ImageButton)btn).xTexStart = 20;
ClientChannelHandler.INSTANCE.unregister();
}

ServerSafetyState.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.aizistral.nochatreports.config.NCRConfig;

import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerGamePacketListener;
import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket;
import net.minecraft.server.network.ServerGamePacketListenerImpl;

@Mixin(ServerboundChatSessionUpdatePacket.class)
public class MixinServerboundChatSessionUpdatePacket {
Expand All @@ -18,6 +22,14 @@ public class MixinServerboundChatSessionUpdatePacket {

@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
private void onHandle(ServerGamePacketListener listener, CallbackInfo info) {
var impl = (ServerGamePacketListenerImpl) listener;

if (!impl.getPlayer().getServer().isSingleplayerOwner(impl.getPlayer().getGameProfile())) {
if (NCRConfig.getCommon().demandOnClient()) {
impl.disconnect(Component.literal(NCRConfig.getCommon().demandOnClientMessage()));
}
}

info.cancel();
}

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 82d46ed

Please sign in to comment.