goauth

Fabric plugin for enhanced whitelists
git clone git://git.bain.cz/goauth.git
Log | Files | Refs | README | LICENSE

commit 7bee0491d39b16f4fc2a25aa70be40b905c56925
parent 99a212ba50a556056360e1a95204bd5ae90bc8da
Author: bain <bain@bain.cz>
Date:   Tue, 30 Nov 2021 19:59:54 +0100

update to 1.18

Diffstat:
Mgradle.properties | 8++++----
Msrc/main/java/cz/bain/plugins/goauth/Goauth.java | 18++++++++++++++----
Msrc/main/java/cz/bain/plugins/goauth/WhitelistUpdateRunner.java | 2+-
Msrc/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java | 8+++-----
Msrc/main/resources/fabric.mod.json | 2+-
5 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/gradle.properties b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.17.1 -yarn_mappings=1.17.1+build.64 -loader_version=0.12.5 +minecraft_version=1.18 +yarn_mappings=1.18+build.1 +loader_version=0.12.6 # Mod Properties mod_version=1.0 maven_group=cz.bain.plugins archives_base_name=goauth # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.42.1+1.17 +fabric_version=0.43.1+1.18 diff --git a/src/main/java/cz/bain/plugins/goauth/Goauth.java b/src/main/java/cz/bain/plugins/goauth/Goauth.java @@ -10,8 +10,6 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.UserCache; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -53,8 +51,8 @@ public class Goauth implements ModInitializer { port = Integer.parseInt(config.getRequired("port")); byte[] key; try { - key = Hex.decodeHex(config.getRequired("key").toCharArray()); - } catch (DecoderException e) { + key = hexStringToByteArray(config.getRequired("key")); + } catch (IllegalStateException e) { LOGGER.error("Failed to parse communication key! Needs to be in hex."); return; } @@ -69,4 +67,16 @@ public class Goauth implements ModInitializer { new Thread(new WhitelistUpdateRunner(key, this)).start(); LOGGER.info("Initialized!"); } + + public static byte[] hexStringToByteArray(String s) throws IllegalStateException { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + int b1 = Character.digit(s.charAt(i), 16); + int b2 = Character.digit(s.charAt(i+1), 16); + if (b1 == -1 || b2 == -1) throw new IllegalStateException(); + data[i / 2] = (byte) ((b1 << 4) + b2); + } + return data; + } } diff --git a/src/main/java/cz/bain/plugins/goauth/WhitelistUpdateRunner.java b/src/main/java/cz/bain/plugins/goauth/WhitelistUpdateRunner.java @@ -50,7 +50,7 @@ public class WhitelistUpdateRunner implements Runnable { byte[] sizeBytes = inputStream.readNBytes(4); if (sizeBytes.length != 4) continue; int size = fromByteArray(sizeBytes); - if (size > 2048) { + if (size > 2048 || size <= 0) { outputStream.write(0x01); outputStream.flush(); Goauth.LOGGER.warn("Whitelist update rejected: payload size too big ({})", size); diff --git a/src/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java b/src/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java @@ -49,11 +49,9 @@ public class OnPlayerConnectListener implements OnPlayerConnectCallback { // fake initial connection info, use DummyServerPlayNetworkHandler to override all events and ignore them ServerPlayNetworkHandler serverPlayNetworkHandler = new DummyServerPlayNetworkHandler(server, connection, player, plugin); serverPlayNetworkHandler.sendPacket(new GameJoinS2CPacket( - player.getId(), GameMode.SPECTATOR, null, - 0, false, server.getWorldRegistryKeys(), - ((PlayerManagerAccessor) server.getPlayerManager()).getRegistryManager(), - DimensionTypeAccessor.getTHE_END(), World.END, 1, - 3, true, false, false, true + player.getId(), false, GameMode.SPECTATOR, null, + server.getWorldRegistryKeys(), ((PlayerManagerAccessor) server.getPlayerManager()).getRegistryManager(), + DimensionTypeAccessor.getTHE_END(), World.END, 0, 69, 3, 3, true, false, false, true )); serverPlayNetworkHandler.sendPacket(new CustomPayloadS2CPacket(CustomPayloadS2CPacket.BRAND, (new PacketByteBuf(Unpooled.buffer())).writeString("limbo"))); serverPlayNetworkHandler.sendPacket(new DifficultyS2CPacket(Difficulty.PEACEFUL, true)); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json @@ -24,6 +24,6 @@ "depends": { "fabricloader": ">=0.12.5", "fabric": "*", - "minecraft": "1.17.1" + "minecraft": "1.18" } }