Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rotgruengelb committed Aug 20, 2023
1 parent 82bad05 commit bdd68a7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 86 deletions.
2 changes: 0 additions & 2 deletions src/main/java/net/rotgruengelb/clientcatcher/Api.java
@@ -1,8 +1,6 @@
package net.rotgruengelb.clientcatcher;

import com.mojang.authlib.GameProfile;
import net.minecraft.block.BambooBlock;
import net.minecraft.block.CactusBlock;

public class Api {
public static String getPlayerBrand(GameProfile gameProfile) {
Expand Down
126 changes: 60 additions & 66 deletions src/main/java/net/rotgruengelb/clientcatcher/ClientCatcher.java
@@ -1,95 +1,89 @@
package net.rotgruengelb.clientcatcher;

import com.mojang.authlib.GameProfile;

import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.api.DedicatedServerModInitializer;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;

import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.entity.EntityType;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.*;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import net.rotgruengelb.clientcatcher.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.UUID;
import java.util.function.Predicate;

import static net.minecraft.server.command.CommandManager.*;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

public class ClientCatcher implements DedicatedServerModInitializer {
public static final String MODID = "clientcatcher";
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);
public static final String MODID = "clientcatcher";
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

public static HashMap<UUID, String> clientBrands = new HashMap<>();
public static HashMap<UUID, String> clientBrands = new HashMap<>();

@Override
public void onInitializeServer() {
@Override
public void onInitializeServer() {

ServerPlayNetworking.registerGlobalReceiver(CustomPayloadC2SPacket.BRAND, (server, player, handler, buf, responseSender) -> {
try {
var brand = buf.readString(1024).strip().trim();
if (!brand.isBlank()) {
clientBrands.put(player.getUuid(), brand);
return;
}
LOGGER.info("{} brand: {}", player, brand);
} catch (Exception error) {
LOGGER.error("Error", error);
}
if (player != null) {
clientBrands.put(player.getUuid(), "unknown");
}
});
ServerPlayNetworking.registerGlobalReceiver(CustomPayloadC2SPacket.BRAND, (server, player, handler, buf, responseSender) -> {
try {
var brand = buf.readString(1024).strip().trim();
if (!brand.isBlank()) {
clientBrands.put(player.getUuid(), brand);
return;
}
LOGGER.info("{} brand: {}", player, brand);
} catch (Exception error) {
LOGGER.error("Error", error);
}
if (player != null) {
clientBrands.put(player.getUuid(), "unknown");
}
});

ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
try {
clientBrands.remove(handler.player.getUuid());
} catch (Exception error) {
LOGGER.error("Error", error);
}
});
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
try {
clientBrands.remove(handler.player.getUuid());
} catch (Exception error) {
LOGGER.error("Error", error);
}
});

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
if (environment.dedicated) {
dispatcher.register(literal("clientcatcher")
.requires(Permissions.require("clientcatcher.command",4))
.then(literal("client")
.requires(Permissions.require("clientcatcher.command.client",4))
.then(argument("player", GameProfileArgumentType.gameProfile()).executes(ctx -> {
for (GameProfile profile : GameProfileArgumentType.getProfileArgument(ctx, "player")) {
String brand = Api.getPlayerBrand(profile);
var brandText = Text.literal(brand);
brandText.setStyle(brandText.getStyle()
.withColor(brand.equals("vanilla") ? Formatting.GREEN : Formatting.YELLOW)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Text.literal("WARNING: Modded clients can spoof/change their client brand!")
)));
var profileText = Text.literal(profile.getName());
profileText.setStyle(profileText.getStyle()
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_ENTITY, new HoverEvent.EntityContent(EntityType.PLAYER, profile.getId(), Text.literal(profile.getName())))
));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
if (environment.dedicated) {
dispatcher.register(literal("clientcatcher")
.requires(Permissions.require("clientcatcher.command", 4))
.then(literal("client")
.requires(Permissions.require("clientcatcher.command.client", 4))
.then(argument("player", GameProfileArgumentType.gameProfile()).executes(ctx -> {
for (GameProfile profile : GameProfileArgumentType.getProfileArgument(ctx, "player")) {
String brand = Api.getPlayerBrand(profile);
var brandText = Text.literal(brand);
brandText.setStyle(brandText.getStyle()
.withColor(brand.equals("vanilla") ? Formatting.GREEN : Formatting.YELLOW)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Text.literal("WARNING: Modded clients can spoof/change their client brand!")
)));
var profileText = Text.literal(profile.getName());
profileText.setStyle(profileText.getStyle()
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_ENTITY, new HoverEvent.EntityContent(EntityType.PLAYER, profile.getId(), Text.literal(profile.getName())))
));

Text response = Text.literal("").append(profileText).append(Text.of(" brand is: ")).append(brandText);
ctx.getSource().sendFeedback(() -> response, true);
}
Text response = Text.literal("").append(profileText).append(Text.of(" brand is: ")).append(brandText);
ctx.getSource().sendFeedback(() -> response, true);
}

return SINGLE_SUCCESS;
}))));
}
});
}
return SINGLE_SUCCESS;
}))));
}
});
}
}
18 changes: 0 additions & 18 deletions src/main/java/net/rotgruengelb/clientcatcher/util/Util.java

This file was deleted.

0 comments on commit bdd68a7

Please sign in to comment.