Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel Detection & Management #36

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.option.KeyBinding;
Expand Down Expand Up @@ -128,5 +129,8 @@ public void onInitialize() {
while (paradiseCommandOpener.wasPressed())
MinecraftClient.getInstance().setScreen(new ChatScreen(ParadiseClient_Fabric.commandManager.prefix));
});
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
ChannelListener.clearChannels();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void init() {
register(new ECBCommand(minecraftClient));
register(new SignedVelocityCommand(minecraftClient));
register(new DumpCommand(minecraftClient));
register(new ChannelCommand(minecraftClient));


// Register this command at the very end so it registers all commands in it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.spigotrce.paradiseclientfabric.command.impl;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.github.spigotrce.paradiseclientfabric.command.Command;
import io.github.spigotrce.paradiseclientfabric.listener.ChannelListener;
import io.github.spigotrce.paradiseclientfabric.Helper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandSource;

/**
* Command to display and manage detected channels.
*/
public class ChannelCommand extends Command {

public ChannelCommand(MinecraftClient minecraftClient) {
super("channels", "Displays and manages detected channels", minecraftClient);
}

@Override
public LiteralArgumentBuilder<CommandSource> build() {
return LiteralArgumentBuilder.<CommandSource>literal(getName())
.executes(context -> {
// Display the list of detected channels
if (ChannelListener.getDetectedChannels().isEmpty()) {
Helper.printChatMessage("&cNo channels detected at the moment.");
} else {
Helper.printChatMessage("&bList of detected channels:");
for (String channel : ChannelListener.getDetectedChannels()) {
Helper.printChatMessage("&f- &d" + channel);
}
}
return SINGLE_SUCCESS;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,43 @@
import io.github.spigotrce.eventbus.event.listener.Listener;
import io.github.spigotrce.paradiseclientfabric.Constants;
import io.github.spigotrce.paradiseclientfabric.Helper;
import io.github.spigotrce.paradiseclientfabric.ParadiseClient_Fabric;
import io.github.spigotrce.paradiseclientfabric.event.channel.PluginMessageEvent;
import net.minecraft.network.PacketByteBuf;

import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class ChannelListener implements Listener {
private static final Set<String> detectedChannels = new HashSet<>(); // Stores detected channels

@SuppressWarnings("unused")
@EventHandler
public void onChannelRegister(PluginMessageEvent event) {
String channelName = event.getChannel();
PacketByteBuf buf = event.getBuf();

try {
if (Objects.equals(channelName, "minecraft:register") || Objects.equals(channelName, "REGISTER")) // 1.13 channel or 1.8 channel
if (Objects.equals(channelName, "minecraft:register") || Objects.equals(channelName, "REGISTER")) {
for (String splitted : buf.toString(Charset.defaultCharset()).split("\000")) {
Helper.printChatMessage("&fChannel: &" + (ParadiseClient_Fabric.networkMod.getRegisteredChannelsByName().contains(splitted) ? "c " : "d ") + splitted);
if (ParadiseClient_Fabric.networkMod.getRegisteredChannelsByName().contains(splitted)) {
Helper.showNotification("Exploit found!", splitted);
}
detectedChannels.add(splitted); // Adds the channel to the list
Helper.printChatMessage("&fChannel: &d" + splitted);
}
else
Helper.printChatMessage("&fChannel: &d" + channelName + " &fData: &d" + buf.toString(Charset.defaultCharset()));
} else {
detectedChannels.add(channelName);
Helper.printChatMessage("&fChannel: &d" + channelName);
}
} catch (Exception e) {
Helper.printChatMessage("&4Error handling listener for payload for channel: " + channelName + " " + e.getMessage());
Constants.LOGGER.error("&4Error handling listener for channel: {} {}", channelName, e);

Helper.printChatMessage("&4Error handling listener for channel: " + channelName + " " + e.getMessage());
Constants.LOGGER.error("&4Error on channel: {} {}", channelName, e);
}
}

public static Set<String> getDetectedChannels() {
return detectedChannels;
}
public static void clearChannels() {
detectedChannels.clear();
}
}