Skip to content

Commit

Permalink
1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed May 5, 2024
1 parent 2f5440e commit 33e9224
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Build
run: ./gradlew build
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ subprojects {
plugins.apply("java-library")

group = "ru.bk.oharass.freedomchat"
version = "1.5.2"
version = "1.6.0"
description = "Liberate your server from the chat-reporting bourgeoisie! Disable chat signing server-side."

tasks {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down
13 changes: 6 additions & 7 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("dev.architectury.loom") version "1.5-SNAPSHOT"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("dev.architectury.loom") version "1.6-SNAPSHOT"
id("io.github.goooler.shadow") version "8.1.7"
}

val shade: Configuration by configurations.creating
Expand All @@ -13,11 +13,10 @@ repositories {
}

dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = "1.20.4")
mappings(group = "net.fabricmc", name = "yarn", version = "1.20.4+build.3", classifier = "v2")
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.15.3")
modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.92.0+1.20.4")
modImplementation(include(group = "net.kyori", name = "adventure-platform-fabric", version = "5.11.0"))
minecraft(group = "com.mojang", name = "minecraft", version = "1.20.6")
mappings(group = "net.fabricmc", name = "yarn", version = "1.20.6+build.1", classifier = "v2")
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = "0.15.11")
modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = "0.97.8+1.20.6")
shade(implementation(group = "org.spongepowered", name = "configurate-yaml", version = "4.1.2"))
}

