Fixed small bugs / problems
This commit is contained in:
parent
4ee09e5a13
commit
9b5a368ed1
@ -122,6 +122,12 @@ public class Ezcheat implements ModInitializer {
|
||||
|
||||
if (!bad.isEmpty()) {
|
||||
String msg = "Unallowed mods: " + String.join(", ", bad);
|
||||
|
||||
// Make sure msg is not too long. If it is, truncate it.
|
||||
if (msg.length() > 256) {
|
||||
msg = msg.substring(0, 256) + "...";
|
||||
}
|
||||
|
||||
player.networkHandler.disconnect(Text.literal(msg));
|
||||
LOGGER.info("Kicked {} for unallowed mods: {}", player.getName().getString(), bad);
|
||||
} else {
|
||||
|
||||
@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.metadata.ModOrigin;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -21,7 +22,11 @@ public class EzcheatClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
|
||||
Ezcheat.LOGGER.info("Joined server: {}", handler.getConnection().getAddress());
|
||||
Ezcheat.LOGGER.info("Is Singleplayer: {}", client.isInSingleplayer());
|
||||
if (!client.isInSingleplayer()) {
|
||||
|
||||
Ezcheat.LOGGER.info("Sending mod hashes to server");
|
||||
this.sendHashes();
|
||||
}
|
||||
});
|
||||
@ -38,22 +43,28 @@ public class EzcheatClient implements ClientModInitializer {
|
||||
Map<String, String> hashes = new HashMap<>();
|
||||
for (var mod : FabricLoader.getInstance().getAllMods()) {
|
||||
try {
|
||||
Path path = null;
|
||||
var paths = mod.getOrigin().getPaths();
|
||||
for (Path p : paths) {
|
||||
var origin = mod.getOrigin();
|
||||
// Skip nested origins
|
||||
if (origin.getKind() == ModOrigin.Kind.NESTED) {
|
||||
Ezcheat.LOGGER.debug("Skipping nested mod {}", mod.getMetadata().getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
Path modFile = null;
|
||||
for (Path p : origin.getPaths()) {
|
||||
if (Files.isRegularFile(p)) {
|
||||
path = p;
|
||||
modFile = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
if (modFile == null) {
|
||||
Ezcheat.LOGGER.debug("Skipping mod {}: No valid path", mod.getMetadata().getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path.startsWith(modsDir)) {
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
if (modFile.startsWith(modsDir)) {
|
||||
try (InputStream in = Files.newInputStream(modFile)) {
|
||||
hashes.put(mod.getMetadata().getId(), DigestUtils.sha256Hex(in));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user