goauth

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

DummyServerPlayNetworkHandler.java (7156B)


      1 package cz.bain.plugins.goauth;
      2 
      3 import net.minecraft.network.ClientConnection;
      4 import net.minecraft.network.Packet;
      5 import net.minecraft.network.packet.c2s.play.*;
      6 import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
      7 import net.minecraft.network.packet.s2c.play.KeepAliveS2CPacket;
      8 import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
      9 import net.minecraft.server.MinecraftServer;
     10 import net.minecraft.server.network.ServerPlayNetworkHandler;
     11 import net.minecraft.server.network.ServerPlayerEntity;
     12 import net.minecraft.server.world.ServerWorld;
     13 import net.minecraft.text.Text;
     14 import net.minecraft.util.Util;
     15 import net.minecraft.util.math.GlobalPos;
     16 import net.minecraft.world.World;
     17 
     18 import java.util.Objects;
     19 import java.util.Optional;
     20 import java.util.UUID;
     21 
     22 public class DummyServerPlayNetworkHandler extends ServerPlayNetworkHandler {
     23 
     24     private int ticks = 0;
     25     private final MinecraftServer server;
     26     private long lastKeepAliveTime;
     27     private boolean waitingForKeepAlive;
     28     private long keepAliveId;
     29     private final Goauth plugin;
     30 
     31     public DummyServerPlayNetworkHandler(MinecraftServer server, ClientConnection connection, ServerPlayerEntity player, Goauth plugin) {
     32         super(server, connection, player);
     33         this.server = server;
     34         this.plugin = plugin;
     35     }
     36 
     37     @Override
     38     public void tick() {
     39         ++this.ticks;
     40         if (this.ticks > 18000) {
     41             this.disconnect(Text.of(StringRepository.limboExpiredDisconnect));
     42         }
     43 
     44         if (this.ticks > 40 && this.ticks % 40 == 0) {
     45             this.sendPacket(new GameMessageS2CPacket(Text.of(this.plugin.reminderText), true));
     46             this.plugin.authStore.put(player);
     47             ServerWorld wld = player.getWorld();
     48             player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(
     49                     wld.getDimensionKey(),
     50                     wld.getRegistryKey(),
     51                     wld.getSeed(),
     52                     player.interactionManager.getGameMode(),
     53                     player.interactionManager.getPreviousGameMode(),
     54                     wld.isDebugWorld(),
     55                     wld.isFlat(),
     56                     true,
     57                     Optional.of(GlobalPos.create(wld.getRegistryKey(), player.getBlockPos()))
     58             ));
     59             Objects.requireNonNull(player.getServer()).getPlayerManager().onPlayerConnect(player.networkHandler.connection, player);
     60             return;
     61         }
     62 
     63         server.getProfiler().push("keepAlive");
     64         long l = Util.getMeasuringTimeMs();
     65         if (l - this.lastKeepAliveTime >= 15000L) {
     66             if (this.waitingForKeepAlive) {
     67                 this.disconnect(Text.translatable("disconnect.timeout"));
     68             } else {
     69                 this.waitingForKeepAlive = true;
     70                 this.lastKeepAliveTime = l;
     71                 this.keepAliveId = l;
     72                 this.sendPacket(new KeepAliveS2CPacket(this.keepAliveId));
     73             }
     74         }
     75 
     76         this.server.getProfiler().pop();
     77     }
     78 
     79     @Override
     80     public void onKeepAlive(KeepAliveC2SPacket packet) {
     81         if (this.waitingForKeepAlive && packet.getId() == this.keepAliveId) {
     82             int i = (int) (Util.getMeasuringTimeMs() - this.lastKeepAliveTime);
     83             this.player.pingMilliseconds = (this.player.pingMilliseconds * 3 + i) / 4;
     84             this.waitingForKeepAlive = false;
     85         } else {
     86             this.disconnect(Text.translatable("disconnect.timeout"));
     87         }
     88 
     89     }
     90 
     91     @Override
     92     public void onDisconnected(Text reason) {
     93         this.plugin.logger.info("{} disconnected from limbo", this.player.getName().getString());
     94         this.player.onDisconnect();
     95         this.player.getTextStream().onDisconnect();
     96         this.plugin.playersLimbo.remove(this.getPlayer().getGameProfile().getName());
     97     }
     98 
     99     /* Override rest of the methods to do nothing, the player can't do it anyway */
    100 
    101     public void onTeleportConfirm(TeleportConfirmC2SPacket packet) {
    102     }
    103 
    104     public void onPlayerMove(PlayerMoveC2SPacket packet) {
    105     }
    106 
    107     public void onRecipeBookData(RecipeBookDataC2SPacket packet) {
    108     }
    109 
    110     public void onRecipeCategoryOptions(RecipeCategoryOptionsC2SPacket packet) {
    111     }
    112 
    113     public void onAdvancementTab(AdvancementTabC2SPacket packet) {
    114     }
    115 
    116     public void onRequestCommandCompletions(RequestCommandCompletionsC2SPacket packet) {
    117     }
    118 
    119     public void onUpdateCommandBlock(UpdateCommandBlockC2SPacket packet) {
    120     }
    121 
    122     public void onUpdateCommandBlockMinecart(UpdateCommandBlockMinecartC2SPacket packet) {
    123     }
    124 
    125     public void onPickFromInventory(PickFromInventoryC2SPacket packet) {
    126     }
    127 
    128     public void onRenameItem(RenameItemC2SPacket packet) {
    129     }
    130 
    131     public void onUpdateBeacon(UpdateBeaconC2SPacket packet) {
    132     }
    133 
    134     public void onJigsawGenerating(JigsawGeneratingC2SPacket packet) {
    135     }
    136 
    137     public void onBookUpdate(BookUpdateC2SPacket packet) {
    138     }
    139 
    140     public void onQueryEntityNbt(QueryEntityNbtC2SPacket packet) {
    141     }
    142 
    143     public void onQueryBlockNbt(QueryBlockNbtC2SPacket packet) {
    144     }
    145 
    146     public void onPlayerAction(PlayerActionC2SPacket packet) {
    147     }
    148 
    149     public void onPlayerInteractBlock(PlayerInteractBlockC2SPacket packet) {
    150     }
    151 
    152     public void onPlayerInteractItem(PlayerInteractItemC2SPacket packet) {
    153     }
    154 
    155     public void onSpectatorTeleport(SpectatorTeleportC2SPacket packet) {
    156     }
    157 
    158     public void onResourcePackStatus(ResourcePackStatusC2SPacket packet) {
    159     }
    160 
    161     public void onBoatPaddleState(BoatPaddleStateC2SPacket packet) {
    162     }
    163 
    164     public void onPlayerInput(PlayerInputC2SPacket packet) {
    165     }
    166 
    167     public void onVehicleMove(VehicleMoveC2SPacket packet) {
    168     }
    169 
    170     public void onUpdateStructureBlock(UpdateStructureBlockC2SPacket packet) {
    171     }
    172 
    173     public void onUpdateJigsaw(UpdateJigsawC2SPacket packet) {
    174     }
    175 
    176     public void onUpdateSelectedSlot(UpdateSelectedSlotC2SPacket packet) {
    177     }
    178 
    179     public void onChatMessage(ChatMessageC2SPacket packet) {
    180     }
    181 
    182     public void onCommandExecution(CommandExecutionC2SPacket packet) {
    183     }
    184 
    185     public void onRequestChatPreview(RequestChatPreviewC2SPacket packet) {
    186     }
    187 
    188     public void onMessageAcknowledgment(MessageAcknowledgmentC2SPacket packet) {
    189     }
    190 
    191     public void onHandSwing(HandSwingC2SPacket packet) {
    192     }
    193 
    194     public void onClientCommand(ClientCommandC2SPacket packet) {
    195     }
    196 
    197     public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet) {
    198     }
    199 
    200     public void onClickSlot(ClickSlotC2SPacket packet) {
    201     }
    202 
    203     public void onCraftRequest(CraftRequestC2SPacket packet) {
    204     }
    205 
    206     public void onButtonClick(ButtonClickC2SPacket packet) {
    207     }
    208 
    209     public void onCreativeInventoryAction(CreativeInventoryActionC2SPacket packet) {
    210     }
    211 
    212     public void onUpdateSign(UpdateSignC2SPacket packet) {
    213     }
    214 
    215     public void onUpdatePlayerAbilities(UpdatePlayerAbilitiesC2SPacket packet) {
    216     }
    217 
    218     public void onUpdateDifficulty(UpdateDifficultyC2SPacket packet) {
    219     }
    220 
    221     public void onSelectMerchantTrade(SelectMerchantTradeC2SPacket packet) {
    222     }
    223 
    224     public void onUpdateDifficultyLock(UpdateDifficultyLockC2SPacket packet) {
    225     }
    226 
    227 }