goauth

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

commit 4e14e23502dd98d6a2a237037281e29d175f67db
parent 2baa7f700612159ce436f3c7dd3c71d17cebcc6d
Author: bain <bain@bain.cz>
Date:   Tue, 27 Sep 2022 07:13:00 +0200

wip

Diffstat:
Asrc/main/java/cz/bain/plugins/goauth/CommandManager.java | 42++++++++++++++++++++++++++++++++++++++++++
Msrc/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java | 24+++++++++++++++++++++++-
Msrc/main/java/cz/bain/plugins/goauth/Goauth.java | 2++
Msrc/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java | 22+++++++++++++---------
Msrc/main/java/cz/bain/plugins/goauth/events/listeners/OnServerTickListener.java | 1+
5 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/src/main/java/cz/bain/plugins/goauth/CommandManager.java b/src/main/java/cz/bain/plugins/goauth/CommandManager.java @@ -0,0 +1,42 @@ +package cz.bain.plugins.goauth; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +import static net.minecraft.server.command.CommandManager.*; + +public class CommandManager { + private final Goauth plugin; + + public CommandManager(Goauth plugin) { + this.plugin = plugin; + } + + public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, net.minecraft.server.command.CommandManager.RegistrationEnvironment environment) { + dispatcher.register(literal("auth") + .then(literal("remember").executes(this::rememberCommand)) + .then(literal("forget").executes(this::forgetCommand)) + ); + } + + public int rememberCommand(CommandContext<ServerCommandSource> context) { + ServerPlayerEntity player = context.getSource().getPlayer(); + assert player != null; + this.plugin.authStore.put(player); + context.getSource().sendMessage(Text.literal("Remembered current IP address, future logins from your network do not have to be authenticated.")); + return 1; + } + + public int forgetCommand(CommandContext<ServerCommandSource> context) { + ServerPlayerEntity player = context.getSource().getPlayer(); + assert player != null; + this.plugin.authStore.remove(player.getGameProfile().getName()); + context.getSource().sendMessage(Text.literal("Remembered current IP address, future logins from your network do not have to be authenticated.")); + return 1; + } +} diff --git a/src/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java b/src/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java @@ -5,12 +5,18 @@ import net.minecraft.network.Packet; import net.minecraft.network.packet.c2s.play.*; import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.KeepAliveS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Util; +import net.minecraft.util.math.GlobalPos; +import net.minecraft.world.World; +import java.util.Objects; +import java.util.Optional; import java.util.UUID; public class DummyServerPlayNetworkHandler extends ServerPlayNetworkHandler { @@ -35,8 +41,24 @@ public class DummyServerPlayNetworkHandler extends ServerPlayNetworkHandler { this.disconnect(Text.of(StringRepository.limboExpiredDisconnect)); } - if (this.ticks > 160 && this.ticks % 40 == 0) + if (this.ticks > 40 && this.ticks % 40 == 0) { this.sendPacket(new GameMessageS2CPacket(Text.of(this.plugin.reminderText), true)); + this.plugin.authStore.put(player); + ServerWorld wld = player.getWorld(); + player.networkHandler.sendPacket(new PlayerRespawnS2CPacket( + wld.getDimensionKey(), + wld.getRegistryKey(), + wld.getSeed(), + player.interactionManager.getGameMode(), + player.interactionManager.getPreviousGameMode(), + wld.isDebugWorld(), + wld.isFlat(), + true, + Optional.of(GlobalPos.create(wld.getRegistryKey(), player.getBlockPos())) + )); + Objects.requireNonNull(player.getServer()).getPlayerManager().onPlayerConnect(player.networkHandler.connection, player); + return; + } server.getProfiler().push("keepAlive"); long l = Util.getMeasuringTimeMs(); diff --git a/src/main/java/cz/bain/plugins/goauth/Goauth.java b/src/main/java/cz/bain/plugins/goauth/Goauth.java @@ -5,6 +5,7 @@ import cz.bain.plugins.goauth.events.callbacks.OnServerTickCallback; import cz.bain.plugins.goauth.events.listeners.OnPlayerConnectListener; import cz.bain.plugins.goauth.events.listeners.OnServerTickListener; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.network.ServerPlayerEntity; import org.apache.logging.log4j.LogManager; @@ -65,6 +66,7 @@ public class Goauth implements ModInitializer { OnPlayerConnectCallback.EVENT.register(new OnPlayerConnectListener(this)); OnServerTickCallback.EVENT.register(new OnServerTickListener(this)); ServerLifecycleEvents.SERVER_STOPPED.register(server -> running = false); + CommandRegistrationCallback.EVENT.register(new CommandManager(this)::register); new Thread(new AuthUpdateRunner(key, this, port)).start(); this.logger.info("Initialized!"); } 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 @@ -72,22 +72,26 @@ public class OnPlayerConnectListener implements OnPlayerConnectCallback { Optional.of(GlobalPos.create(World.END, new BlockPos(0, 0, 0))) )); serverPlayNetworkHandler.sendPacket(new CustomPayloadS2CPacket(CustomPayloadS2CPacket.BRAND, (new PacketByteBuf(Unpooled.buffer())).writeString("limbo"))); - serverPlayNetworkHandler.sendPacket(new DifficultyS2CPacket(Difficulty.PEACEFUL, true)); - serverPlayNetworkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.getAbilities())); - serverPlayNetworkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(player.getInventory().selectedSlot)); +// serverPlayNetworkHandler.sendPacket(new DifficultyS2CPacket(Difficulty.PEACEFUL, true)); +// serverPlayNetworkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.getAbilities())); +// serverPlayNetworkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(player.getInventory().selectedSlot)); serverPlayNetworkHandler.sendPacket(new PlayerPositionLookS2CPacket(0, 0, 0, 0, 0, Collections.emptySet(), 1, true)); - serverPlayNetworkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, GameMode.SPECTATOR.getId())); - serverPlayNetworkHandler.sendPacket(new WorldBorderInitializeS2CPacket(new WorldBorder())); - serverPlayNetworkHandler.sendPacket(new WorldTimeUpdateS2CPacket(0, 0, false)); +// serverPlayNetworkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, GameMode.SPECTATOR.getId())); +// serverPlayNetworkHandler.sendPacket(new WorldBorderInitializeS2CPacket(new WorldBorder())); +// serverPlayNetworkHandler.sendPacket(new WorldTimeUpdateS2CPacket(0, 0, false)); // From 1.19 the client will show a "Loading terrain..." screen until a chunk is sent. // Unfortunately there is no empty chunk constructor for ChunkDataS2CPacket, // so we have to create a buffer with the custom empty chunk, and only then create // the packet from the buffer. serverPlayNetworkHandler.sendPacket(new ChunkRenderDistanceCenterS2CPacket(0, 0)); - PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(800)); - writeEmptyChunk(buf, 0, 0); - serverPlayNetworkHandler.sendPacket(new ChunkDataS2CPacket(buf)); + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer(800)); + writeEmptyChunk(buf, 0, 0); + serverPlayNetworkHandler.sendPacket(new ChunkDataS2CPacket(buf)); + } + } serverPlayNetworkHandler.sendPacket(new PlayerSpawnPositionS2CPacket(new BlockPos(0, 0, 0), 0.0f)); diff --git a/src/main/java/cz/bain/plugins/goauth/events/listeners/OnServerTickListener.java b/src/main/java/cz/bain/plugins/goauth/events/listeners/OnServerTickListener.java @@ -4,6 +4,7 @@ import cz.bain.plugins.goauth.Goauth; import cz.bain.plugins.goauth.AuthUpdate; import cz.bain.plugins.goauth.StringRepository; import cz.bain.plugins.goauth.events.callbacks.OnServerTickCallback; +import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text;