Expand Down
16 changes: 7 additions & 9 deletions fabric/src/main/java/ru/bk/oharass/freedomchat/FreedomChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class FreedomChat implements ModInitializer {
public void onInitialize() {
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
this.server = server;
if (!Boolean.getBoolean("im.evan.freedomchat.bypassprotocolcheck") && SharedConstants.getProtocolVersion() != 765) {
logger.warn("This version of FreedomChat only supports protocol version 765 (1.20.4). Please use the appropriate version of FreedomChat for your server");
if (!Boolean.getBoolean("im.evan.freedomchat.bypassprotocolcheck") && SharedConstants.getProtocolVersion() != 766) {
logger.warn("This version of FreedomChat only supports protocol version 766 (1.20.6). Please use the appropriate version of FreedomChat for your server");
logger.warn("If you know what you are doing, set the im.evan.freedomchat.bypassprotocolcheck system property to true to bypass this check");
return;
}
Expand All @@ -33,21 +33,19 @@ public void onInitialize() {
.path(configPath)
.nodeStyle(NodeStyle.BLOCK)
.build();
CommentedConfigurationNode config;
final CommentedConfigurationNode config;
try {
config = loader.load();
final boolean rewriteChat = config.node("rewrite-chat").getBoolean(true);
final boolean claimSecureChatEnforced = config.node("claim-secure-chat-enforced").getBoolean(true);
final boolean sendPreventsChatReportsToClient = config.node("send-prevents-chat-reports-to-client").getBoolean(false);
final boolean noChatReports = config.node("send-prevents-chat-reports-to-client").getBoolean(false);
loader.save(config);

handler = new FreedomHandler(
this,
rewriteChat,
claimSecureChatEnforced,
sendPreventsChatReportsToClient,
this
noChatReports
);
} catch (ConfigurateException e) {
} catch (final ConfigurateException e) {
logger.error("An error occurred while loading this configuration: " + e.getMessage());
if (e.getCause() != null) {
e.getCause().printStackTrace();
Expand Down
84 changes: 34 additions & 50 deletions fabric/src/main/java/ru/bk/oharass/freedomchat/FreedomHandler.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,83 @@
package ru.bk.oharass.freedomchat;

import com.google.gson.JsonObject;
import com.mojang.serialization.JsonOps;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.EncoderException;
import io.netty.handler.codec.MessageToByteEncoder;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.ServerMetadataS2CPacket;
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
import net.minecraft.network.state.PlayStateFactories;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.ServerMetadata;
import net.minecraft.text.Text;
import ru.bk.oharass.freedomchat.rewrite.CustomServerMetadata;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

@ChannelHandler.Sharable
public class FreedomHandler extends MessageToByteEncoder<Packet<?>> {

private static final int STATUS_RESPONSE_PACKET_ID = 0x00;
private final PacketCodec<ByteBuf, Packet<? super ClientPlayPacketListener>> s2cPlayPacketCodec;
private final boolean rewriteChat;
private final boolean claimSecureChatEnforced;
private final boolean noChatReports;
private final FreedomChat freedom;

public FreedomHandler(boolean rewriteChat, boolean claimSecureChatEnforced, boolean noChatReports, final FreedomChat freedom) {
public FreedomHandler(final FreedomChat freedom, final boolean rewriteChat, final boolean noChatReports) {
final DynamicRegistryManager registryAccess = freedom.getServer().getRegistryManager();
final Function<ByteBuf, RegistryByteBuf> bufRegistryAccess = RegistryByteBuf.makeFactory(registryAccess);
this.s2cPlayPacketCodec = PlayStateFactories.S2C.bind(bufRegistryAccess).codec();
this.rewriteChat = rewriteChat;
this.claimSecureChatEnforced = claimSecureChatEnforced;
this.noChatReports = noChatReports;
this.freedom = freedom;
}

@Override
public boolean acceptOutboundMessage(Object msg) {
public boolean acceptOutboundMessage(final Object msg) {
return rewriteChat && msg instanceof ChatMessageS2CPacket
|| noChatReports && msg instanceof QueryResponseS2CPacket
|| claimSecureChatEnforced && msg instanceof ServerMetadataS2CPacket;
|| noChatReports && msg instanceof QueryResponseS2CPacket;
}

@Override
protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) {
protected void encode(final ChannelHandlerContext ctx, final Packet msg, final ByteBuf out) {
final PacketByteBuf fbb = new PacketByteBuf(out);

if (msg instanceof ChatMessageS2CPacket packet) {
encode(ctx, packet, fbb);
} else if (msg instanceof ServerMetadataS2CPacket packet) {
if (msg instanceof final ChatMessageS2CPacket packet) {
encode(ctx, packet, fbb);
} else if (msg instanceof QueryResponseS2CPacket packet) {
} else if (msg instanceof final QueryResponseS2CPacket packet) {
encode(ctx, packet, fbb);
}
}

private void encode(final ChannelHandlerContext ctx, final ChatMessageS2CPacket msg, final PacketByteBuf buf) {
private void encode(@SuppressWarnings("unused") final ChannelHandlerContext ctx, final ChatMessageS2CPacket msg, final PacketByteBuf buf) {
final Text content = Objects.requireNonNullElseGet(msg.unsignedContent(), () -> Text.literal(msg.body().content()));

final Optional<MessageType.Parameters> ctbo = msg.serializedParameters().toParameters(freedom.getServer().getRegistryManager());
if (ctbo.isEmpty()) {
freedom.getLogger().warn("Processing packet with unknown ChatType " + msg.serializedParameters().typeId(), new Throwable());
return;
}
final Text decoratedContent = ctbo.orElseThrow().applyChatDecoration(content);
final MessageType.Parameters chatType = msg.serializedParameters();
final Text decoratedContent = chatType.applyChatDecoration(content);

final GameMessageS2CPacket system = new GameMessageS2CPacket(decoratedContent, false);
writeId(ctx, system, buf);
system.write(buf);
}

private void encode(final ChannelHandlerContext ctx, final ServerMetadataS2CPacket msg, final PacketByteBuf buf) {
writeId(ctx, msg, buf);
buf.writeText(msg.getDescription());
buf.writeOptional(msg.getFavicon(), PacketByteBuf::writeByteArray);
buf.writeBoolean(true);
s2cPlayPacketCodec.encode(buf, system);
}

private void encode(final ChannelHandlerContext ctx, final QueryResponseS2CPacket msg, final PacketByteBuf buf) {
final JsonObject status = ServerMetadata.CODEC
.encodeStart(JsonOps.INSTANCE, msg.metadata())
.get()
.left()
.orElseThrow(() -> new EncoderException("Failed to encode ServerStatus"))
.getAsJsonObject();

status.addProperty("preventsChatReports", true);
private void encode(@SuppressWarnings("unused") final ChannelHandlerContext ctx, final QueryResponseS2CPacket msg, final PacketByteBuf buf) {
final ServerMetadata status = msg.metadata();

writeId(ctx, msg, buf);
buf.writeString(GsonComponentSerializer.gson().serializer().toJson(status));
}
final CustomServerMetadata customStatus = new CustomServerMetadata(
status.description(),
status.players(),
status.version(),
status.favicon(),
status.secureChatEnforced(),
true
);

private void writeId(final ChannelHandlerContext ctx, final Packet<?> packet, final PacketByteBuf buf) {
buf.writeVarInt(ctx.channel().attr(ClientConnection.CLIENTBOUND_PROTOCOL_KEY).get().getId(packet));
buf.writeVarInt(STATUS_RESPONSE_PACKET_ID);
buf.encodeAsJson(CustomServerMetadata.CODEC, customStatus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.bk.oharass.freedomchat.rewrite;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.ServerMetadata;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;

import java.util.Optional;

public record CustomServerMetadata(Text description, Optional<ServerMetadata.Players> players,
Optional<ServerMetadata.Version> version, Optional<ServerMetadata.Favicon> favicon,
boolean secureChatEnforced, boolean preventsChatReports) {
public static final Codec<CustomServerMetadata> CODEC = RecordCodecBuilder
.create((instance) -> instance.group(
TextCodecs.CODEC.lenientOptionalFieldOf("description", ScreenTexts.EMPTY)
.forGetter(CustomServerMetadata::description),
ServerMetadata.Players.CODEC.lenientOptionalFieldOf("players")
.forGetter(CustomServerMetadata::players),
ServerMetadata.Version.CODEC.lenientOptionalFieldOf("version")
.forGetter(CustomServerMetadata::version),
ServerMetadata.Favicon.CODEC.lenientOptionalFieldOf("favicon")
.forGetter(CustomServerMetadata::favicon),
Codec.BOOL.lenientOptionalFieldOf("enforcesSecureChat", false)
.forGetter(CustomServerMetadata::secureChatEnforced),
Codec.BOOL.lenientOptionalFieldOf("preventsChatReports", true)
.forGetter(CustomServerMetadata::preventsChatReports))
.apply(instance, CustomServerMetadata::new));

public Text description() {
return this.description;
}

public Optional<ServerMetadata.Players> players() {
return this.players;
}

public Optional<ServerMetadata.Version> version() {
return this.version;
}

public Optional<ServerMetadata.Favicon> favicon() {
return this.favicon;
}

public boolean secureChatEnforced() {
return this.secureChatEnforced;
}

public boolean preventsChatReports() {
return this.preventsChatReports;
}
}
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"freedomchat.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.3",
"fabricloader": ">=0.15.11",
"fabric": "*",
"minecraft": ">=1.20.4",
"java": ">=17"
"minecraft": ">=1.20.6",
"java": ">=21"
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
8 changes: 4 additions & 4 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id("io.papermc.paperweight.userdev") version "1.5.11"
id("xyz.jpenilla.run-paper") version "2.2.2"
id("io.papermc.paperweight.userdev") version "1.7.0"
id("xyz.jpenilla.run-paper") version "2.3.0"
}

dependencies {
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
}

tasks {
Expand All @@ -13,7 +13,7 @@ tasks {
}

runServer {
minecraftVersion("1.20.4")
minecraftVersion("1.20.6")
}

processResources {
Expand Down
10 changes: 4 additions & 6 deletions paper/src/main/java/ru/bk/oharass/freedomchat/FreedomChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class FreedomChat extends JavaPlugin implements Listener {

@Override
public void onEnable() {
if (!Boolean.getBoolean("im.evan.freedomchat.bypassprotocolcheck") && this.getServer().getUnsafe().getProtocolVersion() != 765) {
getLogger().warning("This version of FreedomChat only supports protocol version 765 (1.20.4). Please use the appropriate version of FreedomChat for your server");
if (!Boolean.getBoolean("im.evan.freedomchat.bypassprotocolcheck") && this.getServer().getUnsafe().getProtocolVersion() != 766) {
getLogger().warning("This version of FreedomChat only supports protocol version 766 (1.20.6). Please use the appropriate version of FreedomChat for your server");
getLogger().warning("If you know what you are doing, set the im.evan.freedomchat.bypassprotocolcheck system property to true to bypass this check");
this.getServer().getPluginManager().disablePlugin(this);
return;
Expand All @@ -25,10 +25,8 @@ public void onEnable() {
final FileConfiguration config = this.getConfig();

final FreedomHandler handler = new FreedomHandler(
config.getBoolean("rewrite-chat"),
config.getBoolean("claim-secure-chat-enforced"),
config.getBoolean("send-prevents-chat-reports-to-client"),
this
config.getBoolean("rewrite-chat", true),
config.getBoolean("send-prevents-chat-reports-to-client", false)
);

addListener(listenerKey, channel -> channel.pipeline().addAfter("packet_handler", "freedom_handler", handler));
Expand Down
Loading

0 comments on commit 33e9224

Please sign in to comment.