From 9507914fd92cc10d2d96212b99a010c7619d4520 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sat, 23 Jun 2018 15:42:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=B6?= =?UTF-8?q?=D0=B4=D1=8B=D0=B9=20State?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proto_1_12_2/netty/NettyServer.java | 4 +- .../proto_1_12_2/netty/PacketHandler.java | 163 +++--------------- .../proto_1_12_2/netty/PacketListener.java | 15 -- .../netty/handlers/AbstractStateHandler.java | 54 ++++++ .../netty/handlers/HandshakeHandler.java | 25 +++ .../netty/handlers/HandshakeStateHandler.java | 11 ++ .../netty/handlers/LoginHandler.java | 86 +++++++++ .../netty/handlers/LoginStateHandler.java | 11 ++ .../netty/handlers/PlayHandler.java | 35 ++++ .../netty/handlers/PlayStateHandler.java | 11 ++ .../netty/handlers/StateHandler.java | 12 ++ .../netty/handlers/StatusHandler.java | 38 ++++ .../netty/handlers/StatusStateHandler.java | 11 ++ 13 files changed, 324 insertions(+), 152 deletions(-) delete mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketListener.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/AbstractStateHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeStateHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginStateHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayStateHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StateHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusHandler.java create mode 100644 proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusStateHandler.java diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/NettyServer.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/NettyServer.java index 99aa53a..7e2877f 100644 --- a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/NettyServer.java +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/NettyServer.java @@ -18,6 +18,7 @@ import mc.core.network.Server; import mc.core.network.StartServerException; import mc.core.network.proto_1_12_2.State; import mc.core.network.proto_1_12_2.packets.StatusResponsePacket; +import mc.core.player.Player; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +26,8 @@ import java.util.Map; @Slf4j public class NettyServer implements Server { - static final AttributeKey ATTR_STATE = AttributeKey.newInstance("ATTR_STATE"); + public static final AttributeKey ATTR_STATE = AttributeKey.newInstance("ATTR_STATE"); + public static final AttributeKey ATTR_PLAYER = AttributeKey.newInstance("ATTR_PLAYER"); @Autowired private ApplicationContext applicationContext; diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketHandler.java index 37235be..01b44ca 100644 --- a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketHandler.java +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketHandler.java @@ -4,59 +4,55 @@ */ package mc.core.network.proto_1_12_2.netty; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.util.AttributeKey; import lombok.extern.slf4j.Slf4j; -import mc.core.Config; import mc.core.chat.ChatProcessor; import mc.core.network.CSPacket; import mc.core.network.proto_1_12_2.State; -import mc.core.network.proto_1_12_2.packets.*; -import mc.core.player.Look; +import mc.core.network.proto_1_12_2.netty.handlers.*; import mc.core.player.Player; import mc.core.player.PlayerManager; -import mc.core.player.PlayerMode; -import mc.core.text.Text; -import mc.core.text.TextColor; -import mc.core.world.World; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; import javax.annotation.PostConstruct; -import java.lang.reflect.Method; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Stream; +import java.util.Collection; +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER; import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE; @Slf4j +@ComponentScan("mc.core.network.proto_1_12_2.netty.handlers") public class PacketHandler extends SimpleChannelInboundHandler { - private static final AttributeKey ATTR_PLAYER = AttributeKey.newInstance("ATTR_PLAYER"); - @Autowired - private Config config; + private ApplicationContext applicationContext; @Autowired private PlayerManager playerManager; @Autowired - private World world; - @Autowired private ChatProcessor chatProcessor; - private ImmutableMap, Method> methods = ImmutableMap.of(); + private ImmutableMap> handlersMap = ImmutableMap.of(); @PostConstruct public void init() { - this.methods = Stream.of(this.getClass().getDeclaredMethods()) - .filter(method -> method.isAnnotationPresent(PacketListener.class) - && method.getParameterCount() == 2 - && method.getParameterTypes()[0].isAssignableFrom(Channel.class) - && CSPacket.class.isAssignableFrom(method.getParameterTypes()[1])) - .collect(ImmutableMap.toImmutableMap( - method -> method.getParameterTypes()[1], - Function.identity())); + ImmutableMap.Builder> builder = ImmutableMap.builder(); + + Collection beans1 = applicationContext.getBeansOfType(HandshakeStateHandler.class).values(); + builder.put(State.HANDSHAKE, ImmutableList.copyOf(beans1)); + + Collection beans2 = applicationContext.getBeansOfType(StatusStateHandler.class).values(); + builder.put(State.STATUS, ImmutableList.copyOf(beans2)); + + Collection beans3 = applicationContext.getBeansOfType(LoginStateHandler.class).values(); + builder.put(State.LOGIN, ImmutableList.copyOf(beans3)); + + Collection beans4 = applicationContext.getBeansOfType(PlayStateHandler.class).values(); + builder.put(State.PLAY, ImmutableList.copyOf(beans4)); + + this.handlersMap = builder.build(); } @Override @@ -72,114 +68,9 @@ public class PacketHandler extends SimpleChannelInboundHandler { @Override protected void channelRead0(ChannelHandlerContext ctx, CSPacket packet) throws Exception { - if (this.methods.containsKey(packet.getClass())) { - this.methods.get(packet.getClass()).invoke(this, ctx.channel(), packet); - } else { - log.trace("No def listener of \"{}\"", packet.getClass().getSimpleName()); + ImmutableList stateHandlers = this.handlersMap.get(ctx.channel().attr(ATTR_STATE).get()); + for (StateHandler handler : stateHandlers) { + handler.handle(ctx.channel(), packet); } } - - @PacketListener - private void onHandshake(Channel channel, HandshakePacket packet) { - if (packet.getNextState().equals(State.UNKNOWN)) return; - //FIXME обрати внимание: хацкер может намеренно передать state:03 и тогда может начатся пиздец - log.debug("New state: {}", packet.getNextState()); - channel.attr(ATTR_STATE).set(packet.getNextState()); - } - - @PacketListener - private void onStatusRequest(Channel channel, StatusRequestPacket packet) { - if (!channel.attr(ATTR_STATE).get().equals(State.STATUS)) return; - - StatusResponsePacket responsePacket = new StatusResponsePacket(); - responsePacket.setMaxOnline(config.getMaxPlayers()); - responsePacket.setDescription(config.getDescriptionServer()); - responsePacket.setFaviconBase64(config.getFaviconBase64()); - responsePacket.setOnline(playerManager.getCountOnlinePlayers()); - - channel.writeAndFlush(responsePacket); - } - - @PacketListener - private void onPing(Channel channel, PingPacket packet) { - if (!channel.attr(ATTR_STATE).get().equals(State.STATUS)) return; - channel.writeAndFlush(packet); - } - - @PacketListener - private void onLoginStart(Channel channel, LoginStartPacket packet) { - if (!channel.attr(ATTR_STATE).get().equals(State.LOGIN)) return; - - Optional optPlayer = playerManager.getPlayer(packet.getPlayerName()); - if (optPlayer.isPresent() && optPlayer.get().isOnline()) { - channel.writeAndFlush(new DisconnectPacket( - Text.builder("Player \"") - .append(Text.of(packet.getPlayerName(), TextColor.YELLOW)) - .append(Text.of("\" is online", TextColor.WHITE)) - .build())) - .addListener(ChannelFutureListener.CLOSE); - } else { - Player player = playerManager.getPlayer(packet.getPlayerName()) - .orElseGet(() -> playerManager.createPlayer( - packet.getPlayerName(), - world.getSpawn(), - new Look(0f, 0f))); - - channel.writeAndFlush(new LoginSuccessPacket( - player.getUUID(), - packet.getPlayerName())); - channel.attr(ATTR_PLAYER).set(player); - channel.attr(ATTR_STATE).set(State.PLAY); - - // Join Game - JoinGamePacket pkt1 = new JoinGamePacket(); - pkt1.setEntityId(player.getId()); - pkt1.setMode(PlayerMode.CREATIVE); - pkt1.setDimension(0/*Overworld*/); - pkt1.setDifficulty(0/*Peaceful*/); - pkt1.setLevelType("flat"); - channel.write(pkt1); - - // Spawn Position - SpawnPositionPacket pkt2 = new SpawnPositionPacket(); - pkt2.setLocation(world.getSpawn()); - channel.write(pkt2); - - // Player Abilities - PlayerAbilitiesPacket pkt3 = new PlayerAbilitiesPacket(); - pkt3.setCanFly(true); - pkt3.setFlying(true); - pkt3.setGodMode(true); - pkt3.setInstantDestroyBlocks(true); - channel.write(pkt2); - channel.flush(); - - // Player Position And Look - PlayerPositionAndLookPacket pkt4 = new PlayerPositionAndLookPacket(); - pkt4.setLocation(player.getLocation()); - pkt4.setLook(player.getLook()); - channel.writeAndFlush(pkt4); - } - } - - @PacketListener - private void onClientSettings(Channel channel, ClientSettingsPacket packet) { - if (!channel.attr(ATTR_STATE).get().equals(State.PLAY)) return; - - Player player = channel.attr(ATTR_PLAYER).get(); - player.getSettings().setLocate(packet.getLocale()); - player.getSettings().setViewDistance(packet.getViewDistance()); - player.getSettings().setChatMode(packet.getChatMode()); - player.getSettings().setChatColors(packet.isChatColors()); - - player.getSettings().setCapeEnabled(packet.isCapeEnabled()); - player.getSettings().setJacketEnabled(packet.isJacketEnabled()); - player.getSettings().setLeftSleeveEnabled(packet.isLeftSleeveEnabled()); - player.getSettings().setRightSleeveEnabled(packet.isRightSleeveEnabled()); - player.getSettings().setLeftPantsLegEnabled(packet.isLeftPantsLegEnabled()); - player.getSettings().setRightPantsLegEnabled(packet.isRightPantsLegEnabled()); - player.getSettings().setHatEnabled(packet.isHatEnabled()); - - player.getSettings().setMainHand(packet.getMainHand()); - } } diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketListener.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketListener.java deleted file mode 100644 index c084b7f..0000000 --- a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/PacketListener.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * DmitriyMX - * 2018-06-16 - */ -package mc.core.network.proto_1_12_2.netty; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface PacketListener { -} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/AbstractStateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/AbstractStateHandler.java new file mode 100644 index 0000000..5cb51d4 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/AbstractStateHandler.java @@ -0,0 +1,54 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import com.google.common.collect.ImmutableMap; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import mc.core.network.CSPacket; + +import javax.annotation.PostConstruct; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.util.function.Function; +import java.util.stream.Stream; + +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE; + +@Slf4j +public abstract class AbstractStateHandler implements StateHandler { + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + protected @interface Handler { + } + + private ImmutableMap, Method> methods = ImmutableMap.of(); + + @PostConstruct + protected void init() { + this.methods = Stream.of(this.getClass().getDeclaredMethods()) + .filter(method -> method.isAnnotationPresent(Handler.class) + && method.getParameterCount() == 2 + && method.getParameterTypes()[0].isAssignableFrom(Channel.class) + && CSPacket.class.isAssignableFrom(method.getParameterTypes()[1])) + .collect(ImmutableMap.toImmutableMap( + method -> method.getParameterTypes()[1], + Function.identity())); + } + + @Override + public void handle(Channel channel, CSPacket packet) throws Exception { + if (this.methods.containsKey(packet.getClass())) { + this.methods.get(packet.getClass()).invoke(this, channel, packet); + } else { + log.trace("No def listener of {}:{}", + channel.attr(ATTR_STATE).get(), + packet.getClass().getSimpleName()); + } + } +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeHandler.java new file mode 100644 index 0000000..3ff9af1 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeHandler.java @@ -0,0 +1,25 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import mc.core.network.proto_1_12_2.State; +import mc.core.network.proto_1_12_2.packets.HandshakePacket; +import org.springframework.stereotype.Component; + +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE; + +@Slf4j +@Component +public class HandshakeHandler extends AbstractStateHandler implements HandshakeStateHandler { + @Handler + public void onHandshake(Channel channel, HandshakePacket packet) { + if (packet.getNextState().equals(State.UNKNOWN)) return; + //FIXME обрати внимание: хацкер может намеренно передать state:03 и тогда может начатся пиздец + log.debug("New state: {}", packet.getNextState()); + channel.attr(ATTR_STATE).set(packet.getNextState()); + } +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeStateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeStateHandler.java new file mode 100644 index 0000000..1bf92e7 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/HandshakeStateHandler.java @@ -0,0 +1,11 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +/** + * Marker interface + */ +public interface HandshakeStateHandler extends StateHandler { +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginHandler.java new file mode 100644 index 0000000..62ca419 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginHandler.java @@ -0,0 +1,86 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelFutureListener; +import mc.core.network.proto_1_12_2.State; +import mc.core.network.proto_1_12_2.packets.*; +import mc.core.player.Look; +import mc.core.player.Player; +import mc.core.player.PlayerManager; +import mc.core.player.PlayerMode; +import mc.core.text.Text; +import mc.core.text.TextColor; +import mc.core.world.World; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER; +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE; + +@Component +public class LoginHandler extends AbstractStateHandler implements LoginStateHandler { + @Autowired + private PlayerManager playerManager; + @Autowired + private World world; + + @Handler + public void onLoginStart(Channel channel, LoginStartPacket packet) { + Optional optPlayer = playerManager.getPlayer(packet.getPlayerName()); + if (optPlayer.isPresent() && optPlayer.get().isOnline()) { + channel.writeAndFlush(new DisconnectPacket( + Text.builder("Player \"") + .append(Text.of(packet.getPlayerName(), TextColor.YELLOW)) + .append(Text.of("\" is online", TextColor.WHITE)) + .build())) + .addListener(ChannelFutureListener.CLOSE); + } else { + Player player = playerManager.getPlayer(packet.getPlayerName()) + .orElseGet(() -> playerManager.createPlayer( + packet.getPlayerName(), + world.getSpawn(), + new Look(0f, 0f))); + + channel.writeAndFlush(new LoginSuccessPacket( + player.getUUID(), + packet.getPlayerName())); + channel.attr(ATTR_PLAYER).set(player); + channel.attr(ATTR_STATE).set(State.PLAY); + + // Join Game + JoinGamePacket pkt1 = new JoinGamePacket(); + pkt1.setEntityId(player.getId()); + pkt1.setMode(PlayerMode.CREATIVE); + pkt1.setDimension(0/*Overworld*/); + pkt1.setDifficulty(0/*Peaceful*/); + pkt1.setLevelType("flat"); + channel.write(pkt1); + + // Spawn Position + SpawnPositionPacket pkt2 = new SpawnPositionPacket(); + pkt2.setLocation(world.getSpawn()); + channel.write(pkt2); + + // Player Abilities + PlayerAbilitiesPacket pkt3 = new PlayerAbilitiesPacket(); + pkt3.setCanFly(true); + pkt3.setFlying(true); + pkt3.setGodMode(true); + pkt3.setInstantDestroyBlocks(true); + channel.write(pkt2); + channel.flush(); + + // Player Position And Look + PlayerPositionAndLookPacket pkt4 = new PlayerPositionAndLookPacket(); + pkt4.setLocation(player.getLocation()); + pkt4.setLook(player.getLook()); + channel.writeAndFlush(pkt4); + } + } +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginStateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginStateHandler.java new file mode 100644 index 0000000..a51a626 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/LoginStateHandler.java @@ -0,0 +1,11 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +/** + * Marker interface + */ +public interface LoginStateHandler extends StateHandler { +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayHandler.java new file mode 100644 index 0000000..9f6963e --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayHandler.java @@ -0,0 +1,35 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import io.netty.channel.Channel; +import mc.core.network.proto_1_12_2.packets.ClientSettingsPacket; +import mc.core.player.Player; +import org.springframework.stereotype.Component; + +import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER; + +@Component +public class PlayHandler extends AbstractStateHandler implements PlayStateHandler { + @Handler + public void onClientSettings(Channel channel, ClientSettingsPacket packet) { + Player player = channel.attr(ATTR_PLAYER).get(); + + player.getSettings().setLocate(packet.getLocale()); + player.getSettings().setViewDistance(packet.getViewDistance()); + player.getSettings().setChatMode(packet.getChatMode()); + player.getSettings().setChatColors(packet.isChatColors()); + + player.getSettings().setCapeEnabled(packet.isCapeEnabled()); + player.getSettings().setJacketEnabled(packet.isJacketEnabled()); + player.getSettings().setLeftSleeveEnabled(packet.isLeftSleeveEnabled()); + player.getSettings().setRightSleeveEnabled(packet.isRightSleeveEnabled()); + player.getSettings().setLeftPantsLegEnabled(packet.isLeftPantsLegEnabled()); + player.getSettings().setRightPantsLegEnabled(packet.isRightPantsLegEnabled()); + player.getSettings().setHatEnabled(packet.isHatEnabled()); + + player.getSettings().setMainHand(packet.getMainHand()); + } +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayStateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayStateHandler.java new file mode 100644 index 0000000..8f05c0f --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/PlayStateHandler.java @@ -0,0 +1,11 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +/** + * Marker interface + */ +public interface PlayStateHandler extends StateHandler { +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StateHandler.java new file mode 100644 index 0000000..c853d62 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StateHandler.java @@ -0,0 +1,12 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import io.netty.channel.Channel; +import mc.core.network.CSPacket; + +public interface StateHandler { + void handle(Channel channel, CSPacket packet) throws Exception; +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusHandler.java new file mode 100644 index 0000000..1216cce --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusHandler.java @@ -0,0 +1,38 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +import io.netty.channel.Channel; +import mc.core.Config; +import mc.core.network.proto_1_12_2.packets.PingPacket; +import mc.core.network.proto_1_12_2.packets.StatusRequestPacket; +import mc.core.network.proto_1_12_2.packets.StatusResponsePacket; +import mc.core.player.PlayerManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class StatusHandler extends AbstractStateHandler implements StatusStateHandler { + @Autowired + private Config config; + @Autowired + private PlayerManager playerManager; + + @Handler + public void onStatusRequest(Channel channel, StatusRequestPacket packet) { + StatusResponsePacket responsePacket = new StatusResponsePacket(); + responsePacket.setMaxOnline(config.getMaxPlayers()); + responsePacket.setDescription(config.getDescriptionServer()); + responsePacket.setFaviconBase64(config.getFaviconBase64()); + responsePacket.setOnline(playerManager.getCountOnlinePlayers()); + + channel.writeAndFlush(responsePacket); + } + + @Handler + public void onPing(Channel channel, PingPacket packet) { + channel.writeAndFlush(packet); + } +} diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusStateHandler.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusStateHandler.java new file mode 100644 index 0000000..38d77f2 --- /dev/null +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/handlers/StatusStateHandler.java @@ -0,0 +1,11 @@ +/* + * DmitriyMX + * 2018-06-23 + */ +package mc.core.network.proto_1_12_2.netty.handlers; + +/** + * Marker interface + */ +public interface StatusStateHandler extends StateHandler { +}