From 0c74358c913d5ba910bf86a09aa95eb3ceb16259 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 17:25:13 +0100 Subject: [PATCH] Reorganize project : - move proxy project to root - move Bedrock game data to data dir - clean some \t in translator classes - remove unnecessary comment (vars, constructor, public, private) - reformate some classes to fit the project coding style --- nbactions.xml | 18 + pom.xml | 158 +++++- proxy/.gitignore | 6 - proxy/nb-configuration.xml | 20 - proxy/pom.xml | 153 ------ .../java/org/dragonet/proxy/DragonProxy.java | 212 ------- .../java/org/dragonet/proxy/TickerThread.java | 43 -- .../proxy/entity/meta/EntityMetaData.java | 231 -------- .../org/dragonet/proxy/network/CacheKey.java | 42 -- .../network/InventoryTranslatorRegister.java | 188 ------- .../proxy/network/PCDownstreamSession.java | 156 ------ .../proxy/network/PEPacketProcessor.java | 118 ---- .../network/PacketTranslatorRegister.java | 157 ------ .../proxy/network/RaknetInterface.java | 125 ----- .../proxy/network/SessionRegister.java | 63 --- .../proxy/network/UpstreamSession.java | 516 ------------------ .../translator/IInventoryTranslator.java | 44 -- .../network/translator/MessageTranslator.java | 128 ----- .../translator/inv/ChestWindowTranslator.java | 88 --- .../pc/PCEntityEffectPacketTranslator.java | 66 --- ...ntityPositionRotationPacketTranslator.java | 57 -- .../pc/PCNotifyClientPacketTranslator.java | 57 -- .../pc/PCSpawnPlayerPacketTranslator.java | 63 --- .../pc/PCUpdateSignPacketTranslator.java | 59 -- .../translator/pe/PEChatPacketTranslator.java | 63 --- .../pe/PEPlayerActionPacketTranslator.java | 102 ---- .../SimpleInventoryTransaction.java | 241 -------- .../org/dragonet/proxy/DesktopServer.java | 18 +- .../java/org/dragonet/proxy/DragonProxy.java | 209 +++++++ .../java/org/dragonet/proxy/PocketServer.java | 18 +- .../java/org/dragonet/proxy/TickerThread.java | 42 ++ .../org/dragonet/proxy/commands/Command.java | 0 .../proxy/commands/CommandRegister.java | 0 .../proxy/commands/ConsoleCommandReader.java | 0 .../proxy/commands/IConsoleCommand.java | 0 .../proxy/commands/defaults/HelpCommand.java | 0 .../proxy/commands/defaults/KillCommand.java | 0 .../proxy/commands/defaults/StopCommand.java | 0 .../proxy/commands/defaults/TestCommand.java | 0 .../IConfigurationSerializable.java | 0 .../dragonet/proxy/configuration/Lang.java | 0 .../proxy/configuration/PropertiesConfig.java | 0 .../proxy/configuration/RemoteServer.java | 0 .../proxy/configuration/ServerConfig.java | 0 .../proxy/data}/PocketPotionEffect.java | 2 +- .../proxy/data}/entity/EntityType.java | 2 +- .../proxy/data}/entity/PEEntityAttribute.java | 2 +- .../data/entity/meta/EntityMetaData.java | 225 ++++++++ .../entity/meta/IEntityMetaDataObject.java | 2 +- .../entity/meta/type/BlockPositionMeta.java | 6 +- .../data}/entity/meta/type/ByteArrayMeta.java | 6 +- .../data}/entity/meta/type/ByteMeta.java | 6 +- .../data}/entity/meta/type/FloatMeta.java | 6 +- .../data}/entity/meta/type/IntegerMeta.java | 6 +- .../data}/entity/meta/type/LongMeta.java | 6 +- .../data}/entity/meta/type/ShortMeta.java | 6 +- .../data}/entity/meta/type/SlotMeta.java | 6 +- .../data}/entity/meta/type/Vector3FMeta.java | 6 +- .../proxy/data}/inventory/ContainerId.java | 2 +- .../proxy/data}/inventory/InventoryType.java | 2 +- .../proxy/data}/inventory/ItemList.java | 2 +- .../data}/inventory/PEWindowConstantID.java | 2 +- .../org/dragonet/proxy/data}/nbt/NBTIO.java | 10 +- .../data}/nbt/stream/NBTInputStream.java | 2 +- .../data}/nbt/stream/NBTOutputStream.java | 2 +- .../proxy/data}/nbt/tag/ByteArrayTag.java | 6 +- .../dragonet/proxy/data}/nbt/tag/ByteTag.java | 6 +- .../proxy/data}/nbt/tag/CompoundTag.java | 6 +- .../proxy/data}/nbt/tag/DoubleTag.java | 6 +- .../dragonet/proxy/data}/nbt/tag/EndTag.java | 6 +- .../proxy/data}/nbt/tag/FloatTag.java | 6 +- .../proxy/data}/nbt/tag/IntArrayTag.java | 6 +- .../dragonet/proxy/data}/nbt/tag/IntTag.java | 6 +- .../dragonet/proxy/data}/nbt/tag/ListTag.java | 6 +- .../dragonet/proxy/data}/nbt/tag/LongTag.java | 6 +- .../proxy/data}/nbt/tag/NumberTag.java | 2 +- .../proxy/data}/nbt/tag/ShortTag.java | 6 +- .../proxy/data}/nbt/tag/StringTag.java | 6 +- .../org/dragonet/proxy/data}/nbt/tag/Tag.java | 6 +- .../org/dragonet/proxy/network/CacheKey.java | 32 ++ .../proxy/network/IDownstreamSession.java | 15 +- .../network/InventoryTranslatorRegister.java | 182 ++++++ .../proxy/network/PCDownstreamSession.java | 148 +++++ .../proxy/network/PEPacketProcessor.java | 112 ++++ .../network/PacketTranslatorRegister.java | 148 +++++ .../proxy/network/RaknetInterface.java | 118 ++++ .../proxy/network/SessionRegister.java | 58 ++ .../proxy/network/UpstreamSession.java | 509 +++++++++++++++++ .../proxy/network/cache/CachedEntity.java | 2 +- .../proxy/network/cache/CachedWindow.java | 0 .../proxy/network/cache/EntityCache.java | 2 +- .../proxy/network/cache/WindowCache.java | 0 .../translator/EntityMetaTranslator.java | 38 +- .../translator/IInventoryTranslator.java | 45 ++ .../translator/IPCPacketTranslator.java | 17 +- .../translator/IPEPacketTranslator.java | 17 +- .../translator/ItemBlockTranslator.java | 27 +- .../network/translator/MessageTranslator.java | 120 ++++ .../translator/inv/ChestWindowTranslator.java | 78 +++ .../pc/PCAnimationPacketTranslator.java | 4 - .../pc/PCBlockChangePacketTranslator.java | 32 +- .../translator/pc/PCChatPacketTranslator.java | 67 +-- .../pc/PCDestroyEntitiesPacketTranslator.java | 34 +- .../pc/PCEntityEffectPacketTranslator.java | 56 ++ .../pc/PCEntityMetadataPacketTranslator.java | 14 +- .../pc/PCEntityPositionPacketTranslator.java | 4 - ...ntityPositionRotationPacketTranslator.java | 46 ++ .../PCEntityRemoveEffectPacketTranslator.java | 40 +- .../pc/PCEntityRotationPacketTranslator.java | 4 - .../PCEntitySetPassengerPacketTranslator.java | 32 +- .../pc/PCEntityVelocityPacketTranslator.java | 38 +- .../pc/PCJoinGamePacketTranslator.java | 22 +- .../PCMultiBlockChangePacketTranslator.java | 47 +- .../pc/PCMultiChunkDataPacketTranslator.java | 25 +- .../pc/PCNotifyClientPacketTranslator.java | 47 ++ .../pc/PCOpenWindowPacketTranslator.java | 22 +- .../pc/PCPlaySoundPacketTranslator.java | 58 +- .../pc/PCPlayerListItemPacketTranslator.java | 4 - ...layerPositionRotationPacketTranslator.java | 28 +- .../pc/PCSetSlotPacketTranslator.java | 48 +- .../pc/PCSoundEventPacketTranslator.java | 4 - .../pc/PCSpawnMobPacketTranslator.java | 12 +- .../pc/PCSpawnObjectPacketTranslator.java | 4 - .../pc/PCSpawnPlayerPacketTranslator.java | 52 ++ .../pc/PCUpdateHealthPacketTranslator.java | 32 +- .../pc/PCUpdateSignPacketTranslator.java | 49 ++ .../pc/PCUpdateTimePacketTranslator.java | 20 +- .../pc/PCWindowItemsTranslator.java | 47 +- .../PEAdventureSettingsPacketTranslator.java | 6 +- .../PEBlockPickRequestPacketTranslator.java | 12 +- .../translator/pe/PEChatPacketTranslator.java | 53 ++ .../pe/PECommandRequestPacketTranslator.java | 16 +- .../pe/PEInteractPacketTranslator.java | 6 +- ...EInventoryTransactionPacketTranslator.java | 10 +- .../pe/PEMovePlayerPacketTranslator.java | 4 - .../pe/PEPlayerActionPacketTranslator.java | 92 ++++ .../pe/PEPlayerEquipmentPacketTranslator.java | 32 +- .../pe/PESoundEventPacketTranslator.java | 9 - .../pe/PEWindowClosePacketTranslator.java | 22 +- .../org/dragonet/proxy/protocol/PEPacket.java | 0 .../org/dragonet/proxy/protocol/Protocol.java | 0 .../dragonet/proxy/protocol/ProtocolInfo.java | 0 .../protocol/packets/AddEntityPacket.java | 4 +- .../protocol/packets/AddItemEntityPacket.java | 2 +- .../protocol/packets/AddPlayerPacket.java | 2 +- .../packets/AdventureSettingsPacket.java | 0 .../proxy/protocol/packets/AnimatePacket.java | 0 .../packets/BlockEntityDataPacket.java | 0 .../packets/BlockPickRequestPacket.java | 0 .../packets/ChangeDimensionPacket.java | 0 .../packets/ChunkRadiusUpdatedPacket.java | 0 .../packets/CommandRequestPacket.java | 0 .../packets/ContainerClosePacket.java | 0 .../protocol/packets/ContainerOpenPacket.java | 0 .../protocol/packets/DisconnectPacket.java | 0 .../protocol/packets/FullChunkDataPacket.java | 0 .../protocol/packets/InteractPacket.java | 0 .../packets/InventoryContentPacket.java | 0 .../protocol/packets/InventorySlotPacket.java | 0 .../packets/InventoryTransactionPacket.java | 0 .../protocol/packets/LevelEventPacket.java | 0 .../packets/LevelSoundEventPacket.java | 0 .../proxy/protocol/packets/LoginPacket.java | 0 .../protocol/packets/MobEffectPacket.java | 0 .../protocol/packets/MobEquipmentPacket.java | 0 .../protocol/packets/MoveEntityPacket.java | 0 .../protocol/packets/MovePlayerPacket.java | 0 .../protocol/packets/PlaySoundPacket.java | 0 .../protocol/packets/PlayStatusPacket.java | 0 .../protocol/packets/PlayerActionPacket.java | 0 .../protocol/packets/PlayerHotbarPacket.java | 0 .../protocol/packets/PlayerListPacket.java | 0 .../protocol/packets/PlayerSkinPacket.java | 0 .../protocol/packets/RemoveEntityPacket.java | 0 .../packets/RequestChunkRadiusPacket.java | 0 .../ResourcePackClientResponsePacket.java | 0 .../packets/ResourcePackStackPacket.java | 0 .../packets/ResourcePacksInfoPacket.java | 0 .../proxy/protocol/packets/RespawnPacket.java | 0 .../protocol/packets/SetEntityDataPacket.java | 2 +- .../protocol/packets/SetEntityLinkPacket.java | 0 .../packets/SetEntityMotionPacket.java | 0 .../protocol/packets/SetHealthPacket.java | 0 .../packets/SetPlayerGameTypePacket.java | 0 .../packets/SetSpawnPositionPacket.java | 0 .../proxy/protocol/packets/SetTimePacket.java | 0 .../protocol/packets/StartGamePacket.java | 0 .../proxy/protocol/packets/TextPacket.java | 0 .../packets/UpdateAttributesPacket.java | 2 +- .../protocol/packets/UpdateBlockPacket.java | 0 .../type/InventoryTransactionAction.java | 0 .../proxy/protocol/type/PEEntityLink.java | 0 .../proxy/protocol/type/PlayerListEntry.java | 0 .../dragonet/proxy/protocol/type/Skin.java | 0 .../dragonet/proxy/protocol/type/Slot.java | 2 +- .../proxy/protocol/type/chunk/ChunkData.java | 0 .../proxy/protocol/type/chunk/ExtraData.java | 0 .../proxy/protocol/type/chunk/Section.java | 0 .../transaction/InventoryTransaction.java | 0 .../action/CreativeInventoryAction.java | 0 .../transaction/action/DropItemAction.java | 0 .../transaction/action/InventoryAction.java | 0 .../transaction/action/SlotChangeAction.java | 0 .../transaction/data/ReleaseItemData.java | 0 .../transaction/data/TransactionData.java | 0 .../type/transaction/data/UseItemData.java | 0 .../transaction/data/UseItemOnEntityData.java | 0 .../org/dragonet/proxy/utilities/Binary.java | 0 .../proxy/utilities/BinaryStream.java | 6 +- .../proxy/utilities/BlockPosition.java | 0 .../dragonet/proxy/utilities/Constants.java | 0 .../dragonet/proxy/utilities/DebugTools.java | 32 +- .../dragonet/proxy/utilities/DefaultSkin.java | 0 .../dragonet/proxy/utilities/GameRule.java | 0 .../org/dragonet/proxy/utilities/HTTP.java | 0 .../org/dragonet/proxy/utilities/Logger.java | 0 .../proxy/utilities/LoginChainDecoder.java | 0 .../org/dragonet/proxy/utilities/MCColor.java | 0 .../dragonet/proxy/utilities/MCPESkin.java | 0 .../dragonet/proxy/utilities/NukkitMath.java | 0 .../proxy/utilities/NukkitRandom.java | 0 .../proxy/utilities/NumberConversions.java | 0 .../proxy/utilities/PatternChecker.java | 0 .../dragonet/proxy/utilities/Terminal.java | 0 .../org/dragonet/proxy/utilities/VarInt.java | 0 .../dragonet/proxy/utilities/Vector3F.java | 0 .../dragonet/proxy/utilities/Versioning.java | 0 .../org/dragonet/proxy/utilities/Zlib.java | 0 .../proxy/utilities/io/ArraySplitter.java | 0 .../proxy/utilities/io/ByteUtility.java | 0 .../proxy/utilities/io/DataIOPair.java | 0 .../proxy/utilities/io/PEBinaryReader.java | 0 .../proxy/utilities/io/PEBinaryUtils.java | 0 .../proxy/utilities/io/PEBinaryWriter.java | 0 .../proxy/utilities/io/SkinDownloader.java | 0 .../main/resources/STEVE_SKIN_FULL_BINARY.bin | Bin {proxy/src => src}/main/resources/config.yml | 0 .../main/resources/en_US.properties | 0 238 files changed, 3012 insertions(+), 3712 deletions(-) create mode 100644 nbactions.xml delete mode 100644 proxy/.gitignore delete mode 100644 proxy/nb-configuration.xml delete mode 100644 proxy/pom.xml delete mode 100644 proxy/src/main/java/org/dragonet/proxy/DragonProxy.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/TickerThread.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/entity/meta/EntityMetaData.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/RaknetInterface.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/SessionRegister.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java delete mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java rename {proxy/src => src}/main/java/org/dragonet/proxy/DesktopServer.java (69%) create mode 100644 src/main/java/org/dragonet/proxy/DragonProxy.java rename {proxy/src => src}/main/java/org/dragonet/proxy/PocketServer.java (69%) create mode 100644 src/main/java/org/dragonet/proxy/TickerThread.java rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/Command.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/CommandRegister.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/IConsoleCommand.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/defaults/KillCommand.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/defaults/StopCommand.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/commands/defaults/TestCommand.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/configuration/IConfigurationSerializable.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/configuration/Lang.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/configuration/PropertiesConfig.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/configuration/RemoteServer.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/configuration/ServerConfig.java (100%) rename {proxy/src/main/java/org/dragonet => src/main/java/org/dragonet/proxy/data}/PocketPotionEffect.java (99%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/EntityType.java (98%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/PEEntityAttribute.java (98%) create mode 100644 src/main/java/org/dragonet/proxy/data/entity/meta/EntityMetaData.java rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/IEntityMetaDataObject.java (91%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/BlockPositionMeta.java (83%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/ByteArrayMeta.java (83%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/ByteMeta.java (80%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/FloatMeta.java (81%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/IntegerMeta.java (81%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/LongMeta.java (81%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/ShortMeta.java (81%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/SlotMeta.java (81%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/entity/meta/type/Vector3FMeta.java (73%) rename {proxy/src/main/java/org/dragonet => src/main/java/org/dragonet/proxy/data}/inventory/ContainerId.java (87%) rename {proxy/src/main/java/org/dragonet => src/main/java/org/dragonet/proxy/data}/inventory/InventoryType.java (98%) rename {proxy/src/main/java/org/dragonet => src/main/java/org/dragonet/proxy/data}/inventory/ItemList.java (98%) rename {proxy/src/main/java/org/dragonet => src/main/java/org/dragonet/proxy/data}/inventory/PEWindowConstantID.java (93%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/NBTIO.java (97%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/stream/NBTInputStream.java (98%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/stream/NBTOutputStream.java (98%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/ByteArrayTag.java (89%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/ByteTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/CompoundTag.java (97%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/DoubleTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/EndTag.java (75%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/FloatTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/IntArrayTag.java (89%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/IntTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/ListTag.java (94%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/LongTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/NumberTag.java (86%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/ShortTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/StringTag.java (87%) rename {proxy/src/main/java/org/dragonet/proxy => src/main/java/org/dragonet/proxy/data}/nbt/tag/Tag.java (97%) create mode 100644 src/main/java/org/dragonet/proxy/network/CacheKey.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/IDownstreamSession.java (64%) create mode 100644 src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java create mode 100644 src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java create mode 100644 src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java create mode 100644 src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java create mode 100644 src/main/java/org/dragonet/proxy/network/RaknetInterface.java create mode 100644 src/main/java/org/dragonet/proxy/network/SessionRegister.java create mode 100644 src/main/java/org/dragonet/proxy/network/UpstreamSession.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/cache/CachedEntity.java (97%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/cache/CachedWindow.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/cache/EntityCache.java (99%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/cache/WindowCache.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java (96%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java (75%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java (76%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java (93%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java create mode 100644 src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java (96%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java (60%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java (53%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java (62%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java (90%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java (96%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java (58%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java (96%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java (83%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java (58%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java (65%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java (53%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java (91%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java (72%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java (52%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java (98%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java (94%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java (50%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java (97%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java (84%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java (95%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java (65%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java (73%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java (51%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java (88%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java (81%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java (66%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java (91%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java (96%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java (96%) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java (90%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java (89%) rename {proxy/src => src}/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java (71%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/PEPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/Protocol.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java (95%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java (94%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java (97%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/BlockEntityDataPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ChangeDimensionPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ChunkRadiusUpdatedPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/CommandRequestPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ContainerClosePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ContainerOpenPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/DisconnectPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/FullChunkDataPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/InventoryContentPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/InventorySlotPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/LevelEventPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/LoginPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/MobEffectPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/MobEquipmentPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/MoveEntityPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/MovePlayerPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlaySoundPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlayStatusPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlayerActionPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlayerListPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/PlayerSkinPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/RemoveEntityPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/RequestChunkRadiusPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ResourcePackClientResponsePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ResourcePackStackPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/ResourcePacksInfoPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/RespawnPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java (91%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetEntityMotionPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetHealthPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetPlayerGameTypePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetSpawnPositionPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/SetTimePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/StartGamePacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/TextPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java (93%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/packets/UpdateBlockPacket.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/PEEntityLink.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/PlayerListEntry.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/Skin.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/Slot.java (93%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/chunk/ChunkData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/chunk/ExtraData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/chunk/Section.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Binary.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/BinaryStream.java (98%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/BlockPosition.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Constants.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/DebugTools.java (53%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/DefaultSkin.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/GameRule.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/HTTP.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Logger.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/MCColor.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/MCPESkin.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/NukkitMath.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/NukkitRandom.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/NumberConversions.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/PatternChecker.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Terminal.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/VarInt.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Vector3F.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Versioning.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/Zlib.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/ArraySplitter.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/ByteUtility.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/DataIOPair.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/PEBinaryReader.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/PEBinaryUtils.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/PEBinaryWriter.java (100%) rename {proxy/src => src}/main/java/org/dragonet/proxy/utilities/io/SkinDownloader.java (100%) rename {proxy/src => src}/main/resources/STEVE_SKIN_FULL_BINARY.bin (100%) rename {proxy/src => src}/main/resources/config.yml (100%) rename {proxy/src => src}/main/resources/en_US.properties (100%) diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 000000000..5bec36493 --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,18 @@ + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.dragonet.proxy.DragonProxy + java + true + + + diff --git a/pom.xml b/pom.xml index ab593faa7..d23000275 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,148 @@ - 4.0.0 - org.dragonet.proxy - DragonProxy-parent - 1.0.0 - pom - DragonProxy + 4.0.0 + proxy + 0.2.2.1 + DragonProxy + org.dragonet.proxy - - package - - - proxy - + + dragonproxy-${project.version} + ${project.basedir}/target + + + ${project.basedir}/src/main/resources + + + package + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + + + + + *:* + + junit:junit + **/*.html + **/*.txt + + + + true + + + + package + + shade + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + + org.dragonet.proxy.DragonProxy + true + + + + org/dragonet/proxy + + true + + + + + + + + - A proxy for Minecraft: Pocket Editions to join Minecraft desktop(Java) version servers. - http://dragonet.org/ + + + sonatype + Sonatype Nexus + default + https://oss.sonatype.org/content/repositories/public/ + + + maven-repo + https://raw.githubusercontent.com/JRakNet/MavenRepository/master + + + egg82-ninja + https://www.myget.org/F/egg82-java/maven/ + + + jitpack.io + https://jitpack.io + + + + + + net.marfgamer + jraknet + 2.8.2 + + + com.github.Steveice10 + MCProtocolLib + -SNAPSHOT + + + com.github.Steveice10 + MCAuthLib + -SNAPSHOT + + + org.yaml + snakeyaml + 1.19 + + + org.apache.commons + commons-lang3 + 3.7 + + + com.google.guava + guava + 23.4-jre + + + ninja.egg82.lib + egg82-lib + 2.6.32 + + + junit + junit + 4.12 + test + + + + UTF-8 + UTF-8 + diff --git a/proxy/.gitignore b/proxy/.gitignore deleted file mode 100644 index 80d197b79..000000000 --- a/proxy/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.* -build -out -target/ -!.gitignore -dependency-reduced-pom.xml diff --git a/proxy/nb-configuration.xml b/proxy/nb-configuration.xml deleted file mode 100644 index 8f3692163..000000000 --- a/proxy/nb-configuration.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - none - ${project.basedir}/../licenseheader.txt - true - - diff --git a/proxy/pom.xml b/proxy/pom.xml deleted file mode 100644 index 312df8678..000000000 --- a/proxy/pom.xml +++ /dev/null @@ -1,153 +0,0 @@ - - 4.0.0 - proxy - 0.2.2.1 - proxy - - - dragonproxy-${project.version} - ${project.basedir}/target - - - ${project.basedir}/src/main/resources - - - package - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - - - - - - *:* - - junit:junit - **/*.html - **/*.txt - - - - true - - - - package - - shade - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - - - org.dragonet.proxy.DragonProxy - true - - - - org/dragonet/proxy - - true - - - - - - - - - - - org.dragonet.proxy - DragonProxy-parent - 1.0.0 - - - - - sonatype - Sonatype Nexus - default - https://oss.sonatype.org/content/repositories/public/ - - - maven-repo - https://raw.githubusercontent.com/JRakNet/MavenRepository/master - - - egg82-ninja - https://www.myget.org/F/egg82-java/maven/ - - - jitpack.io - https://jitpack.io - - - - - - net.marfgamer - jraknet - 2.8.2 - - - com.github.Steveice10 - MCProtocolLib - -SNAPSHOT - - - com.github.Steveice10 - MCAuthLib - -SNAPSHOT - - - org.yaml - snakeyaml - 1.19 - - - org.apache.commons - commons-lang3 - 3.7 - - - com.google.guava - guava - 23.4-jre - - - ninja.egg82.lib - egg82-lib - 2.6.32 - - - junit - junit - 4.12 - test - - - - UTF-8 - UTF-8 - - diff --git a/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java b/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java deleted file mode 100644 index ae7958c12..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - -import org.dragonet.proxy.network.SessionRegister; -import org.dragonet.proxy.network.RaknetInterface; -import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.configuration.ServerConfig; -import org.dragonet.proxy.utilities.*; -import org.dragonet.proxy.commands.CommandRegister; -import org.dragonet.proxy.commands.ConsoleCommandReader; - -import org.yaml.snakeyaml.Yaml; - -public class DragonProxy { - // vars - public static final boolean IS_RELEASE = false; // DO NOT CHANGE, ONLY ON PRODUCTION - - private Logger logger; - private final TickerThread ticker = new TickerThread(this); - private ServerConfig config; - private Lang lang; - private SessionRegister sessionRegister; - private RaknetInterface network; - private boolean shuttingDown; - private ScheduledExecutorService generalThreadPool; - private CommandRegister commandRegister; - private String authMode; - private ConsoleCommandReader console; - private String motd; - private boolean debug = false; - - // main - public static void main(String[] args) { - new DragonProxy().run(args); - } - - // functions - public Logger getLogger() { - return logger; - } - - public ServerConfig getConfig() { - return config; - } - - public Lang getLang() { - return lang; - } - - public SessionRegister getSessionRegister() { - return sessionRegister; - } - - public RaknetInterface getNetwork() { - return network; - } - - public boolean isShuttingDown() { - return shuttingDown; - } - - public ScheduledExecutorService getGeneralThreadPool() { - return generalThreadPool; - } - - public CommandRegister getCommandRegister() { - return commandRegister; - } - - public String getAuthMode() { - return authMode; - } - - public boolean isDebug() { - return debug; - } - - public void run(String[] args) { - logger = new Logger(this); - - try { - File fileConfig = new File("config.yml"); - if (!fileConfig.exists()) { - // Create default config - FileOutputStream fos = new FileOutputStream(fileConfig); - InputStream ins = DragonProxy.class.getResourceAsStream("/config.yml"); - int data; - while ((data = ins.read()) != -1) { - fos.write(data); - } - ins.close(); - fos.close(); - } - config = new Yaml().loadAs(new FileInputStream(fileConfig), ServerConfig.class); - } catch (IOException ex) { - logger.severe("Failed to load configuration file! Make sure the file is writable."); - ex.printStackTrace(); - return; - } - - // Initialize console command reader - console = new ConsoleCommandReader(this); - console.startConsole(); - - // Should we save console log? Set it in config file - /* - * if(config.isLog_console()){ console.startFile("console.log"); - * logger.info("Saving console output enabled"); } else { - * logger.info("Saving console output disabled"); } - */ - - // Put at the top instead - if (!IS_RELEASE) { - logger.warning( - MCColor.YELLOW + "This is a development build. It may contain bugs. Do not use on production.\n"); - } - - // Check for startup arguments - checkArguments(args); - - // Load language file - try { - lang = new Lang(config.lang); - } catch (IOException ex) { - logger.severe("Failed to load language file: " + config.lang + "!"); - ex.printStackTrace(); - return; - } - // Load some more stuff - logger.info(lang.get(Lang.INIT_LOADING, Versioning.RELEASE_VERSION)); - logger.info(lang.get(Lang.INIT_MC_PC_SUPPORT, Versioning.MINECRAFT_PC_VERSION)); - logger.info(lang.get(Lang.INIT_MC_PE_SUPPORT, Versioning.MINECRAFT_PE_VERSION)); - authMode = config.mode.toLowerCase(); - if (!authMode.equals("cls") && !authMode.equals("online") && !authMode.equals("offline")) { - logger.severe("Invalid login 'mode' option detected, must be cls/online/offline. You set it to '" + authMode - + "'! "); - return; - } - - // Init session and command stuff - sessionRegister = new SessionRegister(this); - commandRegister = new CommandRegister(this); - - // Create thread pool - logger.info(lang.get(Lang.INIT_CREATING_THREAD_POOL, config.thread_pool_size)); - generalThreadPool = Executors.newScheduledThreadPool(config.thread_pool_size); - - // Bind - logger.info(lang.get(Lang.INIT_BINDING, config.udp_bind_ip, config.udp_bind_port)); - // RakNet.enableLogging(); - network = new RaknetInterface(this, config.udp_bind_ip, // IP - config.udp_bind_port); // Port - - // MOTD - motd = config.motd; - motd = motd.replace("&", "\u00a7"); - - network.setBroadcastName(motd, 1, 2); - ticker.start(); - logger.info(lang.get(Lang.INIT_DONE)); - } - - public void onTick() { - // network.onTick(); - sessionRegister.onTick(); - } - - public void checkArguments(String[] args) { - for (String arg : args) { - if (arg.toLowerCase().contains("--debug")) { - debug = true; - getLogger().debug = true; - logger.info(MCColor.DARK_AQUA + "Proxy is running in debug mode."); - } - } - } - - public void shutdown() { - logger.info(lang.get(Lang.SHUTTING_DOWN)); - - debug = false; - this.shuttingDown = true; - network.shutdown(); - try { - Thread.sleep(2000); // Wait for all clients disconnected - } catch (Exception ex) { - System.out.println("Exception while shutting down!"); - ex.printStackTrace(); - } - System.out.println("Goodbye!"); - System.exit(0); - } -} diff --git a/proxy/src/main/java/org/dragonet/proxy/TickerThread.java b/proxy/src/main/java/org/dragonet/proxy/TickerThread.java deleted file mode 100644 index 0066cf583..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/TickerThread.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy; - -public class TickerThread extends Thread { - - private final DragonProxy proxy; - - public TickerThread(DragonProxy proxy) { - this.proxy = proxy; - setDaemon(true); - } - - @Override - public void run() { - long time; - while (!proxy.isShuttingDown()) { - time = System.currentTimeMillis(); - proxy.onTick(); - time = System.currentTimeMillis() - time; - if (time >= 50) { - continue; - } else { - try { - Thread.sleep(50 - time); - } catch (InterruptedException ex) { - return; - } - } - } - } - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/EntityMetaData.java b/proxy/src/main/java/org/dragonet/proxy/entity/meta/EntityMetaData.java deleted file mode 100644 index eb6998c4a..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/EntityMetaData.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.entity.meta; - -import java.util.HashMap; -import java.util.Map; - -import org.dragonet.proxy.entity.meta.type.*; -import org.dragonet.proxy.utilities.BinaryStream; -import org.dragonet.proxy.utilities.BlockPosition; - -public class EntityMetaData extends BinaryStream { - public static class Constants { - public static final int DATA_TYPE_BYTE = 0; - public static final int DATA_TYPE_SHORT = 1; - public static final int DATA_TYPE_INT = 2; - public static final int DATA_TYPE_FLOAT = 3; - public static final int DATA_TYPE_STRING = 4; - public static final int DATA_TYPE_SLOT = 5; - public static final int DATA_TYPE_POS = 6; - public static final int DATA_TYPE_LONG = 7; - public static final int DATA_TYPE_VECTOR3F = 8; - - public static final int DATA_FLAGS = 0; - public static final int DATA_HEALTH = 1; // int (minecart/boat) - public static final int DATA_VARIANT = 2; // int - public static final int DATA_COLOR = 3, DATA_COLOUR = 3; // byte - public static final int DATA_NAMETAG = 4; // string - public static final int DATA_OWNER_EID = 5; // long - public static final int DATA_TARGET_EID = 6; // long - public static final int DATA_AIR = 7; // short - public static final int DATA_POTION_COLOR = 8; // int (ARGB!) - public static final int DATA_POTION_AMBIENT = 9; // byte - /* 10 (byte) */ - public static final int DATA_HURT_TIME = 11; // int (minecart/boat) - public static final int DATA_HURT_DIRECTION = 12; // int (minecart/boat) - public static final int DATA_PADDLE_TIME_LEFT = 13; // float - public static final int DATA_PADDLE_TIME_RIGHT = 14; // float - public static final int DATA_EXPERIENCE_VALUE = 15; // int (xp orb) - public static final int DATA_MINECART_DISPLAY_BLOCK = 16; // int (id | (data << 16)) - public static final int DATA_MINECART_DISPLAY_OFFSET = 17; // int - public static final int DATA_MINECART_HAS_DISPLAY = 18; // byte (must be 1 for minecart to show block inside) - // TODO: add more properties - public static final int DATA_ENDERMAN_HELD_ITEM_ID = 23; // short - public static final int DATA_ENDERMAN_HELD_ITEM_DAMAGE = 24; // short - public static final int DATA_ENTITY_AGE = 25; // short - /* - * 27 (byte) player-specific flags 28 (int) player "index"? 29 (block coords) - * bed position - */ - public static final int DATA_BED_POSITION = 29; - public static final int DATA_FIREBALL_POWER_X = 30; // float - public static final int DATA_FIREBALL_POWER_Y = 31; - public static final int DATA_FIREBALL_POWER_Z = 32; - /* - * 33 (unknown) 34 (float) fishing bobber 35 (float) fishing bobber 36 (float) - * fishing bobber - */ - public static final int DATA_POTION_AUX_VALUE = 37; // short - public static final int DATA_LEAD_HOLDER_EID = 38; // long - public static final int DATA_SCALE = 39; // float - public static final int DATA_INTERACTIVE_TAG = 40; // string (button text) - public static final int DATA_NPC_SKIN_ID = 41; // string - public static final int DATA_URL_TAG = 42; // string - public static final int DATA_MAX_AIR = 43; // short - public static final int DATA_MARK_VARIANT = 44; // int - /* - * 45 (byte) container stuff 46 (int) container stuff 47 (int) container stuff - */ - public static final int DATA_BLOCK_TARGET = 48; // block coords (ender crystal) - public static final int DATA_WITHER_INVULNERABLE_TICKS = 49; // int - public static final int DATA_WITHER_TARGET_1 = 50; // long - public static final int DATA_WITHER_TARGET_2 = 51; // long - public static final int DATA_WITHER_TARGET_3 = 52; // long - /* 53 (short) */ - public static final int DATA_BOUNDING_BOX_WIDTH = 54; // float - public static final int DATA_BOUNDING_BOX_HEIGHT = 55; // float - public static final int DATA_FUSE_LENGTH = 56; // int - public static final int DATA_RIDER_SEAT_POSITION = 57; // vector3f - public static final int DATA_RIDER_ROTATION_LOCKED = 58; // byte - public static final int DATA_RIDER_MAX_ROTATION = 59; // float - public static final int DATA_RIDER_MIN_ROTATION = 60; // float - public static final int DATA_AREA_EFFECT_CLOUD_RADIUS = 61; // float - public static final int DATA_AREA_EFFECT_CLOUD_WAITING = 62; // int - public static final int DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63; // int - /* 64 (int) shulker-related */ - public static final int DATA_SHULKER_ATTACH_FACE = 65; // byte - /* 66 (short) shulker-related */ - public static final int DATA_SHULKER_ATTACH_POS = 67; // block coords - public static final int DATA_TRADING_PLAYER_EID = 68; // long - /* 70 (byte) command-block */ - public static final int DATA_COMMAND_BLOCK_COMMAND = 71; // string - public static final int DATA_COMMAND_BLOCK_LAST_OUTPUT = 72; // string - public static final int DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73; // byte - public static final int DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74; // byte - public static final int DATA_STRENGTH = 75; // int - public static final int DATA_MAX_STRENGTH = 76; // int - /* - * 77 (int) 78 (int) - */ - public static final int DATA_FLAG_ONFIRE = 0; - public static final int DATA_FLAG_SNEAKING = 1; - public static final int DATA_FLAG_RIDING = 2; - public static final int DATA_FLAG_SPRINTING = 3; - public static final int DATA_FLAG_ACTION = 4; - public static final int DATA_FLAG_INVISIBLE = 5; - public static final int DATA_FLAG_TEMPTED = 6; - public static final int DATA_FLAG_INLOVE = 7; - public static final int DATA_FLAG_SADDLED = 8; - public static final int DATA_FLAG_POWERED = 9; - public static final int DATA_FLAG_IGNITED = 10; - public static final int DATA_FLAG_BABY = 11; - public static final int DATA_FLAG_CONVERTING = 12; - public static final int DATA_FLAG_CRITICAL = 13; - public static final int DATA_FLAG_CAN_SHOW_NAMETAG = 14; - public static final int DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15; - public static final int DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16; - public static final int DATA_FLAG_SILENT = 17; - public static final int DATA_FLAG_WALLCLIMBING = 18; - public static final int DATA_FLAG_CAN_CLIMB = 19; - public static final int DATA_FLAG_SWIMMER = 20; - public static final int DATA_FLAG_CAN_FLY = 21; - public static final int DATA_FLAG_RESTING = 22; - public static final int DATA_FLAG_SITTING = 23; - public static final int DATA_FLAG_ANGRY = 24; - public static final int DATA_FLAG_INTERESTED = 25; - public static final int DATA_FLAG_CHARGED = 26; - public static final int DATA_FLAG_TAMED = 27; - public static final int DATA_FLAG_LEASHED = 28; - public static final int DATA_FLAG_SHEARED = 29; - public static final int DATA_FLAG_GLIDING = 30; - public static final int DATA_FLAG_ELDER = 31; - public static final int DATA_FLAG_MOVING = 32; - public static final int DATA_FLAG_BREATHING = 33; - public static final int DATA_FLAG_CHESTED = 34; - public static final int DATA_FLAG_STACKABLE = 35; - public static final int DATA_FLAG_SHOWBASE = 36; - public static final int DATA_FLAG_REARING = 37; - public static final int DATA_FLAG_VIBRATING = 38; - public static final int DATA_FLAG_IDLING = 39; - public static final int DATA_FLAG_EVOKER_SPELL = 40; - public static final int DATA_FLAG_CHARGE_ATTACK = 41; - public static final int DATA_FLAG_WASD_CONTROLLED = 42; - public static final int DATA_FLAG_CAN_POWER_JUMP = 43; - public static final int DATA_FLAG_LINGER = 44; - public static final int DATA_FLAG_HAS_COLLISION = 45; - public static final int DATA_FLAG_AFFECTED_BY_GRAVITY = 46; - public static final int DATA_FLAG_FIRE_IMMUNE = 47; - public static final int DATA_FLAG_DANCING = 48; - } - - // vars - public HashMap map; - - // constructor - public EntityMetaData() { - this.map = new HashMap<>(); - } - - // public - public static EntityMetaData from(BinaryStream source) { - // TODO - return createDefault(); - } - - public static EntityMetaData createDefault() { - EntityMetaData data = new EntityMetaData(); - data.setGenericFlag(Constants.DATA_FLAG_BREATHING, true); - data.setGenericFlag(Constants.DATA_FLAG_AFFECTED_BY_GRAVITY, true); - data.setGenericFlag(Constants.DATA_FLAG_HAS_COLLISION, true); - data.setGenericFlag(Constants.DATA_FLAG_CAN_CLIMB, true); - data.set(Constants.DATA_AIR, new ShortMeta((short) 400)); - data.set(Constants.DATA_MAX_AIR, new ShortMeta((short) 400)); - data.set(Constants.DATA_NAMETAG, new ByteArrayMeta("")); - data.set(Constants.DATA_LEAD_HOLDER_EID, new LongMeta(-1L)); - data.set(Constants.DATA_SCALE, new FloatMeta(1.0f)); -// data.set(Constants.DATA_BED_POSITION, new BlockPositionMeta(new BlockPosition(0, 0, 0))); - return data; - } - /* - * public static EntityMetaData getMetaDataFromPlayer(GlowPlayer player) { byte - * flags = (byte) 0x00; if (player.getFireTicks() > 0) { flags |= - * EntityMetaData.Constants.DATA_FLAG_ONFIRE; } if(player.isSprinting()){ flags - * |= EntityMetaData.Constants.DATA_FLAG_SPRINTING; } if(player.isSneaking()){ - * flags |= EntityMetaData.Constants.DATA_FLAG_SNEAKING; } EntityMetaData data = - * createDefault(); data.set(EntityMetaData.Constants.DATA_FLAGS, new - * ByteMeta(flags)); data.set(EntityMetaData.Constants.DATA_NAMETAG, new - * ByteArrayMeta(player.getDisplayName())); return data; } - */ - - public void set(int key, IEntityMetaDataObject object) { - this.map.put(key, object); - } - - public void encode() { - reset(); - putUnsignedVarInt(map.size()); - for (Map.Entry entry : this.map.entrySet()) { - putUnsignedVarInt(entry.getKey()); - putUnsignedVarInt(entry.getValue().type()); - entry.getValue().encode(this); - } - } - - public void setGenericFlag(int flagId, boolean value) { - long flag = 0; - if (!map.containsKey(Constants.DATA_FLAGS)) { - map.put(Constants.DATA_FLAGS, new LongMeta(0L)); - } else { - flag = ((LongMeta) map.get(Constants.DATA_FLAGS)).data; - } - boolean currValue = ((flag >> flagId) & 0b1) > 0; - if (currValue != value) { - flag ^= (1L << flagId); - } - ((LongMeta) map.get(Constants.DATA_FLAGS)).data = flag; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java b/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java deleted file mode 100644 index 2e8d85748..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -public final class CacheKey { - // vars - // PEPacket - public static final String PACKET_JOIN_GAME_PACKET = "achedJoinGamePacket"; - public static final String PACKET_LOGIN_PACKET = "achedLoginPacket"; - // int - public static final String PLAYER_EID = "player_entity_id"; - // int - public static final String AUTHENTICATION_STATE = "auth_state"; - // String - public static final String AUTHENTICATION_EMAIL = "auth_mail"; - // Position - public static final String BLOCK_BREAKING_POSITION = "block_breaking_position"; - // Position - public static final String WINDOW_BLOCK_POSITION = "window_block_position"; - // int - public static final String WINDOW_OPENED_ID = "window_opened_id"; - - // constructor - public CacheKey() { - - } - - // public - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java deleted file mode 100644 index f6a8d9de3..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import java.util.HashMap; -import java.util.Map; - -import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; -import com.github.steveice10.mc.protocol.data.game.window.WindowType; -import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; -import org.dragonet.inventory.PEWindowConstantID; -import org.dragonet.proxy.network.cache.CachedWindow; -import org.dragonet.proxy.network.translator.ItemBlockTranslator; -import org.dragonet.proxy.network.translator.inv.ChestWindowTranslator; -import org.dragonet.proxy.network.translator.IInventoryTranslator; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.ContainerClosePacket; -import org.dragonet.proxy.protocol.packets.InventoryContentPacket; -import org.dragonet.proxy.protocol.type.Slot; - -public final class InventoryTranslatorRegister { - - // PC Type => PE Translator - private static final Map TRANSLATORS = new HashMap<>(); - - static { - TRANSLATORS.put(WindowType.CHEST, new ChestWindowTranslator()); - } - - // constructor - - // public - public static PEPacket[] sendPlayerInventory(UpstreamSession session) { - CachedWindow win = session.getWindowCache().getPlayerInventory(); - // Translate and send - InventoryContentPacket ret = new InventoryContentPacket(); - ret.windowId = PEWindowConstantID.PLAYER_INVENTORY.getId(); - ret.items = new Slot[40]; - // hotbar - for (int i = 36; i < 45; i++) { - ret.items[i - 36] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); - } - // inventory - for (int i = 9; i < 36; i++) { - // TODO: Add NBT support - ret.items[i] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); - } - // armors - for (int i = 5; i < 9; i++) { - ret.items[i + 31] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); - } - // TODO: Add armor support - return new PEPacket[] { ret }; - } - - public static void open(UpstreamSession session, ServerOpenWindowPacket win) { - closeOpened(session, true); - if (TRANSLATORS.containsKey(win.getType())) { - CachedWindow cached = new CachedWindow(win.getWindowId(), win.getType(), 36 + win.getSlots()); - session.getWindowCache().cacheWindow(cached); - TRANSLATORS.get(win.getType()).open(session, cached); - - com.github.steveice10.packetlib.packet.Packet[] items = session.getWindowCache() - .getCachedPackets(win.getWindowId()); - for (com.github.steveice10.packetlib.packet.Packet item : items) { - if (item != null) { - if (ServerWindowItemsPacket.class.isAssignableFrom(item.getClass())) { - updateContent(session, (ServerWindowItemsPacket) item); - } else { - updateSlot(session, (ServerSetSlotPacket) item); - } - } - } - } else { - // Not supported - session.getDownstream().send(new ClientCloseWindowPacket(win.getWindowId())); - } - } - - public static void closeOpened(UpstreamSession session, boolean byServer) { - if (session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID)) { - // There is already a window opened - int id = (int) session.getDataCache().remove(CacheKey.WINDOW_OPENED_ID); - if (!byServer) { - session.getDownstream().send(new ContainerClosePacket((byte) (id & 0xFF))); - } - if (session.getDataCache().containsKey(CacheKey.WINDOW_BLOCK_POSITION)) { - // Already a block was replaced to Chest, reset it - session.sendFakeBlock(((Position) session.getDataCache().get(CacheKey.WINDOW_BLOCK_POSITION)).getX(), - ((Position) session.getDataCache().get(CacheKey.WINDOW_BLOCK_POSITION)).getY(), - ((Position) session.getDataCache().remove(CacheKey.WINDOW_BLOCK_POSITION)).getZ(), 1, // Set to - // stone - // since - // we - // don't - // know - // what - // it - // was, - // server - // will - // correct - // it - // once - // client - // interacts - // it - 0); - } - if (byServer) { - session.sendPacket(new ContainerClosePacket((byte) (id & 0xFF)), true); - } - } - } - - public static void updateContent(UpstreamSession session, ServerWindowItemsPacket packet) { - if (packet.getWindowId() == 0) { - return; // We don't process player inventory updates here. - } - if (!session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID) - || !session.getWindowCache().hasWindow(packet.getWindowId())) { - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - int openedId = (int) session.getDataCache().get(CacheKey.WINDOW_OPENED_ID); - if (packet.getWindowId() != openedId) { - // Hmm - closeOpened(session, true); - return; - } - - CachedWindow win = session.getWindowCache().get(openedId); - IInventoryTranslator t = TRANSLATORS.get(win.pcType); - if (t == null) { - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - win.slots = packet.getItems(); - t.updateContent(session, win); - } - - public static void updateSlot(UpstreamSession session, ServerSetSlotPacket packet) { - if (packet.getWindowId() == 0) { - return; // We don't process player inventory updates here. - } - if (!session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID) - || !session.getWindowCache().hasWindow(packet.getWindowId())) { - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - int openedId = (int) session.getDataCache().get(CacheKey.WINDOW_OPENED_ID); - if (packet.getWindowId() != openedId) { - // Hmm - closeOpened(session, true); - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - CachedWindow win = session.getWindowCache().get(openedId); - System.out.println("WIN=" + win.slots.length + ", REQ_SLOT=" + packet.getSlot()); - if (win.size <= packet.getSlot()) { - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - IInventoryTranslator t = TRANSLATORS.get(win.pcType); - if (t == null) { - session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); - return; - } - win.slots[packet.getSlot()] = packet.getItem(); // Update here - t.updateSlot(session, win, packet.getSlot()); - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java b/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java deleted file mode 100644 index ee465662e..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import com.github.steveice10.mc.protocol.MinecraftProtocol; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; -import com.github.steveice10.packetlib.Client; -import com.github.steveice10.packetlib.event.session.ConnectedEvent; -import com.github.steveice10.packetlib.event.session.DisconnectedEvent; -import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; -import com.github.steveice10.packetlib.event.session.SessionAdapter; -import com.github.steveice10.packetlib.packet.Packet; -import com.github.steveice10.packetlib.tcp.TcpSessionFactory; -import org.dragonet.proxy.DesktopServer; -import org.dragonet.proxy.DragonProxy; -import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.protocol.PEPacket; - -import java.util.LinkedList; -import java.util.List; - -/** - * Maintaince the connection between the proxy and remote Minecraft server. - */ -public class PCDownstreamSession implements IDownstreamSession { - // vars - public MinecraftProtocol protocol; - - private final DragonProxy proxy; - private final UpstreamSession upstream; - private DesktopServer serverInfo; - private Client remoteClient; - - // constructor - public PCDownstreamSession(DragonProxy proxy, UpstreamSession upstream) { - this.proxy = proxy; - this.upstream = upstream; - } - - // public - public void connect(DesktopServer serverInfo) { - this.serverInfo = serverInfo; - connect(serverInfo.remote_addr, serverInfo.remote_port); - } - - public void connect(String addr, int port) { - if (this.protocol == null) { - upstream.onConnected(); // Clear the flags - upstream.disconnect("ERROR! "); - return; - } - remoteClient = new Client(addr, port, protocol, new TcpSessionFactory()); - remoteClient.getSession().addListener(new SessionAdapter() { - public void connected(ConnectedEvent event) { - proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_REMOTE_CONNECTED, upstream.getUsername(), - upstream.getRemoteAddress())); - upstream.onConnected(); - } - - public void disconnected(DisconnectedEvent event) { - upstream.disconnect(proxy.getLang().get(event.getReason())); - } - - public void packetReceived(PacketReceivedEvent event) { - /* - * if (!event.getPacket().getClass().getSimpleName().toLowerCase().contains( - * "block") && - * !event.getPacket().getClass().getSimpleName().toLowerCase().contains( - * "entity") && - * !event.getPacket().getClass().getSimpleName().toLowerCase().contains("time") - * && - * !event.getPacket().getClass().getSimpleName().toLowerCase().contains("chunk") - * ) { String debug_string = event.getPacket().getClass().getSimpleName() + - * " > " + event.getPacket().toString(); if(debug_string.length() > 128) - * debug_string = debug_string.substring(0, 128) + "... "; - * System.out.println("REMOTE << " + debug_string); } - */ - // Handle the packet - try { - PEPacket[] packets = PacketTranslatorRegister.translateToPE(upstream, event.getPacket()); - if (packets == null) { - return; - } - if (packets.length <= 0) { - return; - } - if (packets.length == 1) { - upstream.sendPacket(packets[0]); - } else { - upstream.sendAllPackets(packets, true); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - }); - remoteClient.getSession().connect(); - } - - public void disconnect() { - if (remoteClient != null && remoteClient.getSession().isConnected()) { - remoteClient.getSession().disconnect("Disconnect"); - } - } - - public boolean isConnected() { - return remoteClient != null && remoteClient.getSession().isConnected(); - } - - public void send(Packet... packets) { - for (Packet p : packets) { - send(p); - } - } - - public void send(Packet packet) { - if (packet == null) - return; -// System.out.println("UPSTREAMING >> " + packet.getClass().getSimpleName()); - remoteClient.getSession().send(packet); - } - - public void sendChat(String chat) { - remoteClient.getSession().send(new ClientChatPacket(chat)); - } - - public void onTick() { - - } - - public DragonProxy getProxy() { - return proxy; - } - - public UpstreamSession getUpstream() { - return upstream; - } - - public DesktopServer getServerInfo() { - return serverInfo; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java b/proxy/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java deleted file mode 100644 index 441ba78f1..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import java.io.FileOutputStream; -import java.util.ArrayDeque; -import java.util.Deque; - -import com.github.steveice10.packetlib.packet.Packet; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.Protocol; -import org.dragonet.proxy.protocol.ProtocolInfo; -import org.dragonet.proxy.protocol.packets.ChunkRadiusUpdatedPacket; -import org.dragonet.proxy.protocol.packets.LoginPacket; -import org.dragonet.proxy.protocol.packets.RequestChunkRadiusPacket; - -public class PEPacketProcessor implements Runnable { - // vars - public static final int MAX_PACKETS_PER_CYCLE = 200; - - private final UpstreamSession client; - private final Deque packets = new ArrayDeque<>(); - - // constructor - public PEPacketProcessor(UpstreamSession client) { - this.client = client; - } - - // public - public UpstreamSession getClient() { - return client; - } - - public void putPacket(byte[] packet) { - packets.add(packet); - } - - public void run() { - int cnt = 0; - while (cnt < MAX_PACKETS_PER_CYCLE && !packets.isEmpty()) { - cnt++; - byte[] p = packets.pop(); - PEPacket[] packets; - try { - packets = Protocol.decode(p); - if (packets == null || packets.length <= 0) { - continue; - } - } catch (Exception e) { - e.printStackTrace(); - return; - } - for (PEPacket decoded : packets) { - handlePacket(decoded); - } - } - - } - - public void handlePacket(PEPacket packet) { - if (packet == null) { - return; - } - - // System.out.println("RECEIVED PACKET=" + packet.getClass().getSimpleName()); - /* - * try{ FileOutputStream fos = new FileOutputStream("cap_" + - * System.currentTimeMillis() + "_" + packet.getClass().getSimpleName() + - * ".bin"); fos.write(packet.getBuffer()); fos.close(); }catch(Exception e){} - */ - - switch (packet.pid()) { - case ProtocolInfo.LOGIN_PACKET: - client.onLogin((LoginPacket) packet); - break; - case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET: - if (client.isLoggedIn()) { - return; - } - client.postLogin(); - break; - case ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET: - client.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius)); - break; - case ProtocolInfo.TEXT_PACKET: // Text (check CLS Login) - if (client.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) { - PacketTranslatorRegister.translateToPC(client, packet); - break; - } - default: - if (client.getDownstream() == null) { - break; - } - if (!client.getDownstream().isConnected()) { - break; - } - Packet[] translated = PacketTranslatorRegister.translateToPC(client, packet); - if (translated == null || translated.length == 0) { - break; - } - client.getDownstream().send(translated); - break; - } - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java deleted file mode 100644 index f66b3f93d..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.*; -import com.github.steveice10.packetlib.packet.Packet; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import java.util.HashMap; -import java.util.Map; -import org.dragonet.proxy.network.translator.IPEPacketTranslator; -import org.dragonet.proxy.network.translator.pc.*; -import org.dragonet.proxy.network.translator.pe.*; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.*; - -public final class PacketTranslatorRegister { - // vars - private static final Map, IPCPacketTranslator> PC_TO_PE_TRANSLATOR = new HashMap<>(); - private static final Map, IPEPacketTranslator> PE_TO_PC_TRANSLATOR = new HashMap<>(); - - /** - * PC to PE - */ - static { - // Login phase - PC_TO_PE_TRANSLATOR.put(ServerJoinGamePacket.class, new PCJoinGamePacketTranslator()); - - // Settings && Weather - PC_TO_PE_TRANSLATOR.put(ServerNotifyClientPacket.class, new PCNotifyClientPacketTranslator()); - - // Chat - PC_TO_PE_TRANSLATOR.put(ServerChatPacket.class, new PCChatPacketTranslator()); - - // Map - PC_TO_PE_TRANSLATOR.put(ServerChunkDataPacket.class, new PCMultiChunkDataPacketTranslator()); - - PC_TO_PE_TRANSLATOR.put(ServerUpdateTimePacket.class, new PCUpdateTimePacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerBlockChangePacket.class, new PCBlockChangePacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerMultiBlockChangePacket.class, new PCMultiBlockChangePacketTranslator()); - // PC_TO_PE_TRANSLATOR.put(ServerUpdateSignPacket.class, new - // PCUpdateSignPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerPlaySoundPacket.class, new PCPlaySoundPacketTranslator()); - // - // // Entity - PC_TO_PE_TRANSLATOR.put(ServerPlayerPositionRotationPacket.class, new PCPlayerPositionRotationPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerSpawnMobPacket.class, new PCSpawnMobPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerPlayerListEntryPacket.class, new PCPlayerListItemPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerSpawnPlayerPacket.class, new PCSpawnPlayerPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerSpawnObjectPacket.class, new PCSpawnObjectPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityMetadataPacket.class, new PCEntityMetadataPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityDestroyPacket.class, new PCDestroyEntitiesPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityPositionRotationPacket.class,new PCEntityPositionRotationPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityPositionPacket.class, new PCEntityPositionPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityRotationPacket.class, new PCEntityRotationPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityVelocityPacket.class, new PCEntityVelocityPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityEffectPacket.class, new PCEntityEffectPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityRemoveEffectPacket.class, new PCEntityRemoveEffectPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerPlayerHealthPacket.class, new PCUpdateHealthPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntityAnimationPacket.class, new PCAnimationPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerEntitySetPassengersPacket.class, new PCEntitySetPassengerPacketTranslator()); - // - // //Inventory - PC_TO_PE_TRANSLATOR.put(ServerOpenWindowPacket.class, new PCOpenWindowPacketTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerWindowItemsPacket.class, new PCWindowItemsTranslator()); - PC_TO_PE_TRANSLATOR.put(ServerSetSlotPacket.class, new PCSetSlotPacketTranslator()); - - } - - /** - * PE to PC - */ - static { - // Map - PE_TO_PC_TRANSLATOR.put(LevelSoundEventPacket.class, new PESoundEventPacketTranslator()); - - // Chat - PE_TO_PC_TRANSLATOR.put(TextPacket.class, new PEChatPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(CommandRequestPacket.class, new PECommandRequestPacketTranslator()); - - // Entity - // PE_TO_PC_TRANSLATOR.put(UseItem.class, new PEUseItemPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(MovePlayerPacket.class, new PEMovePlayerPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(PlayerActionPacket.class, new PEPlayerActionPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(InteractPacket.class, new PEInteractPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(AdventureSettingsPacket.class, new PEAdventureSettingsPacketTranslator()); - - // Inventory - PE_TO_PC_TRANSLATOR.put(ContainerClosePacket.class, new PEWindowClosePacketTranslator()); - PE_TO_PC_TRANSLATOR.put(MobEquipmentPacket.class, new PEPlayerEquipmentPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(InventoryTransactionPacket.class, new PEInventoryTransactionPacketTranslator()); - PE_TO_PC_TRANSLATOR.put(BlockPickRequestPacket.class, new PEBlockPickRequestPacketTranslator()); - } - - // constructor - public PacketTranslatorRegister() { - - } - - // public - public static PEPacket[] translateToPE(UpstreamSession session, Packet packet) { - if (packet == null) { - return null; - } - IPCPacketTranslator target = (IPCPacketTranslator) PC_TO_PE_TRANSLATOR.get(packet.getClass()); - if (target == null) { - return null; - } - try { - return target.translate(session, packet); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Packet[] translateToPC(UpstreamSession session, PEPacket packet) { - if (packet == null) { - return null; - } - IPEPacketTranslator target = (IPEPacketTranslator) PE_TO_PC_TRANSLATOR - .get(packet.getClass()); - if (target == null) { - return null; - } - try { - return target.translate(session, packet); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/RaknetInterface.java b/proxy/src/main/java/org/dragonet/proxy/network/RaknetInterface.java deleted file mode 100644 index cd0fbc84e..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/RaknetInterface.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import java.net.InetSocketAddress; -import java.util.*; - -import net.marfgamer.jraknet.RakNetPacket; -import net.marfgamer.jraknet.identifier.MinecraftIdentifier; -import net.marfgamer.jraknet.server.RakNetServer; -import net.marfgamer.jraknet.server.RakNetServerListener; -import net.marfgamer.jraknet.server.ServerPing; -import net.marfgamer.jraknet.session.RakNetClientSession; -import org.dragonet.proxy.DragonProxy; -import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.protocol.ProtocolInfo; -import org.dragonet.proxy.utilities.Versioning; - -public class RaknetInterface implements RakNetServerListener { - // vars - public static final Set IMMEDIATE_PACKETS = new HashSet<>(); - - private final DragonProxy proxy; - private final SessionRegister sessions; - private final RakNetServer rakServer; - - static { - IMMEDIATE_PACKETS.add("PlayStatus"); - } - - // constructor - public RaknetInterface(DragonProxy proxy, String ip, int port) { - this.proxy = proxy; - rakServer = new RakNetServer(port, Integer.MAX_VALUE); - rakServer.addListener(this); - rakServer.addSelfListener(); - sessions = this.proxy.getSessionRegister(); - rakServer.startThreaded(); - } - - // public - public DragonProxy getProxy() { - return proxy; - } - - public RakNetServer getRakServer() { - return rakServer; - } - - /* - * public void onTick() { } - */ - - public void handlePing(ServerPing ping) { - System.out.println("PING " + ping.getSender().toString()); - } - - public void handleMessage(RakNetClientSession session, RakNetPacket packet, int channel) { - UpstreamSession upstream = sessions.getSession(session.getAddress().toString()); - if (upstream == null) { - return; - } - // System.out.println("Received RakNet packet: " + - // packet.getClass().getSimpleName()); - upstream.handlePacketBinary(packet.array()); - } - - public void onClientConnect(RakNetClientSession session) { - System.out.println("CLIENT CONNECT"); - String identifier = session.getAddress().toString(); - UpstreamSession upstream = new UpstreamSession(proxy, identifier, session, session.getAddress()); - sessions.newSession(upstream); - } - - public void onClientDisconnect(RakNetClientSession session, String reason) { - System.out.println("CLIENT DISCONNECT"); - UpstreamSession upstream = sessions.getSession(session.getAddress().toString()); - if (upstream == null) { - return; - } - upstream.onDisconnect(proxy.getLang().get(Lang.MESSAGE_CLIENT_DISCONNECT)); // It will handle rest of the - // things. - } - - public void onThreadException(Throwable throwable) { - System.out.println("Thread exception: " + throwable.getMessage()); - throwable.printStackTrace(); - } - - public void onHandlerException(InetSocketAddress address, Throwable throwable) { - System.out.println("Handler exception: " + throwable.getMessage()); - throwable.printStackTrace(); - } - - public void onSessionException(RakNetClientSession session, Throwable throwable) { - System.out.println("Session exception: " + throwable.getMessage()); - throwable.printStackTrace(); - } - - public void setBroadcastName(String serverName, int players, int maxPlayers) { - rakServer.setIdentifier( - new MinecraftIdentifier(serverName, ProtocolInfo.CURRENT_PROTOCOL, ProtocolInfo.MINECRAFT_VERSION_NETWORK, - players, maxPlayers, new Random().nextLong(), "DragonProxy", "Survival")); - if (!rakServer.isBroadcastingEnabled()) { - rakServer.setBroadcastingEnabled(true); - } - } - - public void shutdown() { - rakServer.shutdown(); - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/SessionRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/SessionRegister.java deleted file mode 100644 index cb5892b39..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/SessionRegister.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.dragonet.proxy.DragonProxy; - -public class SessionRegister { - // vars - private final DragonProxy proxy; - private final Map clients = Collections - .synchronizedMap(new HashMap()); - - // constructor - public SessionRegister(DragonProxy proxy) { - this.proxy = proxy; - } - - // public - public void onTick() { - Iterator> iterator = clients.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry ent = iterator.next(); - ent.getValue().onTick(); - } - } - - public void newSession(UpstreamSession session) { - clients.put(session.getRaknetID(), session); - } - - public void removeSession(UpstreamSession session) { - clients.remove(session.getRaknetID()); - } - - public UpstreamSession getSession(String identifier) { - return clients.get(identifier); - } - - public Map getAll() { - return Collections.unmodifiableMap(clients); - } - - public int getOnlineCount() { - return clients.size(); - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java b/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java deleted file mode 100644 index bd90218cf..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java +++ /dev/null @@ -1,516 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network; - -import com.github.steveice10.mc.auth.exception.request.RequestException; -import com.github.steveice10.mc.auth.service.AuthenticationService; -import com.github.steveice10.mc.protocol.MinecraftProtocol; -import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import java.io.FileOutputStream; -import java.net.InetSocketAddress; -import java.util.*; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import net.marfgamer.jraknet.protocol.Reliability; -import net.marfgamer.jraknet.session.RakNetClientSession; -import org.dragonet.proxy.DesktopServer; -import org.dragonet.proxy.DragonProxy; -import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.configuration.RemoteServer; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.type.ByteMeta; -import org.dragonet.proxy.network.cache.CachedEntity; -import org.dragonet.proxy.network.cache.EntityCache; -import org.dragonet.proxy.network.cache.WindowCache; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.ProtocolInfo; -import org.dragonet.proxy.protocol.packets.*; -import org.dragonet.proxy.protocol.type.chunk.ChunkData; -import org.dragonet.proxy.protocol.type.chunk.Section; -import org.dragonet.proxy.utilities.*; - -/** - * Maintaince the connection between the proxy and Minecraft: Pocket Edition - * clients. - */ -public class UpstreamSession { - // vars - private final DragonProxy proxy; - private final String raknetID; - private final RakNetClientSession raknetClient; - private boolean loggedIn; - private boolean spawned; - private List cachedPackets; - private final InetSocketAddress remoteAddress; - private final PEPacketProcessor packetProcessor; - private final ScheduledFuture packetProcessorScheule; - private LoginChainDecoder profile; - private String username; - private IDownstreamSession downstream; - - /* - * ============================================================================= - * ========================== | Caches for Protocol Compatibility | /* - * ============================================================================= - * ========================== - */ - private final Map dataCache = Collections.synchronizedMap(new HashMap()); - private final Map playerInfoCache = Collections - .synchronizedMap(new HashMap()); - private final EntityCache entityCache = new EntityCache(this); - private final WindowCache windowCache = new WindowCache(this); - protected boolean connecting; - - /* - * ============================================================================= - * ========================== - */ - private MinecraftProtocol protocol; - - // constructor - public UpstreamSession(DragonProxy proxy, String raknetID, RakNetClientSession raknetClient, - InetSocketAddress remoteAddress) { - this.proxy = proxy; - this.raknetID = raknetID; - this.remoteAddress = remoteAddress; - this.raknetClient = raknetClient; - packetProcessor = new PEPacketProcessor(this); - packetProcessorScheule = proxy.getGeneralThreadPool().scheduleAtFixedRate(packetProcessor, 10, 50, - TimeUnit.MILLISECONDS); - } - - // public - public DragonProxy getProxy() { - return proxy; - } - - public String getRaknetID() { - return raknetID; - } - - public RakNetClientSession getRaknetClient() { - return raknetClient; - } - - public boolean isLoggedIn() { - return loggedIn; - } - - public boolean isSpawned() { - return spawned; - } - - public InetSocketAddress getRemoteAddress() { - return remoteAddress; - } - - public PEPacketProcessor getPacketProcessor() { - return packetProcessor; - } - - public LoginChainDecoder getProfile() { - return profile; - } - - public String getUsername() { - return username; - } - - public IDownstreamSession getDownstream() { - return downstream; - } - - public Map getDataCache() { - return dataCache; - } - - public Map getPlayerInfoCache() { - return playerInfoCache; - } - - public EntityCache getEntityCache() { - return entityCache; - } - - public WindowCache getWindowCache() { - return windowCache; - } - - public void sendPacket(PEPacket packet) { - sendPacket(packet, false); - } - - public void sendPacket(PEPacket packet, boolean immediate) { - if (packet == null) - return; - // System.out.println("Sending [" + packet.getClass().getSimpleName() + "] "); - - packet.encode(); - - byte[] buffer; - try { - buffer = Zlib.deflate( - Binary.appendBytes(Binary.writeUnsignedVarInt(packet.getBuffer().length), packet.getBuffer()), 6); - } catch (Exception e) { - e.printStackTrace(); - return; - } - - // handler.sendEncapsulated(identifier, encapsulated, RakNet.FLAG_NEED_ACK | - // (overridedImmediate ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL)); - raknetClient.sendMessage(Reliability.RELIABLE_ORDERED, 0, - new net.marfgamer.jraknet.Packet(Binary.appendBytes((byte) 0xfe, buffer))); - } - - public void sendAllPackets(PEPacket[] packets, boolean immediate) { - if (packets.length < 5) { - for (PEPacket packet : packets) { - sendPacket(packet); - } - } /* - * else { Batch batch = new BatchPacket(); boolean mustImmediate = immediate; if - * (!mustImmediate) { for (PEPacket packet : packets) { if - * (packet.isShouldSendImmidate()) { batch.packets.add(packet); mustImmediate = - * true; break; } } } sendPacket(batch, mustImmediate); } - */ - } - - public void connectToServer(RemoteServer server) { - if (server == null) - return; - connecting = true; - if (downstream != null && downstream.isConnected()) { - spawned = false; - cachedPackets = null; - - downstream.disconnect(); - // TODO: Send chat message about server change. - - // Remove all loaded entities - /* - * BatchPacket batch = new BatchPacket(); - * this.entityCache.getEntities().entrySet().forEach((ent) -> { if(ent.getKey() - * != 0){ batch.packets.add(new RemoveEntityPacket(ent.getKey())); } }); - * this.entityCache.reset(true); sendPacket(batch, true); - */ - return; - } - cachedPackets = new LinkedList<>(); - if (server.getClass().isAssignableFrom(DesktopServer.class)) { - downstream = new PCDownstreamSession(proxy, this); - ((PCDownstreamSession) downstream).protocol = protocol; - downstream.connect(server.remote_addr, server.remote_port); - } else { - // downstream = new PEDownstreamSession(proxy, this); - // ((PEDownstreamSession)downstream).connect((PocketServer) server); - disconnect("PE targets not supported yet"); - } - } - - public void onConnected() { - connecting = false; - } - - /** - * Disconnected from server. - * - * @param reason - */ - public void disconnect(String reason) { - if (!connecting) { - sendPacket(new DisconnectPacket(false, reason)); - // RakNet server will call onDisconnect() - } - } - - /** - * Called when this client disconnects. - * - * @param reason - * The reason of disconnection. - */ - public void onDisconnect(String reason) { - proxy.getLogger().info(proxy.getLang().get(Lang.CLIENT_DISCONNECTED, - proxy.getAuthMode().equals("cls") ? "unknown" : username, remoteAddress, reason)); - if (downstream != null) { - downstream.disconnect(); - } - proxy.getSessionRegister().removeSession(this); - packetProcessorScheule.cancel(true); - } - - public void authenticate(String password) { - proxy.getGeneralThreadPool().execute(() -> { - try { - protocol = new MinecraftProtocol((String) dataCache.get(CacheKey.AUTHENTICATION_EMAIL), password, - false); - } catch (RequestException ex) { - if (ex.getMessage().toLowerCase().contains("invalid")) { - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD)); - disconnect(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD)); - return; - } else { - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - disconnect(proxy.getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - return; - } - } - - if (!username.equals(protocol.getProfile().getName())) { - username = protocol.getProfile().getName(); - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_USERNAME, username)); - } - - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_SUCCESS, username)); - - proxy.getLogger().info( - proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_SUCCESS_CONSOLE, username, remoteAddress, username)); - connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); - }); - } - - public void onLogin(LoginPacket packet) { - if (username != null) { - disconnect("Already logged in, this must be an error! "); - return; - } - - getDataCache().put(CacheKey.PACKET_LOGIN_PACKET, packet); - - PlayStatusPacket status = new PlayStatusPacket(); - System.out.println("CLIENT PROTOCOL = " + packet.protocol); - if (packet.protocol != ProtocolInfo.CURRENT_PROTOCOL) { - status.status = PlayStatusPacket.LOGIN_FAILED_CLIENT; - sendPacket(status, true); - disconnect(proxy.getLang().get(Lang.MESSAGE_UNSUPPORTED_CLIENT)); - return; - } - status.status = PlayStatusPacket.LOGIN_SUCCESS; - sendPacket(status, true); - - // Get the profile and read out the username! - profile = packet.decoded; - this.username = profile.username; - - // Okay @dktapps ;) - sendPacket(new ResourcePacksInfoPacket()); - - // now wait for response - } - - public void postLogin() { - sendPacket(new ResourcePackStackPacket()); - - loggedIn = true; - proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_CLIENT_CONNECTED, username, remoteAddress)); - if (proxy.getAuthMode().equals("online")) { - StartGamePacket pkStartGame = new StartGamePacket(); - pkStartGame.eid = 1L; // well we use 1 now - pkStartGame.rtid = 1L; - pkStartGame.dimension = 0; - pkStartGame.seed = 0; - pkStartGame.generator = 1; - pkStartGame.spawnPosition = new BlockPosition(0, 72, 0); - pkStartGame.position = new Vector3F(0f, 72f + Constants.PLAYER_HEAD_OFFSET, 0f); - pkStartGame.levelId = ""; - pkStartGame.worldName = "World"; - pkStartGame.defaultPlayerPermission = 2; - pkStartGame.commandsEnabled = true; - pkStartGame.premiumWorldTemplateId = ""; - sendPacket(pkStartGame, true); - - SetSpawnPositionPacket pkSpawn = new SetSpawnPositionPacket(); - pkSpawn.position = new BlockPosition(0, 72, 0); - sendPacket(pkSpawn, true); - - ChunkData data = new ChunkData(); - data.sections = new Section[16]; - for (int cy = 0; cy < 16; cy++) { - data.sections[cy] = new Section(); - if(cy < 6) { - Arrays.fill(data.sections[cy].blockIds, (byte) 1); - } - } - data.encode(); - sendPacket(new FullChunkDataPacket(0, 0, data.getBuffer())); - sendPacket(new FullChunkDataPacket(0, -1, data.getBuffer())); - sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer())); - sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer())); - - PlayStatusPacket pkStat = new PlayStatusPacket(); - pkStat.status = PlayStatusPacket.PLAYER_SPAWN; - sendPacket(pkStat, true); - - dataCache.put(CacheKey.AUTHENTICATION_STATE, "email"); - - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_NOTICE, username)); - sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_EMAIL)); - } else if (proxy.getAuthMode().equals("cls")) { - // CLS LOGIN! - if ((username.length() < 6 + 1 + 1) || (!username.contains("_"))) { - disconnect(proxy.getLang().get(Lang.MESSAGE_CLS_NOTICE)); - return; - } - String name = username.substring(0, username.length() - 7); - String keyCode = username.substring(username.length() - 6); - String resp = HTTP.performGetRequest("http://api.dragonet.org/cls/query_token.php?" - + String.format("username=%s&keycode=%s", name, keyCode)); - if (resp == null) { - disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, - proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE))); - proxy.getLogger() - .severe(proxy.getLang() - .get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)) - .replace("§c", "").replace("§0", "")); - return; - } - JsonElement json; - try { - JsonParser jsonParser = new JsonParser(); - json = jsonParser.parse(resp); - } catch (Exception e) { - disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR))); - proxy.getLogger() - .severe(proxy.getLang() - .get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR)) - .replace("§c", "").replace("§0", "")); - // Json parse error! - return; - } - JsonObject obj = json.getAsJsonObject(); - if (!obj.get("status").getAsString().equals("success")) { - disconnect(proxy.getLang().get(Lang.MESSAGE_CLS_NOTICE)); - return; - } - AuthenticationService authSvc = new AuthenticationService(obj.get("client").getAsString()); - authSvc.setUsername(obj.get("ign").getAsString()); - authSvc.setAccessToken(obj.get("token").getAsString()); - try { - authSvc.login(); - } catch (RequestException ex) { - ex.printStackTrace(); - disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR))); - return; - } - username = authSvc.getSelectedProfile().getName(); - HTTP.performGetRequest("http://api.dragonet.org/cls/update_token.php?" - + String.format("username=%s&oldtoken=%s&newtoken=%s", name, obj.get("token").getAsString(), - authSvc.getAccessToken())); - protocol = new MinecraftProtocol(authSvc.getSelectedProfile(), authSvc.getAccessToken()); - - proxy.getLogger().debug("Initially joining [" + proxy.getConfig().default_server + "]... "); - connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); - } else { - protocol = new MinecraftProtocol(username); - - proxy.getLogger().debug("Initially joining [" + proxy.getConfig().default_server + "]... "); - - /* - * // begin test things StartGamePacket pkStartGame = new StartGamePacket(); - * pkStartGame.eid = 0; //Use EID 0 for eaisier management pkStartGame.rtid = 0; - * pkStartGame.dimension = (byte) 0; pkStartGame.seed = 0; pkStartGame.generator - * = 1; pkStartGame.position = new Vector3F(0f, 72f, 0f); pkStartGame.levelId = - * ""; pkStartGame.worldName = "World"; pkStartGame.spawnPosition = new - * BlockPosition(0, 0, 0); pkStartGame.premiumWorldTemplateId = ""; - * sendPacket(pkStartGame, true); - * - * PlayStatusPacket pkStat = new PlayStatusPacket(); pkStat.status = - * PlayStatusPacket.PLAYER_SPAWN; sendPacket(pkStat, true); - * - * AdventureSettingsPacket adv = new AdventureSettingsPacket(); - * adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true); - * adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, true); sendPacket(adv); - * - * for(int x = -7; x < 8; x ++) { for(int z = -7; z < 8; z ++) { - * org.dragonet.proxy.protocol.type.chunk.ChunkData c = new ChunkData(); - * c.sections = new org.dragonet.proxy.protocol.type.chunk.Section[16]; for(int - * cy = 0; cy < 16; cy++) { c.sections[cy] = new - * org.dragonet.proxy.protocol.type.chunk.Section(); if(cy < 4) { - * Arrays.fill(c.sections[cy].blockIds, (byte)1); } } - * org.dragonet.proxy.protocol.packets.FullChunkDataPacket p = new - * org.dragonet.proxy.protocol.packets.FullChunkDataPacket(); p.x = x; p.z = z; - * c.encode(); p.payload = c.getBuffer(); sendPacket(p); } } - * - * // InventoryContentPacket content = new InventoryContentPacket(); // - * content.items = new org.dragonet.proxy.protocol.type.Slot[36]; // - * sendPacket(content); // end of test things - */ - - connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); - } - } - - public void setSpawned() { - spawned = true; - - if (cachedPackets != null) { - cachedPackets.stream().forEach(this::sendPacket); - - PlayStatusPacket play = new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN); - sendPacket(play); - - cachedPackets = null; - } - } - - public void sendChat(String chat) { - if (chat.contains("\n")) { - String[] lines = chat.split("\n"); - for (String line : lines) { - sendChat(line); - } - return; - } - TextPacket text = new TextPacket(); // raw - text.type = TextPacket.TYPE_RAW; - text.message = chat; - sendPacket(text, true); - } - - public void sendFakeBlock(int x, int y, int z, int id, int meta) { - UpdateBlockPacket pkBlock = new UpdateBlockPacket(); - pkBlock.id = id; - pkBlock.data = meta; - pkBlock.flags = UpdateBlockPacket.FLAG_NEIGHBORS; - pkBlock.blockPosition = new BlockPosition(x, y, z); - sendPacket(pkBlock, true); - } - - public void handlePacketBinary(byte[] packet) { - packetProcessor.putPacket(packet); - } - - public void putCachePacket(PEPacket p) { - if (p == null) - return; - if (spawned || cachedPackets == null) { - // System.out.println("Not caching since already spawned! "); - sendPacket(p); - return; - } - cachedPackets.add(p); - } - - public void onTick() { - entityCache.onTick(); - if (downstream != null) - downstream.onTick(); - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java deleted file mode 100644 index 8cb43d372..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator; - -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.cache.CachedWindow; - -public interface IInventoryTranslator { - /** - * Opens a window on MCPE. - * - * @param session - * @param window - * @return Can that window be opened on MCPE? - */ - boolean open(UpstreamSession session, CachedWindow window); - - /** - * Update a window's content. - * - * @param session - * @param window - */ - void updateContent(UpstreamSession session, CachedWindow window); - - /** - * Update a single slot in a window. - * - * @param session - * @param window - * @param slotIndex - */ - void updateSlot(UpstreamSession session, CachedWindow window, int slotIndex); -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java deleted file mode 100644 index e503646b7..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator; - -import com.github.steveice10.mc.protocol.data.message.ChatColor; -import com.github.steveice10.mc.protocol.data.message.ChatFormat; -import com.github.steveice10.mc.protocol.data.message.Message; - -import java.util.List; - -public final class MessageTranslator { - // vars - - // constructor - public MessageTranslator() { - - } - - // public - public static String translate(Message message) { - StringBuilder build = new StringBuilder(message.getText()); - for (Message msg : message.getExtra()) { - build.append(toMinecraftColor(msg.getStyle().getColor())); - build.append(toMinecraftFormat(msg.getStyle().getFormats())); - build.append(msg.getFullText()); - } - return build.toString(); - } - - public static String toMinecraftColor(ChatColor color) { - String base = "\u00a7"; - switch (color) { - case AQUA: - base += "b"; - break; - case BLACK: - base += "0"; - break; - case BLUE: - base += "9"; - break; - case DARK_AQUA: - base += "3"; - break; - case DARK_BLUE: - base += "1"; - break; - case DARK_GRAY: - base += "8"; - break; - case DARK_GREEN: - base += "2"; - break; - case DARK_PURPLE: - base += "5"; - break; - case DARK_RED: - base += "4"; - break; - case GOLD: - base += "6"; - break; - case GRAY: - base += "7"; - break; - case GREEN: - base += "a"; - break; - case LIGHT_PURPLE: - base += "d"; - break; - case RED: - base += "c"; - break; - case RESET: - base += "r"; - break; - case WHITE: - base += "f"; - break; - case YELLOW: - base += "e"; - break; - default: - break; - } - return base; - } - - // private - private static String toMinecraftFormat(List formats) { - String superBase = ""; - for (ChatFormat cf : formats) { - String base = "\u00a7"; - switch (cf) { - case BOLD: - base += "l"; - break; - case ITALIC: - base += "o"; - break; - case OBFUSCATED: - base += "k"; - break; - case STRIKETHROUGH: - base += "m"; - break; - case UNDERLINED: - base += "n"; - break; - default: - break; - } - superBase += base; - } - return superBase; - } -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java deleted file mode 100644 index a3d839953..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.inv; - -import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; - -import org.dragonet.inventory.InventoryType; -import org.dragonet.proxy.network.CacheKey; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.cache.CachedWindow; -import org.dragonet.proxy.network.translator.IInventoryTranslator; -import org.dragonet.proxy.network.translator.ItemBlockTranslator; -import org.dragonet.proxy.protocol.packets.BlockEntityDataPacket; -import org.dragonet.proxy.protocol.packets.ContainerOpenPacket; -import org.dragonet.proxy.protocol.packets.InventoryContentPacket; -import org.dragonet.proxy.protocol.type.Slot; -import org.dragonet.proxy.utilities.BlockPosition; - -public class ChestWindowTranslator implements IInventoryTranslator { - // vars - - // constructor - public ChestWindowTranslator() { - - } - - // public - public boolean open(UpstreamSession session, CachedWindow window) { - Position pos = new Position((int) session.getEntityCache().getClientEntity().x, - (int) session.getEntityCache().getClientEntity().y - 4, - (int) session.getEntityCache().getClientEntity().z); - session.getDataCache().put(CacheKey.WINDOW_OPENED_ID, window.windowId); - session.getDataCache().put(CacheKey.WINDOW_BLOCK_POSITION, pos); - session.sendFakeBlock(pos.getX(), pos.getY(), pos.getZ(), 54, 0); - CompoundTag tag = new CompoundTag(null); - tag.put(new StringTag("id", "Chest")); - tag.put(new IntTag("x", pos.getX())); - tag.put(new IntTag("y", pos.getY())); - tag.put(new IntTag("z", pos.getZ())); - BlockEntityDataPacket blockEntityData = new BlockEntityDataPacket(); - blockEntityData.blockPosition = new BlockPosition(pos.getX(), pos.getY(), pos.getZ()); - blockEntityData.tag = tag; - session.sendPacket(blockEntityData); - - ContainerOpenPacket pk = new ContainerOpenPacket(); - pk.windowId = window.windowId; - // pk. = window.size <= 27 ? (short)(InventoryType.SlotSize.CHEST & 0xFFFF) : - // (short)(InventoryType.SlotSize.DOUBLE_CHEST & 0xFFFF); - pk.type = window.size <= 27 ? InventoryType.PEInventory.CHEST : InventoryType.PEInventory.DOUBLE_CHEST; - pk.position = new BlockPosition(pos.getX(), pos.getY(), pos.getZ()); - session.sendPacket(pk); - return true; - } - - public void updateContent(UpstreamSession session, CachedWindow window) { - sendContent(session, window); - } - - public void updateSlot(UpstreamSession session, CachedWindow window, int slotIndex) { - sendContent(session, window);// TOO LAZY LOL - } - - private void sendContent(UpstreamSession session, CachedWindow win) { - InventoryContentPacket pk = new InventoryContentPacket(); - pk.windowId = (byte) (win.windowId & 0xFF); - pk.items = new Slot[win.slots.length]; - for (int i = 0; i < pk.items.length; i++) { - pk.items[i] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); - } - session.sendPacket(pk, true); - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java deleted file mode 100644 index a9f7bed06..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pc; - -import com.github.steveice10.mc.protocol.data.MagicValues; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; -import org.dragonet.PocketPotionEffect; -import org.dragonet.proxy.network.CacheKey; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.cache.CachedEntity; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.MobEffectPacket; -import org.dragonet.proxy.utilities.Logger; - -public class PCEntityEffectPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityEffectPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityEffectPacket packet) { - CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (entity == null) { - return null; - } - int effectId = MagicValues.value(Integer.class, packet.getEffect()); - - PocketPotionEffect effect = PocketPotionEffect.getByID(effectId); - if(effect == null) { - System.out.println("Unknown effect ID: "+effectId); - return null; - } - - MobEffectPacket eff = new MobEffectPacket(); - eff.rtid = packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID) ? 1L - : entity.proxyEid; - eff.effectId = effect.getEffect(); - if (entity.effects.contains(effectId)) { - eff.eventId = MobEffectPacket.EVENT_MODIFY; - } else { - eff.eventId = MobEffectPacket.EVENT_ADD; - entity.effects.add(effectId); - } - eff.amplifier = packet.getAmplifier(); - eff.duration = packet.getDuration(); - eff.particles = packet.getShowParticles(); - return new PEPacket[] { eff }; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java deleted file mode 100644 index a9e6283c6..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pc; - -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.cache.CachedEntity; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.MoveEntityPacket; -import org.dragonet.proxy.utilities.Constants; -import org.dragonet.proxy.utilities.Vector3F; - -public class PCEntityPositionRotationPacketTranslator - implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityPositionRotationPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityPositionRotationPacket packet) { - CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (e == null) { - return null; - } - - e.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), - packet.getPitch()); - - MoveEntityPacket pk = new MoveEntityPacket(); - pk.rtid = e.proxyEid; - pk.yaw = (byte) (e.yaw / (360d / 256d)); - pk.headYaw = (byte) (e.yaw / (360d / 256d)); - pk.pitch = (byte) (e.pitch / (360d / 256d)); - pk.position = new Vector3F((float) e.x, (float) e.y, (float) e.z); - if (e.player) { - pk.position.y += Constants.PLAYER_HEAD_OFFSET; - } - return new PEPacket[] { pk }; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java deleted file mode 100644 index 04796625a..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pc; - -import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.LevelEventPacket; -import org.dragonet.proxy.protocol.packets.SetPlayerGameTypePacket; - -public class PCNotifyClientPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCNotifyClientPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerNotifyClientPacket packet) { - switch (packet.getNotification()) { - case CHANGE_GAMEMODE: - GameMode gm = (GameMode) packet.getValue(); - SetPlayerGameTypePacket pk = new SetPlayerGameTypePacket(); - if (gm == GameMode.CREATIVE) { - pk.gamemode = 1; - } else { - pk.gamemode = 0; - } - return new PEPacket[] { pk }; - case START_RAIN: - LevelEventPacket evtStartRain = new LevelEventPacket(); - evtStartRain.eventId = LevelEventPacket.EVENT_START_RAIN; - return new PEPacket[] { evtStartRain }; - case STOP_RAIN: - LevelEventPacket evtStopRain = new LevelEventPacket(); - evtStopRain.eventId = LevelEventPacket.EVENT_STOP_RAIN; - return new PEPacket[] { evtStopRain }; - } - return null; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java deleted file mode 100644 index 5d6d122f2..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.dragonet.proxy.network.translator.pc; - -import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.cache.CachedEntity; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; -import org.dragonet.proxy.entity.EntityType; -import org.dragonet.proxy.entity.meta.type.ByteArrayMeta; -import org.dragonet.proxy.network.translator.EntityMetaTranslator; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.AddPlayerPacket; -import org.dragonet.proxy.protocol.packets.PlayerSkinPacket; -import org.dragonet.proxy.utilities.Constants; -import org.dragonet.proxy.utilities.Vector3F; - -public class PCSpawnPlayerPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCSpawnPlayerPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerSpawnPlayerPacket packet) { - try { - CachedEntity entity = session.getEntityCache().newPlayer(packet); - - if (session.isSpawned()) - { - PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId); - AddPlayerPacket pkAddPlayer = new AddPlayerPacket(); - pkAddPlayer.eid = entity.proxyEid; - pkAddPlayer.rtid = entity.proxyEid; - pkAddPlayer.username = playerListEntry.getProfile().getName(); - - pkAddPlayer.uuid = packet.getUUID(); - - pkAddPlayer.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, (float) packet.getZ()); - pkAddPlayer.motion = Vector3F.ZERO; - pkAddPlayer.yaw = packet.getYaw(); - pkAddPlayer.pitch = packet.getPitch(); - - pkAddPlayer.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, EntityType.PLAYER); - pkAddPlayer.meta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta(playerListEntry.getProfile().getName())); //hacky for now - - PlayerSkinPacket skin = new PlayerSkinPacket(packet.getUUID()); - - return new PEPacket[] { pkAddPlayer, skin }; - } - return null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java deleted file mode 100644 index d4f29d5c0..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pc; - -import com.github.steveice10.mc.protocol.data.game.world.block.UpdatedTileType; -import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; - -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.translator.IPCPacketTranslator; -import org.dragonet.proxy.protocol.PEPacket; -import org.dragonet.proxy.protocol.packets.BlockEntityDataPacket; - -public class PCUpdateSignPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCUpdateSignPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerUpdateTileEntityPacket packet) { - if (packet.getType().equals(UpdatedTileType.SIGN)) { - CompoundTag root = new CompoundTag(null); - root.put(new StringTag("id", "Sign")); - root.put(new IntTag("x", packet.getPosition().getX())); - root.put(new IntTag("y", packet.getPosition().getY())); - root.put(new IntTag("z", packet.getPosition().getZ())); - root.put(new StringTag("Text1", (String) packet.getNBT().get("Text1").getValue())); - root.put(new StringTag("Text2", (String) packet.getNBT().get("Text2").getValue())); - root.put(new StringTag("Text3", (String) packet.getNBT().get("Text3").getValue())); - root.put(new StringTag("Text4", (String) packet.getNBT().get("Text4").getValue())); - - BlockEntityDataPacket data = new BlockEntityDataPacket(); - data.tag = root; - // packet.getPosition().getX(), packet.getPosition().getY(), - // packet.getPosition().getZ(), root - return new PEPacket[] { data }; - } else { - return null; - } - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java deleted file mode 100644 index 018916cc7..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pe; - -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; -import com.github.steveice10.packetlib.packet.Packet; -import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.network.CacheKey; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.translator.IPEPacketTranslator; -import org.dragonet.proxy.protocol.packets.TextPacket; -import org.dragonet.proxy.utilities.PatternChecker; - -public class PEChatPacketTranslator implements IPEPacketTranslator { - // vars - - // constructor - public PEChatPacketTranslator() { - - } - - // public - public Packet[] translate(UpstreamSession session, TextPacket packet) { - if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) { - if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("email")) { - if (!PatternChecker.matchEmail(packet.message.trim())) { - session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - return null; - } - session.getDataCache().put(CacheKey.AUTHENTICATION_EMAIL, packet.message.trim()); - session.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "password"); - session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_PASSWORD)); - } else if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("password")) { - if (session.getDataCache().get(CacheKey.AUTHENTICATION_EMAIL) == null || packet.message.equals(" ")) { - session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); - return null; - } - session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGIN_IN)); - session.getDataCache().remove(CacheKey.AUTHENTICATION_STATE); - session.authenticate(packet.message); // We NEVER cache password for better security. - } - return null; - } - - ClientChatPacket pk = new ClientChatPacket(packet.message); - return new Packet[] { pk }; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java deleted file mode 100644 index 65526e6d3..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * GNU LESSER GENERAL PUBLIC LICENSE - * Version 3, 29 June 2007 - * - * Copyright (C) 2007 Free Software Foundation, Inc. - * Everyone is permitted to copy and distribute verbatim copies - * of this license document, but changing it is not allowed. - * - * You can view LICENCE file for details. - * - * @author The Dragonet Team - */ -package org.dragonet.proxy.network.translator.pe; - -import com.github.steveice10.mc.protocol.data.MagicValues; -import com.github.steveice10.mc.protocol.data.game.ClientRequest; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; -import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState; -import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket; -import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket; -import com.github.steveice10.packetlib.packet.Packet; -import org.dragonet.proxy.network.CacheKey; -import org.dragonet.proxy.network.UpstreamSession; -import org.dragonet.proxy.network.translator.IPEPacketTranslator; -import org.dragonet.proxy.protocol.packets.PlayerActionPacket; - -public class PEPlayerActionPacketTranslator implements IPEPacketTranslator { - // vars - - // constructor - public PEPlayerActionPacketTranslator() { - - } - - // public - public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) { - if (packet.action == PlayerActionPacket.ACTION_RESPAWN) { - return new Packet[] { new ClientRequestPacket(ClientRequest.RESPAWN) }; - } - if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) { - ClientPlayerStatePacket stat = new ClientPlayerStatePacket( - (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING); - return new Packet[] { stat }; - } - if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) { - ClientPlayerStatePacket stat = new ClientPlayerStatePacket( - (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING); - return new Packet[] { stat }; - } - if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) { - ClientPlayerStatePacket stat = new ClientPlayerStatePacket( - (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING); - return new Packet[] { stat }; - } - if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) { - ClientPlayerStatePacket stat = new ClientPlayerStatePacket( - (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING); - return new Packet[] { stat }; - } - if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) { - ClientPlayerStatePacket stat = new ClientPlayerStatePacket( - (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED); - return new Packet[] { stat }; - } - if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) { - ClientPlayerActionPacket act = new ClientPlayerActionPacket( - com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, - new Position(0, 0, 0), BlockFace.UP); - return new Packet[] { act }; - } - if (packet.action == PlayerActionPacket.ACTION_START_BREAK) { - ClientPlayerActionPacket act = new ClientPlayerActionPacket( - com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, - new Position(packet.position.x, packet.position.y, packet.position.z), - MagicValues.key(BlockFace.class, packet.face)); - session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition()); - return new Packet[] { act }; - } - if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) { - if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) { - ClientPlayerActionPacket act = new ClientPlayerActionPacket( - com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, - (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), - MagicValues.key(BlockFace.class, packet.face)); - return new Packet[] { act }; - } - if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) { - ClientPlayerActionPacket act = new ClientPlayerActionPacket( - com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, - (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), - MagicValues.key(BlockFace.class, packet.face)); - return new Packet[] { act }; - } - } - return null; - } - - // private - -} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java deleted file mode 100644 index 3989a1370..000000000 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java +++ /dev/null @@ -1,241 +0,0 @@ -//package cn.nukkit.inventory.transaction; -// -//import cn.nukkit.Player; -//import cn.nukkit.Server; -//import cn.nukkit.event.inventory.InventoryTransactionEvent; -//import cn.nukkit.inventory.Inventory; -//import cn.nukkit.inventory.transaction.action.InventoryAction; -//import cn.nukkit.inventory.transaction.action.SlotChangeAction; -//import cn.nukkit.item.Item; -//import cn.nukkit.utils.MainLogger; -// -//import java.util.*; -//import java.util.Map.Entry; -// -///** -// * @author CreeperFace -// */ -//public class SimpleInventoryTransaction implements InventoryTransaction { -// -// private long creationTime; -// protected boolean hasExecuted; -// -// protected Set inventories = new HashSet<>(); -// -// protected Set actions = new HashSet<>(); -// -// public SimpleInventoryTransaction(Player source, List actions) { -// creationTime = System.currentTimeMillis(); -// -// for (InventoryAction action : actions) { -// this.addAction(action); -// } -// } -// -// @Override -// public long getCreationTime() { -// return creationTime; -// } -// -// @Override -// public Set getInventories() { -// return inventories; -// } -// -// @Override -// public Set getActions() { -// return actions; -// } -// -// public void addAction(InventoryAction action) { -// if (this.actions.contains(action)) { -// return; -// } -// -// if (action instanceof SlotChangeAction) { -// this.inventories.add(((SlotChangeAction) action).getInventory()); -// } -// -// this.actions.add(action); -// } -// -// protected boolean matchItems(List needItems, List haveItems) { -// for (InventoryAction action : this.actions) { -// if (action.getTargetItem().getId() != Item.AIR) { -// needItems.add(action.getTargetItem()); -// } -// -// if (action.getSourceItem().getId() != Item.AIR) { -// haveItems.add(action.getSourceItem()); -// } -// } -// -// for (Item needItem : new ArrayList<>(needItems)) { -// for (Item haveItem : new ArrayList<>(haveItems)) { -// if (needItem.equals(haveItem)) { -// int amount = Math.min(haveItem.getCount(), needItem.getCount()); -// needItem.setCount(needItem.getCount() - amount); -// haveItem.setCount(haveItem.getCount() - amount); -// if (haveItem.getCount() == 0) { -// haveItems.remove(haveItem); -// } -// if (needItem.getCount() == 0) { -// needItems.remove(needItem); -// break; -// } -// } -// } -// } -// -// return haveItems.isEmpty() && needItems.isEmpty(); -// } -// -// /** -// * Iterates over SlotChangeActions in this transaction and compacts any which refer to the same inventorySlot in the same -// * inventory so they can be correctly handled. -// *

-// * Under normal circumstances, the same inventorySlot would never be changed more than once in a single transaction. However, -// * due to the way things like the crafting grid are "implemented" in MCPE 1.2 (a.k.a. hacked-in), we may get -// * multiple inventorySlot changes referring to the same inventorySlot in a single transaction. These multiples are not even guaranteed -// * to be in the correct order (inventorySlot splitting in the crafting grid for example, causes the actions to be sent in the -// * wrong order), so this method also tries to chain them into order. -// * -// * @return bool -// */ -// protected boolean squashDuplicateSlotChanges() { -// Map> slotChanges = new HashMap<>(); -// -// for (InventoryAction action : this.actions) { -// if (action instanceof SlotChangeAction) { -// int hash = Objects.hash(((SlotChangeAction) action).getInventory(), ((SlotChangeAction) action).getSlot()); -// -// List list = slotChanges.get(hash); -// if (list == null) { -// list = new ArrayList<>(); -// } -// -// list.add((SlotChangeAction) action); -// -// slotChanges.put(hash, list); -// } -// } -// -// for (Entry> entry : new ArrayList<>(slotChanges.entrySet())) { -// int hash = entry.getKey(); -// List list = entry.getValue(); -// -// if (list.size() == 1) { //No need to compact inventorySlot changes if there is only one on this inventorySlot -// slotChanges.remove(hash); -// continue; -// } -// -// List originalList = new ArrayList<>(list); -// -// SlotChangeAction originalAction = null; -// Item lastTargetItem = null; -// -// for (int i = 0; i < list.size(); i++) { -// SlotChangeAction action = list.get(i); -// -// if (action.isValid(this.source)) { -// originalAction = action; -// lastTargetItem = action.getTargetItem(); -// list.remove(i); -// break; -// } -// } -// -// if (originalAction == null) { -// return false; //Couldn't find any actions that had a source-item matching the current inventory inventorySlot -// } -// -// int sortedThisLoop; -// -// do { -// sortedThisLoop = 0; -// for (int i = 0; i < list.size(); i++) { -// SlotChangeAction action = list.get(i); -// -// Item actionSource = action.getSourceItem(); -// if (actionSource.equalsExact(lastTargetItem)) { -// lastTargetItem = action.getTargetItem(); -// list.remove(i); -// sortedThisLoop++; -// } -// else if (actionSource.equals(lastTargetItem)) { -// lastTargetItem.count -= actionSource.count; -// list.remove(i); -// if (lastTargetItem.count == 0) sortedThisLoop++; -// } -// } -// } while (sortedThisLoop > 0); -// -// if (list.size() > 0) { //couldn't chain all the actions together -// MainLogger.getLogger().debug("Failed to compact " + originalList.size() + " actions for " + this.source.getName()); -// return false; -// } -// -// for (SlotChangeAction action : originalList) { -// this.actions.remove(action); -// } -// -// this.addAction(new SlotChangeAction(originalAction.getInventory(), originalAction.getSlot(), originalAction.getSourceItem(), lastTargetItem)); -// -// MainLogger.getLogger().debug("Successfully compacted " + originalList.size() + " actions for " + this.source.getName()); -// } -// -// return true; -// } -// -// public boolean canExecute() { -// this.squashDuplicateSlotChanges(); -// -// List haveItems = new ArrayList<>(); -// List needItems = new ArrayList<>(); -// return matchItems(needItems, haveItems) && this.actions.size() > 0 && haveItems.size() == 0 && needItems.size() == 0; -// } -// -// /** -// * @return bool -// */ -// public boolean execute() { -// if (this.hasExecuted() || !this.canExecute()) { -// return false; -// } -// -// InventoryTransactionEvent ev = new InventoryTransactionEvent(this); -// Server.getInstance().getPluginManager().callEvent(ev); -// if (ev.isCancelled()) { -// this.handleFailed(); -// return true; -// } -// -// for (InventoryAction action : this.actions) { -// if (!action.onPreExecute(this.source)) { -// this.handleFailed(); -// return true; -// } -// } -// -// for (InventoryAction action : this.actions) { -// if (action.execute(this.source)) { -// action.onExecuteSuccess(this.source); -// } else { -// action.onExecuteFail(this.source); -// } -// } -// -// this.hasExecuted = true; -// return true; -// } -// -// protected void handleFailed() { -// for (InventoryAction action : this.actions) { -// action.onExecuteFail(this.source); -// } -// } -// -// public boolean hasExecuted() { -// return this.hasExecuted; -// } -//} diff --git a/proxy/src/main/java/org/dragonet/proxy/DesktopServer.java b/src/main/java/org/dragonet/proxy/DesktopServer.java similarity index 69% rename from proxy/src/main/java/org/dragonet/proxy/DesktopServer.java rename to src/main/java/org/dragonet/proxy/DesktopServer.java index 9b07693cf..b8d0744c2 100644 --- a/proxy/src/main/java/org/dragonet/proxy/DesktopServer.java +++ b/src/main/java/org/dragonet/proxy/DesktopServer.java @@ -16,18 +16,12 @@ import org.dragonet.proxy.configuration.RemoteServer; public class DesktopServer extends RemoteServer { - // vars - // constructor - public DesktopServer() { - super(); - } - - // public - public static DesktopServer deserialize(Map map) { - return (DesktopServer) delicatedDeserialize(new DesktopServer(), map); - } - - // private + public DesktopServer() { + super(); + } + public static DesktopServer deserialize(Map map) { + return (DesktopServer) delicatedDeserialize(new DesktopServer(), map); + } } diff --git a/src/main/java/org/dragonet/proxy/DragonProxy.java b/src/main/java/org/dragonet/proxy/DragonProxy.java new file mode 100644 index 000000000..c6d855724 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/DragonProxy.java @@ -0,0 +1,209 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import org.dragonet.proxy.network.SessionRegister; +import org.dragonet.proxy.network.RaknetInterface; +import org.dragonet.proxy.configuration.Lang; +import org.dragonet.proxy.configuration.ServerConfig; +import org.dragonet.proxy.utilities.*; +import org.dragonet.proxy.commands.CommandRegister; +import org.dragonet.proxy.commands.ConsoleCommandReader; + +import org.yaml.snakeyaml.Yaml; + +public class DragonProxy { + + public static final boolean IS_RELEASE = false; // DO NOT CHANGE, ONLY ON PRODUCTION + + private Logger logger; + private final TickerThread ticker = new TickerThread(this); + private ServerConfig config; + private Lang lang; + private SessionRegister sessionRegister; + private RaknetInterface network; + private boolean shuttingDown; + private ScheduledExecutorService generalThreadPool; + private CommandRegister commandRegister; + private String authMode; + private ConsoleCommandReader console; + private String motd; + private boolean debug = false; + + public static void main(String[] args) { + new DragonProxy().run(args); + } + + public Logger getLogger() { + return logger; + } + + public ServerConfig getConfig() { + return config; + } + + public Lang getLang() { + return lang; + } + + public SessionRegister getSessionRegister() { + return sessionRegister; + } + + public RaknetInterface getNetwork() { + return network; + } + + public boolean isShuttingDown() { + return shuttingDown; + } + + public ScheduledExecutorService getGeneralThreadPool() { + return generalThreadPool; + } + + public CommandRegister getCommandRegister() { + return commandRegister; + } + + public String getAuthMode() { + return authMode; + } + + public boolean isDebug() { + return debug; + } + + public void run(String[] args) { + logger = new Logger(this); + + try { + File fileConfig = new File("config.yml"); + if (!fileConfig.exists()) { + // Create default config + FileOutputStream fos = new FileOutputStream(fileConfig); + InputStream ins = DragonProxy.class.getResourceAsStream("/config.yml"); + int data; + while ((data = ins.read()) != -1) { + fos.write(data); + } + ins.close(); + fos.close(); + } + config = new Yaml().loadAs(new FileInputStream(fileConfig), ServerConfig.class); + } catch (IOException ex) { + logger.severe("Failed to load configuration file! Make sure the file is writable."); + ex.printStackTrace(); + return; + } + + // Initialize console command reader + console = new ConsoleCommandReader(this); + console.startConsole(); + + // Should we save console log? Set it in config file + /* + * if(config.isLog_console()){ console.startFile("console.log"); + * logger.info("Saving console output enabled"); } else { + * logger.info("Saving console output disabled"); } + */ + // Put at the top instead + if (!IS_RELEASE) { + logger.warning( + MCColor.YELLOW + "This is a development build. It may contain bugs. Do not use on production.\n"); + } + + // Check for startup arguments + checkArguments(args); + + // Load language file + try { + lang = new Lang(config.lang); + } catch (IOException ex) { + logger.severe("Failed to load language file: " + config.lang + "!"); + ex.printStackTrace(); + return; + } + // Load some more stuff + logger.info(lang.get(Lang.INIT_LOADING, Versioning.RELEASE_VERSION)); + logger.info(lang.get(Lang.INIT_MC_PC_SUPPORT, Versioning.MINECRAFT_PC_VERSION)); + logger.info(lang.get(Lang.INIT_MC_PE_SUPPORT, Versioning.MINECRAFT_PE_VERSION)); + authMode = config.mode.toLowerCase(); + if (!authMode.equals("cls") && !authMode.equals("online") && !authMode.equals("offline")) { + logger.severe("Invalid login 'mode' option detected, must be cls/online/offline. You set it to '" + authMode + + "'! "); + return; + } + + // Init session and command stuff + sessionRegister = new SessionRegister(this); + commandRegister = new CommandRegister(this); + + // Create thread pool + logger.info(lang.get(Lang.INIT_CREATING_THREAD_POOL, config.thread_pool_size)); + generalThreadPool = Executors.newScheduledThreadPool(config.thread_pool_size); + + // Bind + logger.info(lang.get(Lang.INIT_BINDING, config.udp_bind_ip, config.udp_bind_port)); + // RakNet.enableLogging(); + network = new RaknetInterface(this, config.udp_bind_ip, // IP + config.udp_bind_port); // Port + + // MOTD + motd = config.motd; + motd = motd.replace("&", "\u00a7"); + + network.setBroadcastName(motd, 1, 2); + ticker.start(); + logger.info(lang.get(Lang.INIT_DONE)); + } + + public void onTick() { + // network.onTick(); + sessionRegister.onTick(); + } + + public void checkArguments(String[] args) { + for (String arg : args) { + if (arg.toLowerCase().contains("--debug")) { + debug = true; + getLogger().debug = true; + logger.info(MCColor.DARK_AQUA + "Proxy is running in debug mode."); + } + } + } + + public void shutdown() { + logger.info(lang.get(Lang.SHUTTING_DOWN)); + + debug = false; + this.shuttingDown = true; + network.shutdown(); + try { + Thread.sleep(2000); // Wait for all clients disconnected + } catch (Exception ex) { + System.out.println("Exception while shutting down!"); + ex.printStackTrace(); + } + System.out.println("Goodbye!"); + System.exit(0); + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/PocketServer.java b/src/main/java/org/dragonet/proxy/PocketServer.java similarity index 69% rename from proxy/src/main/java/org/dragonet/proxy/PocketServer.java rename to src/main/java/org/dragonet/proxy/PocketServer.java index b71599557..347762212 100644 --- a/proxy/src/main/java/org/dragonet/proxy/PocketServer.java +++ b/src/main/java/org/dragonet/proxy/PocketServer.java @@ -16,18 +16,12 @@ import org.dragonet.proxy.configuration.RemoteServer; public class PocketServer extends RemoteServer { - // vars - // constructor - public PocketServer() { - super(); - } - - // public - public static PocketServer deserialize(Map map) { - return (PocketServer) delicatedDeserialize(new PocketServer(), map); - } - - // private + public PocketServer() { + super(); + } + public static PocketServer deserialize(Map map) { + return (PocketServer) delicatedDeserialize(new PocketServer(), map); + } } diff --git a/src/main/java/org/dragonet/proxy/TickerThread.java b/src/main/java/org/dragonet/proxy/TickerThread.java new file mode 100644 index 000000000..8b3a52caf --- /dev/null +++ b/src/main/java/org/dragonet/proxy/TickerThread.java @@ -0,0 +1,42 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy; + +public class TickerThread extends Thread { + + private final DragonProxy proxy; + + public TickerThread(DragonProxy proxy) { + this.proxy = proxy; + setDaemon(true); + } + + @Override + public void run() { + long time; + while (!proxy.isShuttingDown()) { + time = System.currentTimeMillis(); + proxy.onTick(); + time = System.currentTimeMillis() - time; + if (time >= 50) { + continue; + } else { + try { + Thread.sleep(50 - time); + } catch (InterruptedException ex) { + return; + } + } + } + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/Command.java b/src/main/java/org/dragonet/proxy/commands/Command.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/Command.java rename to src/main/java/org/dragonet/proxy/commands/Command.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/CommandRegister.java b/src/main/java/org/dragonet/proxy/commands/CommandRegister.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/CommandRegister.java rename to src/main/java/org/dragonet/proxy/commands/CommandRegister.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java b/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java rename to src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/IConsoleCommand.java b/src/main/java/org/dragonet/proxy/commands/IConsoleCommand.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/IConsoleCommand.java rename to src/main/java/org/dragonet/proxy/commands/IConsoleCommand.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java b/src/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java rename to src/main/java/org/dragonet/proxy/commands/defaults/HelpCommand.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/defaults/KillCommand.java b/src/main/java/org/dragonet/proxy/commands/defaults/KillCommand.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/defaults/KillCommand.java rename to src/main/java/org/dragonet/proxy/commands/defaults/KillCommand.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/defaults/StopCommand.java b/src/main/java/org/dragonet/proxy/commands/defaults/StopCommand.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/defaults/StopCommand.java rename to src/main/java/org/dragonet/proxy/commands/defaults/StopCommand.java diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/defaults/TestCommand.java b/src/main/java/org/dragonet/proxy/commands/defaults/TestCommand.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/commands/defaults/TestCommand.java rename to src/main/java/org/dragonet/proxy/commands/defaults/TestCommand.java diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/IConfigurationSerializable.java b/src/main/java/org/dragonet/proxy/configuration/IConfigurationSerializable.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/configuration/IConfigurationSerializable.java rename to src/main/java/org/dragonet/proxy/configuration/IConfigurationSerializable.java diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/Lang.java b/src/main/java/org/dragonet/proxy/configuration/Lang.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/configuration/Lang.java rename to src/main/java/org/dragonet/proxy/configuration/Lang.java diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/PropertiesConfig.java b/src/main/java/org/dragonet/proxy/configuration/PropertiesConfig.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/configuration/PropertiesConfig.java rename to src/main/java/org/dragonet/proxy/configuration/PropertiesConfig.java diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/RemoteServer.java b/src/main/java/org/dragonet/proxy/configuration/RemoteServer.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/configuration/RemoteServer.java rename to src/main/java/org/dragonet/proxy/configuration/RemoteServer.java diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/ServerConfig.java b/src/main/java/org/dragonet/proxy/configuration/ServerConfig.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/configuration/ServerConfig.java rename to src/main/java/org/dragonet/proxy/configuration/ServerConfig.java diff --git a/proxy/src/main/java/org/dragonet/PocketPotionEffect.java b/src/main/java/org/dragonet/proxy/data/PocketPotionEffect.java similarity index 99% rename from proxy/src/main/java/org/dragonet/PocketPotionEffect.java rename to src/main/java/org/dragonet/proxy/data/PocketPotionEffect.java index 9ba10e995..909dacf46 100644 --- a/proxy/src/main/java/org/dragonet/PocketPotionEffect.java +++ b/src/main/java/org/dragonet/proxy/data/PocketPotionEffect.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet; +package org.dragonet.proxy.data; import java.util.HashMap; diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/EntityType.java b/src/main/java/org/dragonet/proxy/data/entity/EntityType.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/entity/EntityType.java rename to src/main/java/org/dragonet/proxy/data/entity/EntityType.java index bd30b07f8..5569615aa 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/EntityType.java +++ b/src/main/java/org/dragonet/proxy/data/entity/EntityType.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity; +package org.dragonet.proxy.data.entity; import java.util.HashMap; import java.util.Map; diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/PEEntityAttribute.java b/src/main/java/org/dragonet/proxy/data/entity/PEEntityAttribute.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/entity/PEEntityAttribute.java rename to src/main/java/org/dragonet/proxy/data/entity/PEEntityAttribute.java index 9137cafc6..fce7afb3c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/PEEntityAttribute.java +++ b/src/main/java/org/dragonet/proxy/data/entity/PEEntityAttribute.java @@ -1,4 +1,4 @@ -package org.dragonet.proxy.entity; +package org.dragonet.proxy.data.entity; import java.util.HashMap; diff --git a/src/main/java/org/dragonet/proxy/data/entity/meta/EntityMetaData.java b/src/main/java/org/dragonet/proxy/data/entity/meta/EntityMetaData.java new file mode 100644 index 000000000..50fd12250 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/EntityMetaData.java @@ -0,0 +1,225 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.data.entity.meta; + +import java.util.HashMap; +import java.util.Map; +import org.dragonet.proxy.data.entity.meta.type.ByteArrayMeta; +import org.dragonet.proxy.data.entity.meta.type.FloatMeta; +import org.dragonet.proxy.data.entity.meta.type.LongMeta; +import org.dragonet.proxy.data.entity.meta.type.ShortMeta; + +import org.dragonet.proxy.utilities.BinaryStream; +import org.dragonet.proxy.utilities.BlockPosition; + +public class EntityMetaData extends BinaryStream { + + public static class Constants { + + public static final int DATA_TYPE_BYTE = 0; + public static final int DATA_TYPE_SHORT = 1; + public static final int DATA_TYPE_INT = 2; + public static final int DATA_TYPE_FLOAT = 3; + public static final int DATA_TYPE_STRING = 4; + public static final int DATA_TYPE_SLOT = 5; + public static final int DATA_TYPE_POS = 6; + public static final int DATA_TYPE_LONG = 7; + public static final int DATA_TYPE_VECTOR3F = 8; + + public static final int DATA_FLAGS = 0; + public static final int DATA_HEALTH = 1; // int (minecart/boat) + public static final int DATA_VARIANT = 2; // int + public static final int DATA_COLOR = 3, DATA_COLOUR = 3; // byte + public static final int DATA_NAMETAG = 4; // string + public static final int DATA_OWNER_EID = 5; // long + public static final int DATA_TARGET_EID = 6; // long + public static final int DATA_AIR = 7; // short + public static final int DATA_POTION_COLOR = 8; // int (ARGB!) + public static final int DATA_POTION_AMBIENT = 9; // byte + /* 10 (byte) */ + public static final int DATA_HURT_TIME = 11; // int (minecart/boat) + public static final int DATA_HURT_DIRECTION = 12; // int (minecart/boat) + public static final int DATA_PADDLE_TIME_LEFT = 13; // float + public static final int DATA_PADDLE_TIME_RIGHT = 14; // float + public static final int DATA_EXPERIENCE_VALUE = 15; // int (xp orb) + public static final int DATA_MINECART_DISPLAY_BLOCK = 16; // int (id | (data << 16)) + public static final int DATA_MINECART_DISPLAY_OFFSET = 17; // int + public static final int DATA_MINECART_HAS_DISPLAY = 18; // byte (must be 1 for minecart to show block inside) + // TODO: add more properties + public static final int DATA_ENDERMAN_HELD_ITEM_ID = 23; // short + public static final int DATA_ENDERMAN_HELD_ITEM_DAMAGE = 24; // short + public static final int DATA_ENTITY_AGE = 25; // short + /* + * 27 (byte) player-specific flags 28 (int) player "index"? 29 (block coords) + * bed position + */ + public static final int DATA_BED_POSITION = 29; + public static final int DATA_FIREBALL_POWER_X = 30; // float + public static final int DATA_FIREBALL_POWER_Y = 31; + public static final int DATA_FIREBALL_POWER_Z = 32; + /* + * 33 (unknown) 34 (float) fishing bobber 35 (float) fishing bobber 36 (float) + * fishing bobber + */ + public static final int DATA_POTION_AUX_VALUE = 37; // short + public static final int DATA_LEAD_HOLDER_EID = 38; // long + public static final int DATA_SCALE = 39; // float + public static final int DATA_INTERACTIVE_TAG = 40; // string (button text) + public static final int DATA_NPC_SKIN_ID = 41; // string + public static final int DATA_URL_TAG = 42; // string + public static final int DATA_MAX_AIR = 43; // short + public static final int DATA_MARK_VARIANT = 44; // int + /* + * 45 (byte) container stuff 46 (int) container stuff 47 (int) container stuff + */ + public static final int DATA_BLOCK_TARGET = 48; // block coords (ender crystal) + public static final int DATA_WITHER_INVULNERABLE_TICKS = 49; // int + public static final int DATA_WITHER_TARGET_1 = 50; // long + public static final int DATA_WITHER_TARGET_2 = 51; // long + public static final int DATA_WITHER_TARGET_3 = 52; // long + /* 53 (short) */ + public static final int DATA_BOUNDING_BOX_WIDTH = 54; // float + public static final int DATA_BOUNDING_BOX_HEIGHT = 55; // float + public static final int DATA_FUSE_LENGTH = 56; // int + public static final int DATA_RIDER_SEAT_POSITION = 57; // vector3f + public static final int DATA_RIDER_ROTATION_LOCKED = 58; // byte + public static final int DATA_RIDER_MAX_ROTATION = 59; // float + public static final int DATA_RIDER_MIN_ROTATION = 60; // float + public static final int DATA_AREA_EFFECT_CLOUD_RADIUS = 61; // float + public static final int DATA_AREA_EFFECT_CLOUD_WAITING = 62; // int + public static final int DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63; // int + /* 64 (int) shulker-related */ + public static final int DATA_SHULKER_ATTACH_FACE = 65; // byte + /* 66 (short) shulker-related */ + public static final int DATA_SHULKER_ATTACH_POS = 67; // block coords + public static final int DATA_TRADING_PLAYER_EID = 68; // long + /* 70 (byte) command-block */ + public static final int DATA_COMMAND_BLOCK_COMMAND = 71; // string + public static final int DATA_COMMAND_BLOCK_LAST_OUTPUT = 72; // string + public static final int DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73; // byte + public static final int DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74; // byte + public static final int DATA_STRENGTH = 75; // int + public static final int DATA_MAX_STRENGTH = 76; // int + /* + * 77 (int) 78 (int) + */ + public static final int DATA_FLAG_ONFIRE = 0; + public static final int DATA_FLAG_SNEAKING = 1; + public static final int DATA_FLAG_RIDING = 2; + public static final int DATA_FLAG_SPRINTING = 3; + public static final int DATA_FLAG_ACTION = 4; + public static final int DATA_FLAG_INVISIBLE = 5; + public static final int DATA_FLAG_TEMPTED = 6; + public static final int DATA_FLAG_INLOVE = 7; + public static final int DATA_FLAG_SADDLED = 8; + public static final int DATA_FLAG_POWERED = 9; + public static final int DATA_FLAG_IGNITED = 10; + public static final int DATA_FLAG_BABY = 11; + public static final int DATA_FLAG_CONVERTING = 12; + public static final int DATA_FLAG_CRITICAL = 13; + public static final int DATA_FLAG_CAN_SHOW_NAMETAG = 14; + public static final int DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15; + public static final int DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16; + public static final int DATA_FLAG_SILENT = 17; + public static final int DATA_FLAG_WALLCLIMBING = 18; + public static final int DATA_FLAG_CAN_CLIMB = 19; + public static final int DATA_FLAG_SWIMMER = 20; + public static final int DATA_FLAG_CAN_FLY = 21; + public static final int DATA_FLAG_RESTING = 22; + public static final int DATA_FLAG_SITTING = 23; + public static final int DATA_FLAG_ANGRY = 24; + public static final int DATA_FLAG_INTERESTED = 25; + public static final int DATA_FLAG_CHARGED = 26; + public static final int DATA_FLAG_TAMED = 27; + public static final int DATA_FLAG_LEASHED = 28; + public static final int DATA_FLAG_SHEARED = 29; + public static final int DATA_FLAG_GLIDING = 30; + public static final int DATA_FLAG_ELDER = 31; + public static final int DATA_FLAG_MOVING = 32; + public static final int DATA_FLAG_BREATHING = 33; + public static final int DATA_FLAG_CHESTED = 34; + public static final int DATA_FLAG_STACKABLE = 35; + public static final int DATA_FLAG_SHOWBASE = 36; + public static final int DATA_FLAG_REARING = 37; + public static final int DATA_FLAG_VIBRATING = 38; + public static final int DATA_FLAG_IDLING = 39; + public static final int DATA_FLAG_EVOKER_SPELL = 40; + public static final int DATA_FLAG_CHARGE_ATTACK = 41; + public static final int DATA_FLAG_WASD_CONTROLLED = 42; + public static final int DATA_FLAG_CAN_POWER_JUMP = 43; + public static final int DATA_FLAG_LINGER = 44; + public static final int DATA_FLAG_HAS_COLLISION = 45; + public static final int DATA_FLAG_AFFECTED_BY_GRAVITY = 46; + public static final int DATA_FLAG_FIRE_IMMUNE = 47; + public static final int DATA_FLAG_DANCING = 48; + } + + // vars + public HashMap map; + + // constructor + public EntityMetaData() { + this.map = new HashMap<>(); + } + + // public + public static EntityMetaData from(BinaryStream source) { + // TODO + return createDefault(); + } + + public static EntityMetaData createDefault() { + EntityMetaData data = new EntityMetaData(); + data.setGenericFlag(Constants.DATA_FLAG_BREATHING, true); + data.setGenericFlag(Constants.DATA_FLAG_AFFECTED_BY_GRAVITY, true); + data.setGenericFlag(Constants.DATA_FLAG_HAS_COLLISION, true); + data.setGenericFlag(Constants.DATA_FLAG_CAN_CLIMB, true); + data.set(Constants.DATA_AIR, new ShortMeta((short) 400)); + data.set(Constants.DATA_MAX_AIR, new ShortMeta((short) 400)); + data.set(Constants.DATA_NAMETAG, new ByteArrayMeta("")); + data.set(Constants.DATA_LEAD_HOLDER_EID, new LongMeta(-1L)); + data.set(Constants.DATA_SCALE, new FloatMeta(1.0f)); +// data.set(Constants.DATA_BED_POSITION, new BlockPositionMeta(new BlockPosition(0, 0, 0))); + return data; + } + + public void set(int key, IEntityMetaDataObject object) { + this.map.put(key, object); + } + + public void encode() { + reset(); + putUnsignedVarInt(map.size()); + for (Map.Entry entry : this.map.entrySet()) { + putUnsignedVarInt(entry.getKey()); + putUnsignedVarInt(entry.getValue().type()); + entry.getValue().encode(this); + } + } + + public void setGenericFlag(int flagId, boolean value) { + long flag = 0; + if (!map.containsKey(Constants.DATA_FLAGS)) { + map.put(Constants.DATA_FLAGS, new LongMeta(0L)); + } else { + flag = ((LongMeta) map.get(Constants.DATA_FLAGS)).data; + } + boolean currValue = ((flag >> flagId) & 0b1) > 0; + if (currValue != value) { + flag ^= (1L << flagId); + } + ((LongMeta) map.get(Constants.DATA_FLAGS)).data = flag; + } + + // private +} diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/IEntityMetaDataObject.java b/src/main/java/org/dragonet/proxy/data/entity/meta/IEntityMetaDataObject.java similarity index 91% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/IEntityMetaDataObject.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/IEntityMetaDataObject.java index 4df222c4d..6524ff1a1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/IEntityMetaDataObject.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/IEntityMetaDataObject.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta; +package org.dragonet.proxy.data.entity.meta; import org.dragonet.proxy.utilities.BinaryStream; diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/BlockPositionMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/BlockPositionMeta.java similarity index 83% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/BlockPositionMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/BlockPositionMeta.java index ce0c1cf83..7ef6e1f13 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/BlockPositionMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/BlockPositionMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; import org.dragonet.proxy.utilities.BlockPosition; diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteArrayMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteArrayMeta.java similarity index 83% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteArrayMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteArrayMeta.java index abe6ccfc7..9a46b3875 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteArrayMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteArrayMeta.java @@ -10,11 +10,11 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; import java.nio.charset.StandardCharsets; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class ByteArrayMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteMeta.java similarity index 80% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteMeta.java index d1379bb3c..b7d0124bb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ByteMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ByteMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class ByteMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/FloatMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/FloatMeta.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/FloatMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/FloatMeta.java index 9a03d82a1..c22341ebe 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/FloatMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/FloatMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class FloatMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/IntegerMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/IntegerMeta.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/IntegerMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/IntegerMeta.java index 1e1b27143..45c2286d6 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/IntegerMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/IntegerMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class IntegerMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/LongMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/LongMeta.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/LongMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/LongMeta.java index db35088fd..b7e1f5079 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/LongMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/LongMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class LongMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ShortMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ShortMeta.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ShortMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/ShortMeta.java index 530b50898..41c9eff36 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/ShortMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/ShortMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; public class ShortMeta implements IEntityMetaDataObject { diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/SlotMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/SlotMeta.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/SlotMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/SlotMeta.java index 8db15d1c2..b5e04e308 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/SlotMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/SlotMeta.java @@ -10,10 +10,10 @@ * * @author The Dragonet Team */ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.protocol.type.Slot; import org.dragonet.proxy.utilities.BinaryStream; diff --git a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/Vector3FMeta.java b/src/main/java/org/dragonet/proxy/data/entity/meta/type/Vector3FMeta.java similarity index 73% rename from proxy/src/main/java/org/dragonet/proxy/entity/meta/type/Vector3FMeta.java rename to src/main/java/org/dragonet/proxy/data/entity/meta/type/Vector3FMeta.java index 918a67e79..71c119bc0 100644 --- a/proxy/src/main/java/org/dragonet/proxy/entity/meta/type/Vector3FMeta.java +++ b/src/main/java/org/dragonet/proxy/data/entity/meta/type/Vector3FMeta.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.entity.meta.type; +package org.dragonet.proxy.data.entity.meta.type; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.IEntityMetaDataObject; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.IEntityMetaDataObject; import org.dragonet.proxy.utilities.BinaryStream; import org.dragonet.proxy.utilities.Vector3F; diff --git a/proxy/src/main/java/org/dragonet/inventory/ContainerId.java b/src/main/java/org/dragonet/proxy/data/inventory/ContainerId.java similarity index 87% rename from proxy/src/main/java/org/dragonet/inventory/ContainerId.java rename to src/main/java/org/dragonet/proxy/data/inventory/ContainerId.java index 551c50ad7..251e747cc 100644 --- a/proxy/src/main/java/org/dragonet/inventory/ContainerId.java +++ b/src/main/java/org/dragonet/proxy/data/inventory/ContainerId.java @@ -1,4 +1,4 @@ -package org.dragonet.inventory; +package org.dragonet.proxy.data.inventory; /** * Created on 2017/10/21. diff --git a/proxy/src/main/java/org/dragonet/inventory/InventoryType.java b/src/main/java/org/dragonet/proxy/data/inventory/InventoryType.java similarity index 98% rename from proxy/src/main/java/org/dragonet/inventory/InventoryType.java rename to src/main/java/org/dragonet/proxy/data/inventory/InventoryType.java index e81251e40..3a5377d4e 100644 --- a/proxy/src/main/java/org/dragonet/inventory/InventoryType.java +++ b/src/main/java/org/dragonet/proxy/data/inventory/InventoryType.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet.inventory; +package org.dragonet.proxy.data.inventory; public final class InventoryType { public static final class PEInventory { diff --git a/proxy/src/main/java/org/dragonet/inventory/ItemList.java b/src/main/java/org/dragonet/proxy/data/inventory/ItemList.java similarity index 98% rename from proxy/src/main/java/org/dragonet/inventory/ItemList.java rename to src/main/java/org/dragonet/proxy/data/inventory/ItemList.java index 31295c68a..be2a6978a 100644 --- a/proxy/src/main/java/org/dragonet/inventory/ItemList.java +++ b/src/main/java/org/dragonet/proxy/data/inventory/ItemList.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet.inventory; +package org.dragonet.proxy.data.inventory; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; diff --git a/proxy/src/main/java/org/dragonet/inventory/PEWindowConstantID.java b/src/main/java/org/dragonet/proxy/data/inventory/PEWindowConstantID.java similarity index 93% rename from proxy/src/main/java/org/dragonet/inventory/PEWindowConstantID.java rename to src/main/java/org/dragonet/proxy/data/inventory/PEWindowConstantID.java index bb200620f..1fe82e88b 100644 --- a/proxy/src/main/java/org/dragonet/inventory/PEWindowConstantID.java +++ b/src/main/java/org/dragonet/proxy/data/inventory/PEWindowConstantID.java @@ -10,7 +10,7 @@ * * @author The Dragonet Team */ -package org.dragonet.inventory; +package org.dragonet.proxy.data.inventory; public enum PEWindowConstantID { PLAYER_INVENTORY(0x00), PLAYER_ARMOR(0x78), PLAYER_CREATIVE(0x79); diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/NBTIO.java b/src/main/java/org/dragonet/proxy/data/nbt/NBTIO.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/nbt/NBTIO.java rename to src/main/java/org/dragonet/proxy/data/nbt/NBTIO.java index 4d0fb2a9f..b59af791d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/NBTIO.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/NBTIO.java @@ -1,9 +1,9 @@ -package org.dragonet.proxy.nbt; +package org.dragonet.proxy.data.nbt; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; -import org.dragonet.proxy.nbt.tag.CompoundTag; -import org.dragonet.proxy.nbt.tag.Tag; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.tag.CompoundTag; +import org.dragonet.proxy.data.nbt.tag.Tag; import java.io.*; import java.nio.ByteOrder; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTInputStream.java b/src/main/java/org/dragonet/proxy/data/nbt/stream/NBTInputStream.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTInputStream.java rename to src/main/java/org/dragonet/proxy/data/nbt/stream/NBTInputStream.java index 016f154dc..ca0246965 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTInputStream.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/stream/NBTInputStream.java @@ -1,4 +1,4 @@ -package org.dragonet.proxy.nbt.stream; +package org.dragonet.proxy.data.nbt.stream; import org.dragonet.proxy.utilities.VarInt; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTOutputStream.java b/src/main/java/org/dragonet/proxy/data/nbt/stream/NBTOutputStream.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTOutputStream.java rename to src/main/java/org/dragonet/proxy/data/nbt/stream/NBTOutputStream.java index bd370330b..d43226425 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/stream/NBTOutputStream.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/stream/NBTOutputStream.java @@ -1,4 +1,4 @@ -package org.dragonet.proxy.nbt.stream; +package org.dragonet.proxy.data.nbt.stream; import org.dragonet.proxy.utilities.VarInt; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/ByteArrayTag.java similarity index 89% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/ByteArrayTag.java index 634cdd452..8f251c149 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/ByteArrayTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import org.dragonet.proxy.utilities.Binary; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/ByteTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/ByteTag.java index b58aa3198..d2506d4df 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/ByteTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/CompoundTag.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/CompoundTag.java index 350fe764f..1f8034f72 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/CompoundTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; import java.io.PrintStream; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/DoubleTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/DoubleTag.java index 5a225b4ab..4f91712a7 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/DoubleTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/EndTag.java similarity index 75% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/EndTag.java index 389eebc1f..787f77fef 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/EndTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/FloatTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/FloatTag.java index 62cdbe89d..d0d25fad4 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/FloatTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/IntArrayTag.java similarity index 89% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/IntArrayTag.java index b7923d94c..c17e12970 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/IntArrayTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; import java.util.Arrays; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/IntTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/IntTag.java index d55766a49..aaa73a94a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/IntTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/ListTag.java similarity index 94% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/ListTag.java index 30fc1cd47..65e138db8 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/ListTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; import java.io.PrintStream; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/LongTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/LongTag.java index e217d8000..d7de6eefd 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/LongTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/NumberTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/NumberTag.java similarity index 86% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/NumberTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/NumberTag.java index ab9bda2d3..63373ebc6 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/NumberTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/NumberTag.java @@ -1,4 +1,4 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; /** * author: MagicDroidX diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/ShortTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/ShortTag.java index 8ff776c11..54c76c53f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/ShortTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/StringTag.java similarity index 87% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/StringTag.java index e15526ab2..a13be9be3 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/StringTag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java b/src/main/java/org/dragonet/proxy/data/nbt/tag/Tag.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java rename to src/main/java/org/dragonet/proxy/data/nbt/tag/Tag.java index a5618bbe2..6750ad789 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java +++ b/src/main/java/org/dragonet/proxy/data/nbt/tag/Tag.java @@ -1,7 +1,7 @@ -package org.dragonet.proxy.nbt.tag; +package org.dragonet.proxy.data.nbt.tag; -import org.dragonet.proxy.nbt.stream.NBTInputStream; -import org.dragonet.proxy.nbt.stream.NBTOutputStream; +import org.dragonet.proxy.data.nbt.stream.NBTInputStream; +import org.dragonet.proxy.data.nbt.stream.NBTOutputStream; import java.io.IOException; import java.io.PrintStream; diff --git a/src/main/java/org/dragonet/proxy/network/CacheKey.java b/src/main/java/org/dragonet/proxy/network/CacheKey.java new file mode 100644 index 000000000..103d40130 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/CacheKey.java @@ -0,0 +1,32 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +public final class CacheKey { + + // PEPackets + public static final String PACKET_JOIN_GAME_PACKET = "achedJoinGamePacket"; + public static final String PACKET_LOGIN_PACKET = "achedLoginPacket"; + + // ints + public static final String PLAYER_EID = "player_entity_id"; + public static final String AUTHENTICATION_STATE = "auth_state"; + public static final String WINDOW_OPENED_ID = "window_opened_id"; + + // Strings + public static final String AUTHENTICATION_EMAIL = "auth_mail"; + + // Positions + public static final String BLOCK_BREAKING_POSITION = "block_breaking_position"; + public static final String WINDOW_BLOCK_POSITION = "window_block_position"; +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/IDownstreamSession.java b/src/main/java/org/dragonet/proxy/network/IDownstreamSession.java similarity index 64% rename from proxy/src/main/java/org/dragonet/proxy/network/IDownstreamSession.java rename to src/main/java/org/dragonet/proxy/network/IDownstreamSession.java index 45906ce05..05069e893 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/IDownstreamSession.java +++ b/src/main/java/org/dragonet/proxy/network/IDownstreamSession.java @@ -13,17 +13,18 @@ package org.dragonet.proxy.network; public interface IDownstreamSession { - public void connect(String addr, int port); - public void disconnect(); + public void connect(String addr, int port); - public boolean isConnected(); + public void disconnect(); - public void send(PACKET packet); + public boolean isConnected(); - public void send(PACKET... packets); + public void send(PACKET packet); - public void sendChat(String chat); + public void send(PACKET... packets); - public void onTick(); + public void sendChat(String chat); + + public void onTick(); } diff --git a/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java b/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java new file mode 100644 index 000000000..5b4f61639 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/InventoryTranslatorRegister.java @@ -0,0 +1,182 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import java.util.HashMap; +import java.util.Map; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; +import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; +import org.dragonet.proxy.data.inventory.PEWindowConstantID; +import org.dragonet.proxy.network.cache.CachedWindow; +import org.dragonet.proxy.network.translator.ItemBlockTranslator; +import org.dragonet.proxy.network.translator.inv.ChestWindowTranslator; +import org.dragonet.proxy.network.translator.IInventoryTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.ContainerClosePacket; +import org.dragonet.proxy.protocol.packets.InventoryContentPacket; +import org.dragonet.proxy.protocol.type.Slot; + +public final class InventoryTranslatorRegister { + + // PC Type => PE Translator + private static final Map TRANSLATORS = new HashMap<>(); + + static { + TRANSLATORS.put(WindowType.CHEST, new ChestWindowTranslator()); + } + + public static PEPacket[] sendPlayerInventory(UpstreamSession session) { + CachedWindow win = session.getWindowCache().getPlayerInventory(); + // Translate and send + InventoryContentPacket ret = new InventoryContentPacket(); + ret.windowId = PEWindowConstantID.PLAYER_INVENTORY.getId(); + ret.items = new Slot[40]; + // hotbar + for (int i = 36; i < 45; i++) { + ret.items[i - 36] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); + } + // inventory + for (int i = 9; i < 36; i++) { + // TODO: Add NBT support + ret.items[i] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); + } + // armors + for (int i = 5; i < 9; i++) { + ret.items[i + 31] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); + } + // TODO: Add armor support + return new PEPacket[]{ret}; + } + + public static void open(UpstreamSession session, ServerOpenWindowPacket win) { + closeOpened(session, true); + if (TRANSLATORS.containsKey(win.getType())) { + CachedWindow cached = new CachedWindow(win.getWindowId(), win.getType(), 36 + win.getSlots()); + session.getWindowCache().cacheWindow(cached); + TRANSLATORS.get(win.getType()).open(session, cached); + + com.github.steveice10.packetlib.packet.Packet[] items = session.getWindowCache() + .getCachedPackets(win.getWindowId()); + for (com.github.steveice10.packetlib.packet.Packet item : items) { + if (item != null) { + if (ServerWindowItemsPacket.class.isAssignableFrom(item.getClass())) { + updateContent(session, (ServerWindowItemsPacket) item); + } else { + updateSlot(session, (ServerSetSlotPacket) item); + } + } + } + } else { + // Not supported + session.getDownstream().send(new ClientCloseWindowPacket(win.getWindowId())); + } + } + + public static void closeOpened(UpstreamSession session, boolean byServer) { + if (session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID)) { + // There is already a window opened + int id = (int) session.getDataCache().remove(CacheKey.WINDOW_OPENED_ID); + if (!byServer) { + session.getDownstream().send(new ContainerClosePacket((byte) (id & 0xFF))); + } + if (session.getDataCache().containsKey(CacheKey.WINDOW_BLOCK_POSITION)) { + // Already a block was replaced to Chest, reset it + session.sendFakeBlock(((Position) session.getDataCache().get(CacheKey.WINDOW_BLOCK_POSITION)).getX(), + ((Position) session.getDataCache().get(CacheKey.WINDOW_BLOCK_POSITION)).getY(), + ((Position) session.getDataCache().remove(CacheKey.WINDOW_BLOCK_POSITION)).getZ(), 1, // Set to + // stone + // since + // we + // don't + // know + // what + // it + // was, + // server + // will + // correct + // it + // once + // client + // interacts + // it + 0); + } + if (byServer) { + session.sendPacket(new ContainerClosePacket((byte) (id & 0xFF)), true); + } + } + } + + public static void updateContent(UpstreamSession session, ServerWindowItemsPacket packet) { + if (packet.getWindowId() == 0) { + return; // We don't process player inventory updates here. + } + if (!session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID) + || !session.getWindowCache().hasWindow(packet.getWindowId())) { + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + int openedId = (int) session.getDataCache().get(CacheKey.WINDOW_OPENED_ID); + if (packet.getWindowId() != openedId) { + // Hmm + closeOpened(session, true); + return; + } + + CachedWindow win = session.getWindowCache().get(openedId); + IInventoryTranslator t = TRANSLATORS.get(win.pcType); + if (t == null) { + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + win.slots = packet.getItems(); + t.updateContent(session, win); + } + + public static void updateSlot(UpstreamSession session, ServerSetSlotPacket packet) { + if (packet.getWindowId() == 0) { + return; // We don't process player inventory updates here. + } + if (!session.getDataCache().containsKey(CacheKey.WINDOW_OPENED_ID) + || !session.getWindowCache().hasWindow(packet.getWindowId())) { + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + int openedId = (int) session.getDataCache().get(CacheKey.WINDOW_OPENED_ID); + if (packet.getWindowId() != openedId) { + // Hmm + closeOpened(session, true); + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + CachedWindow win = session.getWindowCache().get(openedId); + System.out.println("WIN=" + win.slots.length + ", REQ_SLOT=" + packet.getSlot()); + if (win.size <= packet.getSlot()) { + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + IInventoryTranslator t = TRANSLATORS.get(win.pcType); + if (t == null) { + session.getDownstream().send(new ClientCloseWindowPacket(packet.getWindowId())); + return; + } + win.slots[packet.getSlot()] = packet.getItem(); // Update here + t.updateSlot(session, win, packet.getSlot()); + } +} diff --git a/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java b/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java new file mode 100644 index 000000000..6daf590b3 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java @@ -0,0 +1,148 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.github.steveice10.packetlib.Client; +import com.github.steveice10.packetlib.event.session.ConnectedEvent; +import com.github.steveice10.packetlib.event.session.DisconnectedEvent; +import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; +import com.github.steveice10.packetlib.event.session.SessionAdapter; +import com.github.steveice10.packetlib.packet.Packet; +import com.github.steveice10.packetlib.tcp.TcpSessionFactory; +import org.dragonet.proxy.DesktopServer; +import org.dragonet.proxy.DragonProxy; +import org.dragonet.proxy.configuration.Lang; +import org.dragonet.proxy.protocol.PEPacket; + +/** + * Maintaince the connection between the proxy and remote Minecraft server. + */ +public class PCDownstreamSession implements IDownstreamSession { + + public MinecraftProtocol protocol; + + private final DragonProxy proxy; + private final UpstreamSession upstream; + private DesktopServer serverInfo; + private Client remoteClient; + + public PCDownstreamSession(DragonProxy proxy, UpstreamSession upstream) { + this.proxy = proxy; + this.upstream = upstream; + } + + public void connect(DesktopServer serverInfo) { + this.serverInfo = serverInfo; + connect(serverInfo.remote_addr, serverInfo.remote_port); + } + + public void connect(String addr, int port) { + if (this.protocol == null) { + upstream.onConnected(); // Clear the flags + upstream.disconnect("ERROR! "); + return; + } + remoteClient = new Client(addr, port, protocol, new TcpSessionFactory()); + remoteClient.getSession().addListener(new SessionAdapter() { + public void connected(ConnectedEvent event) { + proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_REMOTE_CONNECTED, upstream.getUsername(), + upstream.getRemoteAddress())); + upstream.onConnected(); + } + + public void disconnected(DisconnectedEvent event) { + upstream.disconnect(proxy.getLang().get(event.getReason())); + } + + public void packetReceived(PacketReceivedEvent event) { + /* + * if (!event.getPacket().getClass().getSimpleName().toLowerCase().contains( + * "block") && + * !event.getPacket().getClass().getSimpleName().toLowerCase().contains( + * "entity") && + * !event.getPacket().getClass().getSimpleName().toLowerCase().contains("time") + * && + * !event.getPacket().getClass().getSimpleName().toLowerCase().contains("chunk") + * ) { String debug_string = event.getPacket().getClass().getSimpleName() + + * " > " + event.getPacket().toString(); if(debug_string.length() > 128) + * debug_string = debug_string.substring(0, 128) + "... "; + * System.out.println("REMOTE << " + debug_string); } + */ + // Handle the packet + try { + PEPacket[] packets = PacketTranslatorRegister.translateToPE(upstream, event.getPacket()); + if (packets == null) { + return; + } + if (packets.length <= 0) { + return; + } + if (packets.length == 1) { + upstream.sendPacket(packets[0]); + } else { + upstream.sendAllPackets(packets, true); + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + }); + remoteClient.getSession().connect(); + } + + public void disconnect() { + if (remoteClient != null && remoteClient.getSession().isConnected()) { + remoteClient.getSession().disconnect("Disconnect"); + } + } + + public boolean isConnected() { + return remoteClient != null && remoteClient.getSession().isConnected(); + } + + public void send(Packet... packets) { + for (Packet p : packets) { + send(p); + } + } + + public void send(Packet packet) { + if (packet == null) { + return; + } + remoteClient.getSession().send(packet); + } + + public void sendChat(String chat) { + remoteClient.getSession().send(new ClientChatPacket(chat)); + } + + public void onTick() { + + } + + public DragonProxy getProxy() { + return proxy; + } + + public UpstreamSession getUpstream() { + return upstream; + } + + public DesktopServer getServerInfo() { + return serverInfo; + } +} diff --git a/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java b/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java new file mode 100644 index 000000000..707142f18 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/PEPacketProcessor.java @@ -0,0 +1,112 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import java.io.FileOutputStream; +import java.util.ArrayDeque; +import java.util.Deque; + +import com.github.steveice10.packetlib.packet.Packet; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.Protocol; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.protocol.packets.ChunkRadiusUpdatedPacket; +import org.dragonet.proxy.protocol.packets.LoginPacket; +import org.dragonet.proxy.protocol.packets.RequestChunkRadiusPacket; + +public class PEPacketProcessor implements Runnable { + + public static final int MAX_PACKETS_PER_CYCLE = 200; + + private final UpstreamSession client; + private final Deque packets = new ArrayDeque<>(); + + public PEPacketProcessor(UpstreamSession client) { + this.client = client; + } + + public UpstreamSession getClient() { + return client; + } + + public void putPacket(byte[] packet) { + packets.add(packet); + } + + public void run() { + int cnt = 0; + while (cnt < MAX_PACKETS_PER_CYCLE && !packets.isEmpty()) { + cnt++; + byte[] p = packets.pop(); + PEPacket[] packets; + try { + packets = Protocol.decode(p); + if (packets == null || packets.length <= 0) { + continue; + } + } catch (Exception e) { + e.printStackTrace(); + return; + } + for (PEPacket decoded : packets) { + handlePacket(decoded); + } + } + + } + + public void handlePacket(PEPacket packet) { + if (packet == null) { + return; + } + + // System.out.println("RECEIVED PACKET=" + packet.getClass().getSimpleName()); + /* + * try{ FileOutputStream fos = new FileOutputStream("cap_" + + * System.currentTimeMillis() + "_" + packet.getClass().getSimpleName() + + * ".bin"); fos.write(packet.getBuffer()); fos.close(); }catch(Exception e){} + */ + switch (packet.pid()) { + case ProtocolInfo.LOGIN_PACKET: + client.onLogin((LoginPacket) packet); + break; + case ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET: + if (client.isLoggedIn()) { + return; + } + client.postLogin(); + break; + case ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET: + client.sendPacket(new ChunkRadiusUpdatedPacket(((RequestChunkRadiusPacket) packet).radius)); + break; + case ProtocolInfo.TEXT_PACKET: // Text (check CLS Login) + if (client.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) { + PacketTranslatorRegister.translateToPC(client, packet); + break; + } + default: + if (client.getDownstream() == null) { + break; + } + if (!client.getDownstream().isConnected()) { + break; + } + Packet[] translated = PacketTranslatorRegister.translateToPC(client, packet); + if (translated == null || translated.length == 0) { + break; + } + client.getDownstream().send(translated); + break; + } + } +} diff --git a/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java new file mode 100644 index 000000000..5f98db89c --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -0,0 +1,148 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.*; +import com.github.steveice10.packetlib.packet.Packet; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import java.util.HashMap; +import java.util.Map; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.network.translator.pc.*; +import org.dragonet.proxy.network.translator.pe.*; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.*; + +public final class PacketTranslatorRegister { + + private static final Map, IPCPacketTranslator> PC_TO_PE_TRANSLATOR = new HashMap<>(); + private static final Map, IPEPacketTranslator> PE_TO_PC_TRANSLATOR = new HashMap<>(); + + /** + * PC to PE + */ + static { + // Login phase + PC_TO_PE_TRANSLATOR.put(ServerJoinGamePacket.class, new PCJoinGamePacketTranslator()); + + // Settings && Weather + PC_TO_PE_TRANSLATOR.put(ServerNotifyClientPacket.class, new PCNotifyClientPacketTranslator()); + + // Chat + PC_TO_PE_TRANSLATOR.put(ServerChatPacket.class, new PCChatPacketTranslator()); + + // Map + PC_TO_PE_TRANSLATOR.put(ServerChunkDataPacket.class, new PCMultiChunkDataPacketTranslator()); + + PC_TO_PE_TRANSLATOR.put(ServerUpdateTimePacket.class, new PCUpdateTimePacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerBlockChangePacket.class, new PCBlockChangePacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerMultiBlockChangePacket.class, new PCMultiBlockChangePacketTranslator()); + // PC_TO_PE_TRANSLATOR.put(ServerUpdateSignPacket.class, new + // PCUpdateSignPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerPlaySoundPacket.class, new PCPlaySoundPacketTranslator()); + // + // // Entity + PC_TO_PE_TRANSLATOR.put(ServerPlayerPositionRotationPacket.class, new PCPlayerPositionRotationPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerSpawnMobPacket.class, new PCSpawnMobPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerPlayerListEntryPacket.class, new PCPlayerListItemPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerSpawnPlayerPacket.class, new PCSpawnPlayerPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerSpawnObjectPacket.class, new PCSpawnObjectPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityMetadataPacket.class, new PCEntityMetadataPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityDestroyPacket.class, new PCDestroyEntitiesPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityPositionRotationPacket.class, new PCEntityPositionRotationPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityPositionPacket.class, new PCEntityPositionPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityRotationPacket.class, new PCEntityRotationPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityVelocityPacket.class, new PCEntityVelocityPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityEffectPacket.class, new PCEntityEffectPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityRemoveEffectPacket.class, new PCEntityRemoveEffectPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerPlayerHealthPacket.class, new PCUpdateHealthPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityAnimationPacket.class, new PCAnimationPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntitySetPassengersPacket.class, new PCEntitySetPassengerPacketTranslator()); + // + // //Inventory + PC_TO_PE_TRANSLATOR.put(ServerOpenWindowPacket.class, new PCOpenWindowPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerWindowItemsPacket.class, new PCWindowItemsTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerSetSlotPacket.class, new PCSetSlotPacketTranslator()); + + } + + /** + * PE to PC + */ + static { + // Map + PE_TO_PC_TRANSLATOR.put(LevelSoundEventPacket.class, new PESoundEventPacketTranslator()); + + // Chat + PE_TO_PC_TRANSLATOR.put(TextPacket.class, new PEChatPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(CommandRequestPacket.class, new PECommandRequestPacketTranslator()); + + // Entity + // PE_TO_PC_TRANSLATOR.put(UseItem.class, new PEUseItemPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(MovePlayerPacket.class, new PEMovePlayerPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(PlayerActionPacket.class, new PEPlayerActionPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(InteractPacket.class, new PEInteractPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(AdventureSettingsPacket.class, new PEAdventureSettingsPacketTranslator()); + + // Inventory + PE_TO_PC_TRANSLATOR.put(ContainerClosePacket.class, new PEWindowClosePacketTranslator()); + PE_TO_PC_TRANSLATOR.put(MobEquipmentPacket.class, new PEPlayerEquipmentPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(InventoryTransactionPacket.class, new PEInventoryTransactionPacketTranslator()); + PE_TO_PC_TRANSLATOR.put(BlockPickRequestPacket.class, new PEBlockPickRequestPacketTranslator()); + } + + public static PEPacket[] translateToPE(UpstreamSession session, Packet packet) { + if (packet == null) { + return null; + } + IPCPacketTranslator target = (IPCPacketTranslator) PC_TO_PE_TRANSLATOR.get(packet.getClass()); + if (target == null) { + return null; + } + try { + return target.translate(session, packet); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Packet[] translateToPC(UpstreamSession session, PEPacket packet) { + if (packet == null) { + return null; + } + IPEPacketTranslator target = (IPEPacketTranslator) PE_TO_PC_TRANSLATOR + .get(packet.getClass()); + if (target == null) { + return null; + } + try { + return target.translate(session, packet); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/main/java/org/dragonet/proxy/network/RaknetInterface.java b/src/main/java/org/dragonet/proxy/network/RaknetInterface.java new file mode 100644 index 000000000..1d5d67019 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/RaknetInterface.java @@ -0,0 +1,118 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import java.net.InetSocketAddress; +import java.util.*; + +import net.marfgamer.jraknet.RakNetPacket; +import net.marfgamer.jraknet.identifier.MinecraftIdentifier; +import net.marfgamer.jraknet.server.RakNetServer; +import net.marfgamer.jraknet.server.RakNetServerListener; +import net.marfgamer.jraknet.server.ServerPing; +import net.marfgamer.jraknet.session.RakNetClientSession; +import org.dragonet.proxy.DragonProxy; +import org.dragonet.proxy.configuration.Lang; +import org.dragonet.proxy.protocol.ProtocolInfo; + +public class RaknetInterface implements RakNetServerListener { + + public static final Set IMMEDIATE_PACKETS = new HashSet<>(); + + private final DragonProxy proxy; + private final SessionRegister sessions; + private final RakNetServer rakServer; + + static { + IMMEDIATE_PACKETS.add("PlayStatus"); + } + + public RaknetInterface(DragonProxy proxy, String ip, int port) { + this.proxy = proxy; + rakServer = new RakNetServer(port, Integer.MAX_VALUE); + rakServer.addListener(this); + rakServer.addSelfListener(); + sessions = this.proxy.getSessionRegister(); + rakServer.startThreaded(); + } + + public DragonProxy getProxy() { + return proxy; + } + + public RakNetServer getRakServer() { + return rakServer; + } + + /* + * public void onTick() { } + */ + public void handlePing(ServerPing ping) { + System.out.println("PING " + ping.getSender().toString()); + } + + public void handleMessage(RakNetClientSession session, RakNetPacket packet, int channel) { + UpstreamSession upstream = sessions.getSession(session.getAddress().toString()); + if (upstream == null) { + return; + } + // System.out.println("Received RakNet packet: " + + // packet.getClass().getSimpleName()); + upstream.handlePacketBinary(packet.array()); + } + + public void onClientConnect(RakNetClientSession session) { + System.out.println("CLIENT CONNECT"); + String identifier = session.getAddress().toString(); + UpstreamSession upstream = new UpstreamSession(proxy, identifier, session, session.getAddress()); + sessions.newSession(upstream); + } + + public void onClientDisconnect(RakNetClientSession session, String reason) { + System.out.println("CLIENT DISCONNECT"); + UpstreamSession upstream = sessions.getSession(session.getAddress().toString()); + if (upstream == null) { + return; + } + upstream.onDisconnect(proxy.getLang().get(Lang.MESSAGE_CLIENT_DISCONNECT)); // It will handle rest of the + // things. + } + + public void onThreadException(Throwable throwable) { + System.out.println("Thread exception: " + throwable.getMessage()); + throwable.printStackTrace(); + } + + public void onHandlerException(InetSocketAddress address, Throwable throwable) { + System.out.println("Handler exception: " + throwable.getMessage()); + throwable.printStackTrace(); + } + + public void onSessionException(RakNetClientSession session, Throwable throwable) { + System.out.println("Session exception: " + throwable.getMessage()); + throwable.printStackTrace(); + } + + public void setBroadcastName(String serverName, int players, int maxPlayers) { + rakServer.setIdentifier( + new MinecraftIdentifier(serverName, ProtocolInfo.CURRENT_PROTOCOL, ProtocolInfo.MINECRAFT_VERSION_NETWORK, + players, maxPlayers, new Random().nextLong(), "DragonProxy", "Survival")); + if (!rakServer.isBroadcastingEnabled()) { + rakServer.setBroadcastingEnabled(true); + } + } + + public void shutdown() { + rakServer.shutdown(); + } +} diff --git a/src/main/java/org/dragonet/proxy/network/SessionRegister.java b/src/main/java/org/dragonet/proxy/network/SessionRegister.java new file mode 100644 index 000000000..774ee2621 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/SessionRegister.java @@ -0,0 +1,58 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.dragonet.proxy.DragonProxy; + +public class SessionRegister { + + private final DragonProxy proxy; + private final Map clients = Collections + .synchronizedMap(new HashMap()); + + public SessionRegister(DragonProxy proxy) { + this.proxy = proxy; + } + + public void onTick() { + Iterator> iterator = clients.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry ent = iterator.next(); + ent.getValue().onTick(); + } + } + + public void newSession(UpstreamSession session) { + clients.put(session.getRaknetID(), session); + } + + public void removeSession(UpstreamSession session) { + clients.remove(session.getRaknetID()); + } + + public UpstreamSession getSession(String identifier) { + return clients.get(identifier); + } + + public Map getAll() { + return Collections.unmodifiableMap(clients); + } + + public int getOnlineCount() { + return clients.size(); + } +} diff --git a/src/main/java/org/dragonet/proxy/network/UpstreamSession.java b/src/main/java/org/dragonet/proxy/network/UpstreamSession.java new file mode 100644 index 000000000..9a7e0d74e --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/UpstreamSession.java @@ -0,0 +1,509 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network; + +import com.github.steveice10.mc.auth.exception.request.RequestException; +import com.github.steveice10.mc.auth.service.AuthenticationService; +import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.net.InetSocketAddress; +import java.util.*; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import net.marfgamer.jraknet.protocol.Reliability; +import net.marfgamer.jraknet.session.RakNetClientSession; +import org.dragonet.proxy.DesktopServer; +import org.dragonet.proxy.DragonProxy; +import org.dragonet.proxy.configuration.Lang; +import org.dragonet.proxy.configuration.RemoteServer; +import org.dragonet.proxy.network.cache.EntityCache; +import org.dragonet.proxy.network.cache.WindowCache; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.protocol.packets.*; +import org.dragonet.proxy.protocol.type.chunk.ChunkData; +import org.dragonet.proxy.protocol.type.chunk.Section; +import org.dragonet.proxy.utilities.*; + +/** + * Maintaince the connection between the proxy and Minecraft: Pocket Edition + * clients. + */ +public class UpstreamSession { + + private final DragonProxy proxy; + private final String raknetID; + private final RakNetClientSession raknetClient; + private boolean loggedIn; + private boolean spawned; + private List cachedPackets; + private final InetSocketAddress remoteAddress; + private final PEPacketProcessor packetProcessor; + private final ScheduledFuture packetProcessorScheule; + private LoginChainDecoder profile; + private String username; + private IDownstreamSession downstream; + + /* + * ============================================================================= + * ========================== | Caches for Protocol Compatibility | /* + * ============================================================================= + * ========================== + */ + private final Map dataCache = Collections.synchronizedMap(new HashMap()); + private final Map playerInfoCache = Collections + .synchronizedMap(new HashMap()); + private final EntityCache entityCache = new EntityCache(this); + private final WindowCache windowCache = new WindowCache(this); + protected boolean connecting; + + /* + * ============================================================================= + * ========================== + */ + private MinecraftProtocol protocol; + + public UpstreamSession(DragonProxy proxy, String raknetID, RakNetClientSession raknetClient, + InetSocketAddress remoteAddress) { + this.proxy = proxy; + this.raknetID = raknetID; + this.remoteAddress = remoteAddress; + this.raknetClient = raknetClient; + packetProcessor = new PEPacketProcessor(this); + packetProcessorScheule = proxy.getGeneralThreadPool().scheduleAtFixedRate(packetProcessor, 10, 50, + TimeUnit.MILLISECONDS); + } + + public DragonProxy getProxy() { + return proxy; + } + + public String getRaknetID() { + return raknetID; + } + + public RakNetClientSession getRaknetClient() { + return raknetClient; + } + + public boolean isLoggedIn() { + return loggedIn; + } + + public boolean isSpawned() { + return spawned; + } + + public InetSocketAddress getRemoteAddress() { + return remoteAddress; + } + + public PEPacketProcessor getPacketProcessor() { + return packetProcessor; + } + + public LoginChainDecoder getProfile() { + return profile; + } + + public String getUsername() { + return username; + } + + public IDownstreamSession getDownstream() { + return downstream; + } + + public Map getDataCache() { + return dataCache; + } + + public Map getPlayerInfoCache() { + return playerInfoCache; + } + + public EntityCache getEntityCache() { + return entityCache; + } + + public WindowCache getWindowCache() { + return windowCache; + } + + public void sendPacket(PEPacket packet) { + sendPacket(packet, false); + } + + public void sendPacket(PEPacket packet, boolean immediate) { + if (packet == null) { + return; + } + // System.out.println("Sending [" + packet.getClass().getSimpleName() + "] "); + + packet.encode(); + + byte[] buffer; + try { + buffer = Zlib.deflate( + Binary.appendBytes(Binary.writeUnsignedVarInt(packet.getBuffer().length), packet.getBuffer()), 6); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + // handler.sendEncapsulated(identifier, encapsulated, RakNet.FLAG_NEED_ACK | + // (overridedImmediate ? RakNet.PRIORITY_IMMEDIATE : RakNet.PRIORITY_NORMAL)); + raknetClient.sendMessage(Reliability.RELIABLE_ORDERED, 0, + new net.marfgamer.jraknet.Packet(Binary.appendBytes((byte) 0xfe, buffer))); + } + + public void sendAllPackets(PEPacket[] packets, boolean immediate) { + if (packets.length < 5) { + for (PEPacket packet : packets) { + sendPacket(packet); + } + } + /* + * else { Batch batch = new BatchPacket(); boolean mustImmediate = immediate; if + * (!mustImmediate) { for (PEPacket packet : packets) { if + * (packet.isShouldSendImmidate()) { batch.packets.add(packet); mustImmediate = + * true; break; } } } sendPacket(batch, mustImmediate); } + */ + } + + public void connectToServer(RemoteServer server) { + if (server == null) { + return; + } + connecting = true; + if (downstream != null && downstream.isConnected()) { + spawned = false; + cachedPackets = null; + + downstream.disconnect(); + // TODO: Send chat message about server change. + + // Remove all loaded entities + /* + * BatchPacket batch = new BatchPacket(); + * this.entityCache.getEntities().entrySet().forEach((ent) -> { if(ent.getKey() + * != 0){ batch.packets.add(new RemoveEntityPacket(ent.getKey())); } }); + * this.entityCache.reset(true); sendPacket(batch, true); + */ + return; + } + cachedPackets = new LinkedList<>(); + if (server.getClass().isAssignableFrom(DesktopServer.class)) { + downstream = new PCDownstreamSession(proxy, this); + ((PCDownstreamSession) downstream).protocol = protocol; + downstream.connect(server.remote_addr, server.remote_port); + } else { + // downstream = new PEDownstreamSession(proxy, this); + // ((PEDownstreamSession)downstream).connect((PocketServer) server); + disconnect("PE targets not supported yet"); + } + } + + public void onConnected() { + connecting = false; + } + + /** + * Disconnected from server. + * + * @param reason + */ + public void disconnect(String reason) { + if (!connecting) { + sendPacket(new DisconnectPacket(false, reason)); + // RakNet server will call onDisconnect() + } + } + + /** + * Called when this client disconnects. + * + * @param reason The reason of disconnection. + */ + public void onDisconnect(String reason) { + proxy.getLogger().info(proxy.getLang().get(Lang.CLIENT_DISCONNECTED, + proxy.getAuthMode().equals("cls") ? "unknown" : username, remoteAddress, reason)); + if (downstream != null) { + downstream.disconnect(); + } + proxy.getSessionRegister().removeSession(this); + packetProcessorScheule.cancel(true); + } + + public void authenticate(String password) { + proxy.getGeneralThreadPool().execute(() -> { + try { + protocol = new MinecraftProtocol((String) dataCache.get(CacheKey.AUTHENTICATION_EMAIL), password, + false); + } catch (RequestException ex) { + if (ex.getMessage().toLowerCase().contains("invalid")) { + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD)); + disconnect(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_FAILD)); + return; + } else { + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + disconnect(proxy.getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + return; + } + } + + if (!username.equals(protocol.getProfile().getName())) { + username = protocol.getProfile().getName(); + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_USERNAME, username)); + } + + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_SUCCESS, username)); + + proxy.getLogger().info( + proxy.getLang().get(Lang.MESSAGE_ONLINE_LOGIN_SUCCESS_CONSOLE, username, remoteAddress, username)); + connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); + }); + } + + public void onLogin(LoginPacket packet) { + if (username != null) { + disconnect("Already logged in, this must be an error! "); + return; + } + + getDataCache().put(CacheKey.PACKET_LOGIN_PACKET, packet); + + PlayStatusPacket status = new PlayStatusPacket(); + System.out.println("CLIENT PROTOCOL = " + packet.protocol); + if (packet.protocol != ProtocolInfo.CURRENT_PROTOCOL) { + status.status = PlayStatusPacket.LOGIN_FAILED_CLIENT; + sendPacket(status, true); + disconnect(proxy.getLang().get(Lang.MESSAGE_UNSUPPORTED_CLIENT)); + return; + } + status.status = PlayStatusPacket.LOGIN_SUCCESS; + sendPacket(status, true); + + // Get the profile and read out the username! + profile = packet.decoded; + this.username = profile.username; + + // Okay @dktapps ;) + sendPacket(new ResourcePacksInfoPacket()); + + // now wait for response + } + + public void postLogin() { + sendPacket(new ResourcePackStackPacket()); + + loggedIn = true; + proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_CLIENT_CONNECTED, username, remoteAddress)); + if (proxy.getAuthMode().equals("online")) { + StartGamePacket pkStartGame = new StartGamePacket(); + pkStartGame.eid = 1L; // well we use 1 now + pkStartGame.rtid = 1L; + pkStartGame.dimension = 0; + pkStartGame.seed = 0; + pkStartGame.generator = 1; + pkStartGame.spawnPosition = new BlockPosition(0, 72, 0); + pkStartGame.position = new Vector3F(0f, 72f + Constants.PLAYER_HEAD_OFFSET, 0f); + pkStartGame.levelId = ""; + pkStartGame.worldName = "World"; + pkStartGame.defaultPlayerPermission = 2; + pkStartGame.commandsEnabled = true; + pkStartGame.premiumWorldTemplateId = ""; + sendPacket(pkStartGame, true); + + SetSpawnPositionPacket pkSpawn = new SetSpawnPositionPacket(); + pkSpawn.position = new BlockPosition(0, 72, 0); + sendPacket(pkSpawn, true); + + ChunkData data = new ChunkData(); + data.sections = new Section[16]; + for (int cy = 0; cy < 16; cy++) { + data.sections[cy] = new Section(); + if (cy < 6) { + Arrays.fill(data.sections[cy].blockIds, (byte) 1); + } + } + data.encode(); + sendPacket(new FullChunkDataPacket(0, 0, data.getBuffer())); + sendPacket(new FullChunkDataPacket(0, -1, data.getBuffer())); + sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer())); + sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer())); + + PlayStatusPacket pkStat = new PlayStatusPacket(); + pkStat.status = PlayStatusPacket.PLAYER_SPAWN; + sendPacket(pkStat, true); + + dataCache.put(CacheKey.AUTHENTICATION_STATE, "email"); + + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_NOTICE, username)); + sendChat(proxy.getLang().get(Lang.MESSAGE_ONLINE_EMAIL)); + } else if (proxy.getAuthMode().equals("cls")) { + // CLS LOGIN! + if ((username.length() < 6 + 1 + 1) || (!username.contains("_"))) { + disconnect(proxy.getLang().get(Lang.MESSAGE_CLS_NOTICE)); + return; + } + String name = username.substring(0, username.length() - 7); + String keyCode = username.substring(username.length() - 6); + String resp = HTTP.performGetRequest("http://api.dragonet.org/cls/query_token.php?" + + String.format("username=%s&keycode=%s", name, keyCode)); + if (resp == null) { + disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, + proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE))); + proxy.getLogger() + .severe(proxy.getLang() + .get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)) + .replace("§c", "").replace("§0", "")); + return; + } + JsonElement json; + try { + JsonParser jsonParser = new JsonParser(); + json = jsonParser.parse(resp); + } catch (Exception e) { + disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR))); + proxy.getLogger() + .severe(proxy.getLang() + .get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR)) + .replace("§c", "").replace("§0", "")); + // Json parse error! + return; + } + JsonObject obj = json.getAsJsonObject(); + if (!obj.get("status").getAsString().equals("success")) { + disconnect(proxy.getLang().get(Lang.MESSAGE_CLS_NOTICE)); + return; + } + AuthenticationService authSvc = new AuthenticationService(obj.get("client").getAsString()); + authSvc.setUsername(obj.get("ign").getAsString()); + authSvc.setAccessToken(obj.get("token").getAsString()); + try { + authSvc.login(); + } catch (RequestException ex) { + ex.printStackTrace(); + disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR))); + return; + } + username = authSvc.getSelectedProfile().getName(); + HTTP.performGetRequest("http://api.dragonet.org/cls/update_token.php?" + + String.format("username=%s&oldtoken=%s&newtoken=%s", name, obj.get("token").getAsString(), + authSvc.getAccessToken())); + protocol = new MinecraftProtocol(authSvc.getSelectedProfile(), authSvc.getAccessToken()); + + proxy.getLogger().debug("Initially joining [" + proxy.getConfig().default_server + "]... "); + connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); + } else { + protocol = new MinecraftProtocol(username); + + proxy.getLogger().debug("Initially joining [" + proxy.getConfig().default_server + "]... "); + + /* + * // begin test things StartGamePacket pkStartGame = new StartGamePacket(); + * pkStartGame.eid = 0; //Use EID 0 for eaisier management pkStartGame.rtid = 0; + * pkStartGame.dimension = (byte) 0; pkStartGame.seed = 0; pkStartGame.generator + * = 1; pkStartGame.position = new Vector3F(0f, 72f, 0f); pkStartGame.levelId = + * ""; pkStartGame.worldName = "World"; pkStartGame.spawnPosition = new + * BlockPosition(0, 0, 0); pkStartGame.premiumWorldTemplateId = ""; + * sendPacket(pkStartGame, true); + * + * PlayStatusPacket pkStat = new PlayStatusPacket(); pkStat.status = + * PlayStatusPacket.PLAYER_SPAWN; sendPacket(pkStat, true); + * + * AdventureSettingsPacket adv = new AdventureSettingsPacket(); + * adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true); + * adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, true); sendPacket(adv); + * + * for(int x = -7; x < 8; x ++) { for(int z = -7; z < 8; z ++) { + * org.dragonet.proxy.protocol.type.chunk.ChunkData c = new ChunkData(); + * c.sections = new org.dragonet.proxy.protocol.type.chunk.Section[16]; for(int + * cy = 0; cy < 16; cy++) { c.sections[cy] = new + * org.dragonet.proxy.protocol.type.chunk.Section(); if(cy < 4) { + * Arrays.fill(c.sections[cy].blockIds, (byte)1); } } + * org.dragonet.proxy.protocol.packets.FullChunkDataPacket p = new + * org.dragonet.proxy.protocol.packets.FullChunkDataPacket(); p.x = x; p.z = z; + * c.encode(); p.payload = c.getBuffer(); sendPacket(p); } } + * + * // InventoryContentPacket content = new InventoryContentPacket(); // + * content.items = new org.dragonet.proxy.protocol.type.Slot[36]; // + * sendPacket(content); // end of test things + */ + connectToServer(proxy.getConfig().remote_servers.get(proxy.getConfig().default_server)); + } + } + + public void setSpawned() { + spawned = true; + + if (cachedPackets != null) { + cachedPackets.stream().forEach(this::sendPacket); + + PlayStatusPacket play = new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN); + sendPacket(play); + + cachedPackets = null; + } + } + + public void sendChat(String chat) { + if (chat.contains("\n")) { + String[] lines = chat.split("\n"); + for (String line : lines) { + sendChat(line); + } + return; + } + TextPacket text = new TextPacket(); // raw + text.type = TextPacket.TYPE_RAW; + text.message = chat; + sendPacket(text, true); + } + + public void sendFakeBlock(int x, int y, int z, int id, int meta) { + UpdateBlockPacket pkBlock = new UpdateBlockPacket(); + pkBlock.id = id; + pkBlock.data = meta; + pkBlock.flags = UpdateBlockPacket.FLAG_NEIGHBORS; + pkBlock.blockPosition = new BlockPosition(x, y, z); + sendPacket(pkBlock, true); + } + + public void handlePacketBinary(byte[] packet) { + packetProcessor.putPacket(packet); + } + + public void putCachePacket(PEPacket p) { + if (p == null) { + return; + } + if (spawned || cachedPackets == null) { + // System.out.println("Not caching since already spawned! "); + sendPacket(p); + return; + } + cachedPackets.add(p); + } + + public void onTick() { + entityCache.onTick(); + if (downstream != null) { + downstream.onTick(); + } + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java rename to src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java index d3d602f9d..f0488ea5f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java +++ b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java @@ -17,7 +17,7 @@ import java.util.Set; import java.util.UUID; -import org.dragonet.proxy.entity.EntityType; +import org.dragonet.proxy.data.entity.EntityType; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/CachedWindow.java b/src/main/java/org/dragonet/proxy/network/cache/CachedWindow.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/network/cache/CachedWindow.java rename to src/main/java/org/dragonet/proxy/network/cache/CachedWindow.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java b/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java similarity index 99% rename from proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java rename to src/main/java/org/dragonet/proxy/network/cache/EntityCache.java index f48324721..21a57940d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java +++ b/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java @@ -18,7 +18,7 @@ import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; -import org.dragonet.proxy.entity.EntityType; +import org.dragonet.proxy.data.entity.EntityType; import org.dragonet.proxy.network.UpstreamSession; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/WindowCache.java b/src/main/java/org/dragonet/proxy/network/cache/WindowCache.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/network/cache/WindowCache.java rename to src/main/java/org/dragonet/proxy/network/cache/WindowCache.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java index a731ba306..550d2d89d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java @@ -17,28 +17,21 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; -import org.dragonet.proxy.entity.meta.type.ByteArrayMeta; -import org.dragonet.proxy.entity.meta.type.ByteMeta; -import org.dragonet.proxy.entity.meta.type.LongMeta; -import org.dragonet.proxy.entity.meta.type.ShortMeta; -import org.dragonet.proxy.entity.EntityType; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.type.BlockPositionMeta; -import org.dragonet.proxy.entity.meta.type.FloatMeta; -import org.dragonet.proxy.entity.meta.type.IntegerMeta; -import org.dragonet.proxy.entity.meta.type.SlotMeta; +import org.dragonet.proxy.data.entity.meta.type.ByteArrayMeta; +import org.dragonet.proxy.data.entity.meta.type.ByteMeta; +import org.dragonet.proxy.data.entity.meta.type.LongMeta; +import org.dragonet.proxy.data.entity.meta.type.ShortMeta; +import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.type.BlockPositionMeta; +import org.dragonet.proxy.data.entity.meta.type.FloatMeta; +import org.dragonet.proxy.data.entity.meta.type.IntegerMeta; +import org.dragonet.proxy.data.entity.meta.type.SlotMeta; import org.dragonet.proxy.protocol.type.Slot; import org.dragonet.proxy.utilities.BlockPosition; public final class EntityMetaTranslator { - // vars - // constructor - public EntityMetaTranslator() { - - } - - // public public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType type) { /* * Following format was fetched from http://wiki.vg/Entities#Entity_meta_Format @@ -47,9 +40,9 @@ public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType t if (pcMeta == null) { return peMeta; } - System.out.println("Entity + " + type); +// System.out.println("Entity + " + type); for (EntityMetadata m : pcMeta) { - System.out.println(m); +// System.out.println(m); if (m == null) { continue; } @@ -172,7 +165,7 @@ public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType t peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_PARTICLE_ID, new IntegerMeta((int) m.getValue())); break; case BOAT: //VarInt : Type (0=oak, 1=spruce, 2=birch, 3=jungle, 4=acacia, 5=dark oak) - peMeta.set(EntityMetaData.Constants.DATA_COLOR, new ByteMeta((byte) ((byte) ((Integer)m.getValue()).byteValue()))); + peMeta.set(EntityMetaData.Constants.DATA_COLOR, new ByteMeta((byte) ((byte) ((Integer) m.getValue()).byteValue()))); break; default: //(all LIVING) Boolean : Is potion effect ambient: reduces the number of particles generated by potions to 1/5 the normal amount peMeta.set(EntityMetaData.Constants.DATA_POTION_AMBIENT, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); @@ -215,8 +208,9 @@ public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType t case 12: switch (type) { case MINECART: //Boolean : Is powered - if (m.getValue() instanceof Boolean) + if (m.getValue() instanceof Boolean) { peMeta.set(EntityMetaData.Constants.DATA_FLAG_POWERED, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + } break; // case MINECART_COMMAND_BLOCK: //String : Command case ARMOR_STAND: //Rotation : Head rotation @@ -243,7 +237,7 @@ public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType t case ENDERMAN: //Opt BlockID : Carried block // case ENDER_DRAGON: //VarInt : Dragon phase case GHAST: //Boolean : Is attacking - case SLIME : //VarInt : Size + case SLIME: //VarInt : Size break; case PLAYER: //VarInt : Score // Not supported yet diff --git a/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java new file mode 100644 index 000000000..5573f58f9 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/IInventoryTranslator.java @@ -0,0 +1,45 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator; + +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedWindow; + +public interface IInventoryTranslator { + + /** + * Opens a window on MCPE. + * + * @param session + * @param window + * @return Can that window be opened on MCPE? + */ + boolean open(UpstreamSession session, CachedWindow window); + + /** + * Update a window's content. + * + * @param session + * @param window + */ + void updateContent(UpstreamSession session, CachedWindow window); + + /** + * Update a single slot in a window. + * + * @param session + * @param window + * @param slotIndex + */ + void updateSlot(UpstreamSession session, CachedWindow window, int slotIndex); +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java similarity index 75% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java index 3e3859d75..dd28d2c1d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/IPCPacketTranslator.java @@ -18,12 +18,13 @@ import com.github.steveice10.packetlib.packet.Packet; public interface IPCPacketTranslator

{ - /** - * Translate a packet from PC version to PE version. - * - * @param session - * @param packet - * @return - */ - PEPacket[] translate(UpstreamSession session, P packet); + + /** + * Translate a packet from PC version to PE version. + * + * @param session + * @param packet + * @return + */ + PEPacket[] translate(UpstreamSession session, P packet); } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java similarity index 76% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java index df0b67385..d955546dd 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/IPEPacketTranslator.java @@ -17,12 +17,13 @@ import org.dragonet.proxy.protocol.PEPacket; public interface IPEPacketTranslator

{ - /** - * Translate a packet from PE version to PC version. - * - * @param session - * @param packet - * @return - */ - Packet[] translate(UpstreamSession session, P packet); + + /** + * Translate a packet from PE version to PC version. + * + * @param session + * @param packet + * @return + */ + Packet[] translate(UpstreamSession session, P packet); } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java similarity index 93% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index 2e9b6fd48..0ca00669b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -22,12 +22,11 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import java.util.List; -import org.dragonet.proxy.nbt.tag.ListTag; +import org.dragonet.proxy.data.nbt.tag.ListTag; import org.dragonet.proxy.protocol.type.Slot; public class ItemBlockTranslator { - // vars public static final int UNSUPPORTED_BLOCK_ID = 248; public static final String DRAGONET_COMPOUND = "DragonetNBT"; @@ -104,13 +103,6 @@ public class ItemBlockTranslator { //TODO: replace podzol } - // constructor - public ItemBlockTranslator() { - - } - - // public - // Query handler public static ItemEntry translateToPE(int pcItemBlockId, int damage) { ItemEntry entry = new ItemEntry(pcItemBlockId & 0xFF, damage & 0xf); @@ -151,11 +143,11 @@ public static Slot translateSlotToPE(ItemStack item) { slot.id = entry.id; slot.damage = entry.damage != null ? entry.damage : item.getData(); slot.count = (item.getAmount() & 0xff); - org.dragonet.proxy.nbt.tag.CompoundTag tag = new org.dragonet.proxy.nbt.tag.CompoundTag(); + org.dragonet.proxy.data.nbt.tag.CompoundTag tag = new org.dragonet.proxy.data.nbt.tag.CompoundTag(); tag.putShort("id", item.getId()); tag.putShort("amount", item.getAmount()); tag.putShort("data", item.getData()); - org.dragonet.proxy.nbt.tag.CompoundTag rootTag = new org.dragonet.proxy.nbt.tag.CompoundTag(); + org.dragonet.proxy.data.nbt.tag.CompoundTag rootTag = new org.dragonet.proxy.data.nbt.tag.CompoundTag(); rootTag.put(DRAGONET_COMPOUND, tag); slot.tag = rootTag; translateRawNBT(item.getId(), item.getNBT(), slot.tag); @@ -163,11 +155,11 @@ public static Slot translateSlotToPE(ItemStack item) { } @SuppressWarnings("unchecked") - public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag pcTag, org.dragonet.proxy.nbt.tag.CompoundTag target) { + public static org.dragonet.proxy.data.nbt.tag.CompoundTag translateRawNBT(int id, Tag pcTag, org.dragonet.proxy.data.nbt.tag.CompoundTag target) { if (pcTag != null) { String name = pcTag.getName() != null ? pcTag.getName() : ""; if (target == null) { - target = new org.dragonet.proxy.nbt.tag.CompoundTag(name); + target = new org.dragonet.proxy.data.nbt.tag.CompoundTag(name); } switch (pcTag.getClass().getSimpleName()) { case "ByteArrayTag": @@ -205,7 +197,7 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag case "ListTag": ListTag listTag = new ListTag(); for (Tag subTag : (List) pcTag.getValue()) { - listTag.add(translateRawNBT(0, subTag, new org.dragonet.proxy.nbt.tag.CompoundTag())); + listTag.add(translateRawNBT(0, subTag, new org.dragonet.proxy.data.nbt.tag.CompoundTag())); } target.putList(listTag); break; @@ -218,11 +210,11 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag } //WIP - public static org.dragonet.proxy.nbt.tag.CompoundTag translateBlockEntityToPE(com.github.steveice10.opennbt.tag.builtin.CompoundTag input) { + public static org.dragonet.proxy.data.nbt.tag.CompoundTag translateBlockEntityToPE(com.github.steveice10.opennbt.tag.builtin.CompoundTag input) { if (input == null) { return null; } - org.dragonet.proxy.nbt.tag.CompoundTag output = translateRawNBT(0, input, null); + org.dragonet.proxy.data.nbt.tag.CompoundTag output = translateRawNBT(0, input, null); if (output.contains("id")) { switch (output.getString("id")) { case "minecraft:bed": @@ -303,7 +295,7 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateBlockEntityToPE(co public static ItemStack translateToPC(Slot slot) { ItemStack item; - org.dragonet.proxy.nbt.tag.CompoundTag tag = slot.tag; + org.dragonet.proxy.data.nbt.tag.CompoundTag tag = slot.tag; if (tag != null && tag.contains(DRAGONET_COMPOUND)) { item = new ItemStack(tag.getCompound(DRAGONET_COMPOUND).getShort("id"), tag.getCompound(DRAGONET_COMPOUND).getShort("amount"), @@ -320,7 +312,6 @@ public static BlockFace translateToPC(int face) { return BlockFace.values()[Math.abs(face % 6)]; } - // private private static void swap(int pcId, int peId) { PC_TO_PE_OVERRIDE.put(pcId, new ItemEntry(peId)); PE_TO_PC_OVERRIDE.put(peId, new ItemEntry(pcId)); diff --git a/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java new file mode 100644 index 000000000..6ac6c8e5c --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/MessageTranslator.java @@ -0,0 +1,120 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator; + +import com.github.steveice10.mc.protocol.data.message.ChatColor; +import com.github.steveice10.mc.protocol.data.message.ChatFormat; +import com.github.steveice10.mc.protocol.data.message.Message; + +import java.util.List; + +public final class MessageTranslator { + + public static String translate(Message message) { + StringBuilder build = new StringBuilder(message.getText()); + for (Message msg : message.getExtra()) { + build.append(toMinecraftColor(msg.getStyle().getColor())); + build.append(toMinecraftFormat(msg.getStyle().getFormats())); + build.append(msg.getFullText()); + } + return build.toString(); + } + + public static String toMinecraftColor(ChatColor color) { + String base = "\u00a7"; + switch (color) { + case AQUA: + base += "b"; + break; + case BLACK: + base += "0"; + break; + case BLUE: + base += "9"; + break; + case DARK_AQUA: + base += "3"; + break; + case DARK_BLUE: + base += "1"; + break; + case DARK_GRAY: + base += "8"; + break; + case DARK_GREEN: + base += "2"; + break; + case DARK_PURPLE: + base += "5"; + break; + case DARK_RED: + base += "4"; + break; + case GOLD: + base += "6"; + break; + case GRAY: + base += "7"; + break; + case GREEN: + base += "a"; + break; + case LIGHT_PURPLE: + base += "d"; + break; + case RED: + base += "c"; + break; + case RESET: + base += "r"; + break; + case WHITE: + base += "f"; + break; + case YELLOW: + base += "e"; + break; + default: + break; + } + return base; + } + + private static String toMinecraftFormat(List formats) { + String superBase = ""; + for (ChatFormat cf : formats) { + String base = "\u00a7"; + switch (cf) { + case BOLD: + base += "l"; + break; + case ITALIC: + base += "o"; + break; + case OBFUSCATED: + base += "k"; + break; + case STRIKETHROUGH: + base += "m"; + break; + case UNDERLINED: + base += "n"; + break; + default: + break; + } + superBase += base; + } + return superBase; + } +} diff --git a/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java new file mode 100644 index 000000000..f059cab70 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/inv/ChestWindowTranslator.java @@ -0,0 +1,78 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.inv; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.IntTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; + +import org.dragonet.proxy.data.inventory.InventoryType; +import org.dragonet.proxy.network.CacheKey; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedWindow; +import org.dragonet.proxy.network.translator.IInventoryTranslator; +import org.dragonet.proxy.network.translator.ItemBlockTranslator; +import org.dragonet.proxy.protocol.packets.BlockEntityDataPacket; +import org.dragonet.proxy.protocol.packets.ContainerOpenPacket; +import org.dragonet.proxy.protocol.packets.InventoryContentPacket; +import org.dragonet.proxy.protocol.type.Slot; +import org.dragonet.proxy.utilities.BlockPosition; + +public class ChestWindowTranslator implements IInventoryTranslator { + + public boolean open(UpstreamSession session, CachedWindow window) { + Position pos = new Position((int) session.getEntityCache().getClientEntity().x, + (int) session.getEntityCache().getClientEntity().y - 4, + (int) session.getEntityCache().getClientEntity().z); + session.getDataCache().put(CacheKey.WINDOW_OPENED_ID, window.windowId); + session.getDataCache().put(CacheKey.WINDOW_BLOCK_POSITION, pos); + session.sendFakeBlock(pos.getX(), pos.getY(), pos.getZ(), 54, 0); + CompoundTag tag = new CompoundTag(null); + tag.put(new StringTag("id", "Chest")); + tag.put(new IntTag("x", pos.getX())); + tag.put(new IntTag("y", pos.getY())); + tag.put(new IntTag("z", pos.getZ())); + BlockEntityDataPacket blockEntityData = new BlockEntityDataPacket(); + blockEntityData.blockPosition = new BlockPosition(pos.getX(), pos.getY(), pos.getZ()); + blockEntityData.tag = tag; + session.sendPacket(blockEntityData); + + ContainerOpenPacket pk = new ContainerOpenPacket(); + pk.windowId = window.windowId; + // pk. = window.size <= 27 ? (short)(InventoryType.SlotSize.CHEST & 0xFFFF) : + // (short)(InventoryType.SlotSize.DOUBLE_CHEST & 0xFFFF); + pk.type = window.size <= 27 ? InventoryType.PEInventory.CHEST : InventoryType.PEInventory.DOUBLE_CHEST; + pk.position = new BlockPosition(pos.getX(), pos.getY(), pos.getZ()); + session.sendPacket(pk); + return true; + } + + public void updateContent(UpstreamSession session, CachedWindow window) { + sendContent(session, window); + } + + public void updateSlot(UpstreamSession session, CachedWindow window, int slotIndex) { + sendContent(session, window);// TOO LAZY LOL + } + + private void sendContent(UpstreamSession session, CachedWindow win) { + InventoryContentPacket pk = new InventoryContentPacket(); + pk.windowId = (byte) (win.windowId & 0xFF); + pk.items = new Slot[win.slots.length]; + for (int i = 0; i < pk.items.length; i++) { + pk.items[i] = ItemBlockTranslator.translateSlotToPE(win.slots[i]); + } + session.sendPacket(pk, true); + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java index 92ab865fb..df0d78c51 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java @@ -21,10 +21,6 @@ public class PCAnimationPacketTranslator implements IPCPacketTranslator { - public PCAnimationPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerEntityAnimationPacket packet) { CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java similarity index 60% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java index a8f6c5ad5..678b714eb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java @@ -22,26 +22,16 @@ import org.dragonet.proxy.utilities.BlockPosition; public class PCBlockChangePacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCBlockChangePacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerBlockChangePacket packet) { - UpdateBlockPacket pk = new UpdateBlockPacket(); - pk.flags = UpdateBlockPacket.FLAG_NEIGHBORS << 4; - ItemEntry entry = ItemBlockTranslator.translateToPE(packet.getRecord().getBlock().getId(), packet.getRecord().getBlock().getData()); - - pk.data = entry.damage; - pk.id = entry.id; - pk.blockPosition = new BlockPosition(packet.getRecord().getPosition().getX(), - packet.getRecord().getPosition().getY(), packet.getRecord().getPosition().getZ()); - return new PEPacket[] { pk }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerBlockChangePacket packet) { + UpdateBlockPacket pk = new UpdateBlockPacket(); + pk.flags = UpdateBlockPacket.FLAG_NEIGHBORS << 4; + ItemEntry entry = ItemBlockTranslator.translateToPE(packet.getRecord().getBlock().getId(), packet.getRecord().getBlock().getData()); + + pk.data = entry.damage; + pk.id = entry.id; + pk.blockPosition = new BlockPosition(packet.getRecord().getPosition().getX(), + packet.getRecord().getPosition().getY(), packet.getRecord().getPosition().getZ()); + return new PEPacket[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java similarity index 53% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java index 8aa16a04d..429ae1c0c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java @@ -21,48 +21,37 @@ import org.dragonet.proxy.protocol.packets.TextPacket; public class PCChatPacketTranslator implements IPCPacketTranslator { - // vars - public static final byte TYPE_RAW = 0; - public static final byte TYPE_CHAT = 1; - public static final byte TYPE_TRANSLATION = 2; - public static final byte TYPE_POPUP = 3; - public static final byte TYPE_TIP = 4; - public static final byte TYPE_SYSTEM = 5; - public static final byte TYPE_WHISPER = 6; - public static final byte TYPE_ANNOUNCEMENT = 7; - // constructor - public PCChatPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerChatPacket packet) { - TextPacket pe = new TextPacket(); - if (packet.getMessage() instanceof TranslationMessage) - { - pe.type = TYPE_TRANSLATION; - pe.message = pe.message = MessageTranslator.translate(packet.getMessage()); - } - else - { - pe.type = TYPE_RAW; - pe.message = pe.message = MessageTranslator.translate(packet.getMessage()); - } - - return new PEPacket[] { pe }; - - // TODO: Detect type - /* + public static final byte TYPE_RAW = 0; + public static final byte TYPE_CHAT = 1; + public static final byte TYPE_TRANSLATION = 2; + public static final byte TYPE_POPUP = 3; + public static final byte TYPE_TIP = 4; + public static final byte TYPE_SYSTEM = 5; + public static final byte TYPE_WHISPER = 6; + public static final byte TYPE_ANNOUNCEMENT = 7; + + + public PEPacket[] translate(UpstreamSession session, ServerChatPacket packet) { + TextPacket pe = new TextPacket(); + if (packet.getMessage() instanceof TranslationMessage) { + pe.type = TYPE_TRANSLATION; + pe.message = pe.message = MessageTranslator.translate(packet.getMessage()); + } else { + pe.type = TYPE_RAW; + pe.message = pe.message = MessageTranslator.translate(packet.getMessage()); + } + + return new PEPacket[]{pe}; + + // TODO: Detect type + /* * Reset the chat message so we can parse the JSON again (if needed) - */ - /* + */ + /* * switch (packet.getType()) { case CHAT: ret.type = ChatPacket.TextType.CHAT; * break; case NOTIFICATION: case SYSTEM: default: ret.type = * ChatPacket.TextType.CHAT; break; } return new PEPacket[]{ret}; - */ - } - - // private - + */ + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java similarity index 62% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java index 2ad1670b9..04322b6fa 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCDestroyEntitiesPacketTranslator.java @@ -20,27 +20,17 @@ import org.dragonet.proxy.protocol.packets.RemoveEntityPacket; public class PCDestroyEntitiesPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCDestroyEntitiesPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityDestroyPacket packet) { - PEPacket[] ret = new PEPacket[packet.getEntityIds().length]; - for (int i = 0; i < ret.length; i++) { - CachedEntity e = session.getEntityCache().removeByRemoteEID(packet.getEntityIds()[i]); - if (e == null) { - continue; - } - ret[i] = new RemoveEntityPacket(); - ((RemoveEntityPacket) ret[i]).eid = e.proxyEid; - } - return ret; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerEntityDestroyPacket packet) { + PEPacket[] ret = new PEPacket[packet.getEntityIds().length]; + for (int i = 0; i < ret.length; i++) { + CachedEntity e = session.getEntityCache().removeByRemoteEID(packet.getEntityIds()[i]); + if (e == null) { + continue; + } + ret[i] = new RemoveEntityPacket(); + ((RemoveEntityPacket) ret[i]).eid = e.proxyEid; + } + return ret; + } } diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java new file mode 100644 index 000000000..d6935ce0b --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEffectPacketTranslator.java @@ -0,0 +1,56 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pc; + +import com.github.steveice10.mc.protocol.data.MagicValues; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket; +import org.dragonet.proxy.data.PocketPotionEffect; +import org.dragonet.proxy.network.CacheKey; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedEntity; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.MobEffectPacket; +import org.dragonet.proxy.utilities.Logger; + +public class PCEntityEffectPacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerEntityEffectPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + return null; + } + int effectId = MagicValues.value(Integer.class, packet.getEffect()); + + PocketPotionEffect effect = PocketPotionEffect.getByID(effectId); + if (effect == null) { + System.out.println("Unknown effect ID: " + effectId); + return null; + } + + MobEffectPacket eff = new MobEffectPacket(); + eff.rtid = packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID) ? 1L + : entity.proxyEid; + eff.effectId = effect.getEffect(); + if (entity.effects.contains(effectId)) { + eff.eventId = MobEffectPacket.EVENT_MODIFY; + } else { + eff.eventId = MobEffectPacket.EVENT_ADD; + entity.effects.add(effectId); + } + eff.amplifier = packet.getAmplifier(); + eff.duration = packet.getDuration(); + eff.particles = packet.getShowParticles(); + return new PEPacket[]{eff}; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java similarity index 90% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java index a0c5a3265..6e160e505 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java @@ -13,10 +13,10 @@ package org.dragonet.proxy.network.translator.pc; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; -import org.dragonet.proxy.entity.EntityType; -import org.dragonet.proxy.entity.PEEntityAttribute; -import org.dragonet.proxy.entity.meta.EntityMetaData; -import org.dragonet.proxy.entity.meta.type.SlotMeta; +import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.data.entity.PEEntityAttribute; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.type.SlotMeta; import org.dragonet.proxy.network.CacheKey; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; @@ -30,13 +30,9 @@ public class PCEntityMetadataPacketTranslator implements IPCPacketTranslator { - public PCEntityMetadataPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) { CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - System.out.println("ServerEntityMetadataPacket entity " + packet.getEntityId() + " update "); +// System.out.println("ServerEntityMetadataPacket entity " + packet.getEntityId() + " update "); if (entity == null) { if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) { entity = session.getEntityCache().getClientEntity(); diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java index 6c963bb30..85562b1ec 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java @@ -23,10 +23,6 @@ public class PCEntityPositionPacketTranslator implements IPCPacketTranslator { - public PCEntityPositionPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerEntityPositionPacket packet) { CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); if (e == null) { diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java new file mode 100644 index 000000000..9c0e8e8ca --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionRotationPacketTranslator.java @@ -0,0 +1,46 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pc; + +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedEntity; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.MoveEntityPacket; +import org.dragonet.proxy.utilities.Constants; +import org.dragonet.proxy.utilities.Vector3F; + +public class PCEntityPositionRotationPacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerEntityPositionRotationPacket packet) { + CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (e == null) { + return null; + } + + e.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), + packet.getPitch()); + + MoveEntityPacket pk = new MoveEntityPacket(); + pk.rtid = e.proxyEid; + pk.yaw = (byte) (e.yaw / (360d / 256d)); + pk.headYaw = (byte) (e.yaw / (360d / 256d)); + pk.pitch = (byte) (e.pitch / (360d / 256d)); + pk.position = new Vector3F((float) e.x, (float) e.y, (float) e.z); + if (e.player) { + pk.position.y += Constants.PLAYER_HEAD_OFFSET; + } + return new PEPacket[]{pk}; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java similarity index 58% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java index 198c3f563..38fa9fe91 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRemoveEffectPacketTranslator.java @@ -22,30 +22,20 @@ import org.dragonet.proxy.protocol.packets.MobEffectPacket; public class PCEntityRemoveEffectPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityRemoveEffectPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityRemoveEffectPacket packet) { - CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (entity == null) { - return null; - } - int effectId = MagicValues.value(Integer.class, packet.getEffect()); - if (!entity.effects.contains(effectId)) { - return null; - } - MobEffectPacket eff = new MobEffectPacket(); - eff.rtid = packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID) ? 1L - : entity.proxyEid; - eff.eventId = MobEffectPacket.EVENT_REMOVE; - return new PEPacket[] { eff }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerEntityRemoveEffectPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + return null; + } + int effectId = MagicValues.value(Integer.class, packet.getEffect()); + if (!entity.effects.contains(effectId)) { + return null; + } + MobEffectPacket eff = new MobEffectPacket(); + eff.rtid = packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID) ? 1L + : entity.proxyEid; + eff.eventId = MobEffectPacket.EVENT_REMOVE; + return new PEPacket[]{eff}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java index 58e96a2cf..42e7dd905 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java @@ -23,10 +23,6 @@ public class PCEntityRotationPacketTranslator implements IPCPacketTranslator { - public PCEntityRotationPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerEntityRotationPacket packet) { CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); if (e == null) { diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java similarity index 83% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java index 0f6a1fda8..0c87d77e1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java @@ -23,18 +23,14 @@ public class PCEntitySetPassengerPacketTranslator implements IPCPacketTranslator { - public PCEntitySetPassengerPacketTranslator() { - - } - - public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPacket packet) - { + public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPacket packet) { CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); if (entity == null) { - if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) + if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) { entity = session.getEntityCache().getClientEntity(); - else + } else { return null; + } } SetEntityLinkPacket pk = new SetEntityLinkPacket(); @@ -46,36 +42,28 @@ public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPa pk.type = 0; pk.unknownByte = 0x00; session.sendPacket(pk); - } - else //mount + } else //mount { boolean piloteSet = false; - for (int id : packet.getPassengerIds()) - { + for (int id : packet.getPassengerIds()) { CachedEntity riding = session.getEntityCache().getByRemoteEID(id); if (riding == null) { continue; } - + pk.riding = riding.proxyEid; - - if (!piloteSet) - { + + if (!piloteSet) { pk.type = 1; piloteSet = true; - } - else - { + } else { pk.type = 2; } pk.unknownByte = 0x00; session.sendPacket(pk); - } - - } return null; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java similarity index 58% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java index 3c402eca9..028c5952f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityVelocityPacketTranslator.java @@ -21,29 +21,19 @@ import org.dragonet.proxy.utilities.Vector3F; public class PCEntityVelocityPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityVelocityPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityVelocityPacket packet) { - CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (entity == null) { - return null; - } - entity.motionX = packet.getMotionX(); - entity.motionY = packet.getMotionY(); - entity.motionZ = packet.getMotionZ(); - - SetEntityMotionPacket pk = new SetEntityMotionPacket(); - pk.rtid = entity.proxyEid; - pk.motion = new Vector3F((float) packet.getMotionX(), (float) packet.getMotionY(), (float) packet.getMotionZ()); - return new PEPacket[] { pk }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerEntityVelocityPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + return null; + } + entity.motionX = packet.getMotionX(); + entity.motionY = packet.getMotionY(); + entity.motionZ = packet.getMotionZ(); + + SetEntityMotionPacket pk = new SetEntityMotionPacket(); + pk.rtid = entity.proxyEid; + pk.motion = new Vector3F((float) packet.getMotionX(), (float) packet.getMotionY(), (float) packet.getMotionZ()); + return new PEPacket[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java similarity index 65% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java index 00da03cb7..32eff7eb9 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCJoinGamePacketTranslator.java @@ -19,22 +19,12 @@ import org.dragonet.proxy.protocol.PEPacket; public class PCJoinGamePacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCJoinGamePacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerJoinGamePacket packet) { - session.getDataCache().put(CacheKey.PLAYER_EID, packet.getEntityId()); // Stores the real entity ID - - // This packet is not fully useable, we cache it for now. - session.getDataCache().put(CacheKey.PACKET_JOIN_GAME_PACKET, packet); - return null; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerJoinGamePacket packet) { + session.getDataCache().put(CacheKey.PLAYER_EID, packet.getEntityId()); // Stores the real entity ID + // This packet is not fully useable, we cache it for now. + session.getDataCache().put(CacheKey.PACKET_JOIN_GAME_PACKET, packet); + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java similarity index 53% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java index 8066fb763..1b3496004 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java @@ -23,34 +23,23 @@ import org.dragonet.proxy.utilities.BlockPosition; public class PCMultiBlockChangePacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCMultiBlockChangePacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacket packet) { - UpdateBlockPacket[] packets = new UpdateBlockPacket[packet.getRecords().length]; - int generalFlag = packet.getRecords().length > 64 ? UpdateBlockPacket.FLAG_ALL_PRIORITY - : UpdateBlockPacket.FLAG_NEIGHBORS; - for (int i = 0; i < packets.length; i++) { - packets[i] = new UpdateBlockPacket(); - packets[i].blockPosition = new BlockPosition(packet.getRecords()[i].getPosition().getX(), - packet.getRecords()[i].getPosition().getY(), packet.getRecords()[i].getPosition().getZ()); - - - BlockState block = packet.getRecords()[i].getBlock(); - ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); - - packets[i].id = entry.id; - packets[i].flags = generalFlag; - packets[i].data = entry.damage; - } - return packets; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacket packet) { + UpdateBlockPacket[] packets = new UpdateBlockPacket[packet.getRecords().length]; + int generalFlag = packet.getRecords().length > 64 ? UpdateBlockPacket.FLAG_ALL_PRIORITY + : UpdateBlockPacket.FLAG_NEIGHBORS; + for (int i = 0; i < packets.length; i++) { + packets[i] = new UpdateBlockPacket(); + packets[i].blockPosition = new BlockPosition(packet.getRecords()[i].getPosition().getX(), + packet.getRecords()[i].getPosition().getY(), packet.getRecords()[i].getPosition().getZ()); + + BlockState block = packet.getRecords()[i].getBlock(); + ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); + + packets[i].id = entry.id; + packets[i].flags = generalFlag; + packets[i].data = entry.damage; + } + return packets; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java similarity index 91% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index d7189ee73..325f3d55e 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; -import org.dragonet.proxy.nbt.NBTIO; +import org.dragonet.proxy.data.nbt.NBTIO; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.ItemBlockTranslator; import org.dragonet.proxy.network.translator.IPCPacketTranslator; @@ -31,14 +31,7 @@ import org.dragonet.proxy.protocol.type.chunk.Section; public class PCMultiChunkDataPacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCMultiChunkDataPacketTranslator() { - - } - - // public public PEPacket[] translate(UpstreamSession session, ServerChunkDataPacket packet) { session.getProxy().getGeneralThreadPool().execute(() -> { try { @@ -60,7 +53,6 @@ public PEPacket[] translate(UpstreamSession session, ServerChunkDataPacket packe return null; } - // private private void processChunkSection(Column pc, ChunkData pe) { /* * pe.sections = new Section[16]; for(int i = 0; i < 16; i++) { pe.sections[i] = @@ -75,8 +67,9 @@ private void processChunkSection(Column pc, ChunkData pe) { int cy = y >> 4; Chunk c = pc.getChunks()[cy]; - if (c == null || c.isEmpty()) + if (c == null || c.isEmpty()) { continue; + } BlockStorage blocks = c.getBlocks(); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { @@ -103,17 +96,13 @@ private void processChunkSection(Column pc, ChunkData pe) { } } // Blocks entities - try - { + try { pe.blockEntities = new byte[pc.getTileEntities().length]; - for (int i = 0; i < pc.getTileEntities().length; i++) - { - org.dragonet.proxy.nbt.tag.CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(pc.getTileEntities()[i]); + for (int i = 0; i < pc.getTileEntities().length; i++) { + org.dragonet.proxy.data.nbt.tag.CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(pc.getTileEntities()[i]); pe.blockEntities = NBTIO.write(peTag); } - } - catch (IOException ex) - { + } catch (IOException ex) { Logger.getLogger(PCMultiChunkDataPacketTranslator.class.getName()).log(Level.SEVERE, null, ex); } } diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java new file mode 100644 index 000000000..44d57a57f --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCNotifyClientPacketTranslator.java @@ -0,0 +1,47 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pc; + +import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.LevelEventPacket; +import org.dragonet.proxy.protocol.packets.SetPlayerGameTypePacket; + +public class PCNotifyClientPacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerNotifyClientPacket packet) { + switch (packet.getNotification()) { + case CHANGE_GAMEMODE: + GameMode gm = (GameMode) packet.getValue(); + SetPlayerGameTypePacket pk = new SetPlayerGameTypePacket(); + if (gm == GameMode.CREATIVE) { + pk.gamemode = 1; + } else { + pk.gamemode = 0; + } + return new PEPacket[]{pk}; + case START_RAIN: + LevelEventPacket evtStartRain = new LevelEventPacket(); + evtStartRain.eventId = LevelEventPacket.EVENT_START_RAIN; + return new PEPacket[]{evtStartRain}; + case STOP_RAIN: + LevelEventPacket evtStopRain = new LevelEventPacket(); + evtStopRain.eventId = LevelEventPacket.EVENT_STOP_RAIN; + return new PEPacket[]{evtStopRain}; + } + return null; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java similarity index 72% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java index 440313530..572e9655d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCOpenWindowPacketTranslator.java @@ -19,21 +19,11 @@ import org.dragonet.proxy.protocol.PEPacket; public class PCOpenWindowPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCOpenWindowPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerOpenWindowPacket packet) { - session.getProxy().getGeneralThreadPool().execute(() -> { - InventoryTranslatorRegister.open(session, packet); - }); - return null; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerOpenWindowPacket packet) { + session.getProxy().getGeneralThreadPool().execute(() -> { + InventoryTranslatorRegister.open(session, packet); + }); + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java similarity index 52% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java index 236617267..891448a51 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlaySoundPacketTranslator.java @@ -22,39 +22,29 @@ import org.dragonet.proxy.utilities.BlockPosition; public class PCPlaySoundPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCPlaySoundPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) { - try { - String soundName; - - if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) { - BuiltinSound sound = (BuiltinSound) packet.getSound(); - soundName = sound.name(); - } else { - soundName = ((CustomSound) packet.getSound()).getName(); - } - if (soundName == null) { - return null; - } - PlaySoundPacket pk = new PlaySoundPacket(); - pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ()); - pk.name = soundName; - pk.volume = packet.getVolume(); - pk.pitch = packet.getPitch(); - return new PEPacket[] { pk }; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) { + try { + String soundName; + + if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) { + BuiltinSound sound = (BuiltinSound) packet.getSound(); + soundName = sound.name(); + } else { + soundName = ((CustomSound) packet.getSound()).getName(); + } + if (soundName == null) { + return null; + } + PlaySoundPacket pk = new PlaySoundPacket(); + pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ()); + pk.name = soundName; + pk.volume = packet.getVolume(); + pk.pitch = packet.getPitch(); + return new PEPacket[]{pk}; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java index 1cedd96c4..7a3c47d91 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java @@ -25,10 +25,6 @@ public class PCPlayerListItemPacketTranslator implements IPCPacketTranslator { - public PCPlayerListItemPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerPlayerListEntryPacket packet) { PlayerListPacket pk = new PlayerListPacket(); if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) { diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java similarity index 94% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java index 913c784eb..34dfce6f8 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java @@ -13,7 +13,6 @@ package org.dragonet.proxy.network.translator.pc; import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; -import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility; @@ -23,8 +22,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import org.dragonet.proxy.configuration.Lang; -import org.dragonet.proxy.entity.PEEntityAttribute; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.PEEntityAttribute; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.network.CacheKey; import org.dragonet.proxy.network.PCDownstreamSession; import org.dragonet.proxy.protocol.PEPacket; @@ -36,29 +35,18 @@ import com.google.common.io.ByteStreams; import java.util.HashSet; import java.util.Set; -import org.dragonet.proxy.entity.EntityType; -import org.dragonet.proxy.entity.meta.type.ByteArrayMeta; -import org.dragonet.proxy.entity.meta.type.SlotMeta; -import org.dragonet.proxy.nbt.tag.CompoundTag; +import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.data.entity.meta.type.ByteArrayMeta; +import org.dragonet.proxy.data.entity.meta.type.SlotMeta; import org.dragonet.proxy.network.translator.EntityMetaTranslator; -import org.dragonet.proxy.network.translator.ItemBlockTranslator; import org.dragonet.proxy.protocol.packets.*; import org.dragonet.proxy.protocol.type.Skin; -import org.dragonet.proxy.protocol.type.Slot; import org.dragonet.proxy.utilities.BlockPosition; import org.dragonet.proxy.utilities.Constants; import org.dragonet.proxy.utilities.Vector3F; -public class PCPlayerPositionRotationPacketTranslator - implements IPCPacketTranslator { - // vars +public class PCPlayerPositionRotationPacketTranslator implements IPCPacketTranslator { - // constructor - public PCPlayerPositionRotationPacketTranslator() { - - } - - // public public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotationPacket packet) { if (!session.isSpawned()) { System.out.println("SPAWNED! "); @@ -260,14 +248,10 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotatio cliEntity.yaw = packet.getYaw(); cliEntity.pitch = packet.getPitch(); - // session.sendChat(String.format("FORCING TO (%.2f, %.2f, %.2f", packet.getX(), - // packet.getY(), packet.getZ())); // send the confirmation ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId()); ((PCDownstreamSession) session.getDownstream()).send(confirm); return new PEPacket[]{pk}; } - - // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java similarity index 50% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java index af3dab6e3..e1bb666bd 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSetSlotPacketTranslator.java @@ -20,33 +20,25 @@ import org.dragonet.proxy.protocol.PEPacket; public class PCSetSlotPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCSetSlotPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerSetSlotPacket packet) { - if (!session.getWindowCache().hasWindow(packet.getWindowId())) { - // Cache this - session.getWindowCache().newCachedPacket(packet.getWindowId(), packet); - return null; - } - CachedWindow win = session.getWindowCache().get(packet.getWindowId()); - if (win.pcType == null && packet.getWindowId() != 0) - return null; - if (packet.getWindowId() == 0) { - if (packet.getSlot() >= win.slots.length) - return null; - win.slots[packet.getSlot()] = packet.getItem(); - return InventoryTranslatorRegister.sendPlayerInventory(session); // Too lazy lol - } - InventoryTranslatorRegister.updateSlot(session, packet); - return null; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerSetSlotPacket packet) { + if (!session.getWindowCache().hasWindow(packet.getWindowId())) { + // Cache this + session.getWindowCache().newCachedPacket(packet.getWindowId(), packet); + return null; + } + CachedWindow win = session.getWindowCache().get(packet.getWindowId()); + if (win.pcType == null && packet.getWindowId() != 0) { + return null; + } + if (packet.getWindowId() == 0) { + if (packet.getSlot() >= win.slots.length) { + return null; + } + win.slots[packet.getSlot()] = packet.getItem(); + return InventoryTranslatorRegister.sendPlayerInventory(session); // Too lazy lol + } + InventoryTranslatorRegister.updateSlot(session, packet); + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java index 7f027bdfe..46cbba6f9 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java @@ -21,10 +21,6 @@ public class PCSoundEventPacketTranslator implements IPCPacketTranslator { - public PCSoundEventPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerPlayBuiltinSoundPacket packet) { LevelSoundEventPacket pk = new LevelSoundEventPacket(); pk.position = new Vector3F((float) packet.getX(), (float) packet.getY(), (float) packet.getZ()); diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java similarity index 84% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java index bced7f5e8..26ffaa83f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java @@ -12,13 +12,13 @@ */ package org.dragonet.proxy.network.translator.pc; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.network.translator.IPCPacketTranslator; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; -import org.dragonet.proxy.entity.EntityType; -import org.dragonet.proxy.entity.PEEntityAttribute; +import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.data.entity.PEEntityAttribute; import org.dragonet.proxy.network.translator.EntityMetaTranslator; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.packets.AddEntityPacket; @@ -26,14 +26,10 @@ public class PCSpawnMobPacketTranslator implements IPCPacketTranslator { - public PCSpawnMobPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerSpawnMobPacket packet) { try { CachedEntity e = session.getEntityCache().newEntity(packet); - System.out.println("ServerSpawnObjectPacket register " + packet.getEntityId() + " entity " + (packet.getMetadata().length > 0 ? "has meta" : "no meta")); +// System.out.println("ServerSpawnObjectPacket register " + packet.getEntityId() + " entity " + (packet.getMetadata().length > 0 ? "has meta" : "no meta")); if (e == null) { return null; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java similarity index 95% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java index 6bfe1bbd9..4ea9cc5f9 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java @@ -19,10 +19,6 @@ public class PCSpawnObjectPacketTranslator implements IPCPacketTranslator { - public PCSpawnObjectPacketTranslator() { - - } - public PEPacket[] translate(UpstreamSession session, ServerSpawnObjectPacket packet) { session.getEntityCache().newEntity(packet); // System.out.println("ServerSpawnObjectPacket register " + packet.getEntityId() + " entity " + packet.getType().name()); diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java new file mode 100644 index 000000000..8fd698593 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnPlayerPacketTranslator.java @@ -0,0 +1,52 @@ +package org.dragonet.proxy.network.translator.pc; + +import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedEntity; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.data.entity.meta.type.ByteArrayMeta; +import org.dragonet.proxy.network.translator.EntityMetaTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.AddPlayerPacket; +import org.dragonet.proxy.protocol.packets.PlayerSkinPacket; +import org.dragonet.proxy.utilities.Constants; +import org.dragonet.proxy.utilities.Vector3F; + +public class PCSpawnPlayerPacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerSpawnPlayerPacket packet) { + try { + CachedEntity entity = session.getEntityCache().newPlayer(packet); + + if (session.isSpawned()) { + PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId); + AddPlayerPacket pkAddPlayer = new AddPlayerPacket(); + pkAddPlayer.eid = entity.proxyEid; + pkAddPlayer.rtid = entity.proxyEid; + pkAddPlayer.username = playerListEntry.getProfile().getName(); + + pkAddPlayer.uuid = packet.getUUID(); + + pkAddPlayer.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, (float) packet.getZ()); + pkAddPlayer.motion = Vector3F.ZERO; + pkAddPlayer.yaw = packet.getYaw(); + pkAddPlayer.pitch = packet.getPitch(); + + pkAddPlayer.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, EntityType.PLAYER); + pkAddPlayer.meta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta(playerListEntry.getProfile().getName())); //hacky for now + + PlayerSkinPacket skin = new PlayerSkinPacket(packet.getUUID()); + + return new PEPacket[]{pkAddPlayer, skin}; + } + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java similarity index 65% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java index 75df28ce1..6da4d8d37 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateHealthPacketTranslator.java @@ -20,26 +20,16 @@ import org.dragonet.proxy.protocol.packets.SetHealthPacket; public class PCUpdateHealthPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCUpdateHealthPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) { - SetHealthPacket h = new SetHealthPacket((int) packet.getHealth()); - if (packet.getHealth() > 0 && h.health <= 0) { - h.health = 1; - } - if (packet.getHealth() <= 0.0f) { - RespawnPacket r = new RespawnPacket(); - return new PEPacket[] { h, r }; - } - return new PEPacket[] { h }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) { + SetHealthPacket h = new SetHealthPacket((int) packet.getHealth()); + if (packet.getHealth() > 0 && h.health <= 0) { + h.health = 1; + } + if (packet.getHealth() <= 0.0f) { + RespawnPacket r = new RespawnPacket(); + return new PEPacket[]{h, r}; + } + return new PEPacket[]{h}; + } } diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java new file mode 100644 index 000000000..a17d74e94 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateSignPacketTranslator.java @@ -0,0 +1,49 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pc; + +import com.github.steveice10.mc.protocol.data.game.world.block.UpdatedTileType; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.IntTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; + +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.BlockEntityDataPacket; + +public class PCUpdateSignPacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerUpdateTileEntityPacket packet) { + if (packet.getType().equals(UpdatedTileType.SIGN)) { + CompoundTag root = new CompoundTag(null); + root.put(new StringTag("id", "Sign")); + root.put(new IntTag("x", packet.getPosition().getX())); + root.put(new IntTag("y", packet.getPosition().getY())); + root.put(new IntTag("z", packet.getPosition().getZ())); + root.put(new StringTag("Text1", (String) packet.getNBT().get("Text1").getValue())); + root.put(new StringTag("Text2", (String) packet.getNBT().get("Text2").getValue())); + root.put(new StringTag("Text3", (String) packet.getNBT().get("Text3").getValue())); + root.put(new StringTag("Text4", (String) packet.getNBT().get("Text4").getValue())); + + BlockEntityDataPacket data = new BlockEntityDataPacket(); + data.tag = root; + // packet.getPosition().getX(), packet.getPosition().getY(), + // packet.getPosition().getZ(), root + return new PEPacket[]{data}; + } else { + return null; + } + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java similarity index 73% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java index 0e3165d86..c37a92310 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCUpdateTimePacketTranslator.java @@ -19,20 +19,10 @@ import org.dragonet.proxy.protocol.packets.SetTimePacket; public class PCUpdateTimePacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCUpdateTimePacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerUpdateTimePacket packet) { - SetTimePacket pk = new SetTimePacket(); - pk.time = (int) Math.abs(packet.getTime()); - return new PEPacket[] { pk }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerUpdateTimePacket packet) { + SetTimePacket pk = new SetTimePacket(); + pk.time = (int) Math.abs(packet.getTime()); + return new PEPacket[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java similarity index 51% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java index 92130acd8..38d4c8010 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCWindowItemsTranslator.java @@ -20,34 +20,25 @@ import org.dragonet.proxy.protocol.PEPacket; public class PCWindowItemsTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCWindowItemsTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerWindowItemsPacket packet) { - if (!session.getWindowCache().hasWindow(packet.getWindowId())) { - // Cache this - session.getWindowCache().newCachedPacket(packet.getWindowId(), packet); - return null; - } - CachedWindow win = session.getWindowCache().get(packet.getWindowId()); - if (packet.getWindowId() == 0) { - if (packet.getItems().length < 40) { - // Almost impossible to happen either. - return null; - } - // Update items in window cache - win.slots = packet.getItems(); - return InventoryTranslatorRegister.sendPlayerInventory(session); - } - InventoryTranslatorRegister.updateContent(session, packet); - return null; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerWindowItemsPacket packet) { + if (!session.getWindowCache().hasWindow(packet.getWindowId())) { + // Cache this + session.getWindowCache().newCachedPacket(packet.getWindowId(), packet); + return null; + } + CachedWindow win = session.getWindowCache().get(packet.getWindowId()); + if (packet.getWindowId() == 0) { + if (packet.getItems().length < 40) { + // Almost impossible to happen either. + return null; + } + // Update items in window cache + win.slots = packet.getItems(); + return InventoryTranslatorRegister.sendPlayerInventory(session); + } + InventoryTranslatorRegister.updateContent(session, packet); + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java similarity index 88% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java index 668f6a170..c875a3352 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java @@ -20,12 +20,8 @@ public class PEAdventureSettingsPacketTranslator implements IPEPacketTranslator { - public PEAdventureSettingsPacketTranslator() { - - } - public Packet[] translate(UpstreamSession session, AdventureSettingsPacket packet) { - System.out.println(DebugTools.getAllFields(packet)); +// System.out.println(DebugTools.getAllFields(packet)); return null; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java similarity index 81% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java index d806e6e89..acddfb8c9 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java @@ -19,19 +19,11 @@ import org.dragonet.proxy.utilities.DebugTools; public class PEBlockPickRequestPacketTranslator implements IPEPacketTranslator { - // vars - // constructor - public PEBlockPickRequestPacketTranslator() { - - } - - // public public Packet[] translate(UpstreamSession session, BlockPickRequestPacket packet) { - System.out.println("BlockPickRequestPacket" + DebugTools.getAllFields(packet)); - +// System.out.println("BlockPickRequestPacket" + DebugTools.getAllFields(packet)); + return null; } - // private } diff --git a/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java new file mode 100644 index 000000000..47831d54e --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEChatPacketTranslator.java @@ -0,0 +1,53 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pe; + +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; +import com.github.steveice10.packetlib.packet.Packet; +import org.dragonet.proxy.configuration.Lang; +import org.dragonet.proxy.network.CacheKey; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.TextPacket; +import org.dragonet.proxy.utilities.PatternChecker; + +public class PEChatPacketTranslator implements IPEPacketTranslator { + + public Packet[] translate(UpstreamSession session, TextPacket packet) { + if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE) != null) { + if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("email")) { + if (!PatternChecker.matchEmail(packet.message.trim())) { + session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + return null; + } + session.getDataCache().put(CacheKey.AUTHENTICATION_EMAIL, packet.message.trim()); + session.getDataCache().put(CacheKey.AUTHENTICATION_STATE, "password"); + session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_PASSWORD)); + } else if (session.getDataCache().get(CacheKey.AUTHENTICATION_STATE).equals("password")) { + if (session.getDataCache().get(CacheKey.AUTHENTICATION_EMAIL) == null || packet.message.equals(" ")) { + session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_ERROR)); + return null; + } + session.sendChat(session.getProxy().getLang().get(Lang.MESSAGE_ONLINE_LOGGIN_IN)); + session.getDataCache().remove(CacheKey.AUTHENTICATION_STATE); + session.authenticate(packet.message); // We NEVER cache password for better security. + } + return null; + } + + ClientChatPacket pk = new ClientChatPacket(packet.message); + return new Packet[]{pk}; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java similarity index 66% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java index 95a580dc0..5cbf4bb96 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PECommandRequestPacketTranslator.java @@ -11,18 +11,8 @@ * Created on 2017/11/15. */ public class PECommandRequestPacketTranslator implements IPEPacketTranslator { - // vars - - // constructor - public PECommandRequestPacketTranslator() { - - } - - // public - public Packet[] translate(UpstreamSession session, PEPacket packet) { - return new Packet[] { new ClientChatPacket(((CommandRequestPacket) packet).command) }; - } - - // private + public Packet[] translate(UpstreamSession session, PEPacket packet) { + return new Packet[]{new ClientChatPacket(((CommandRequestPacket) packet).command)}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java similarity index 91% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java index bdc01402f..af5b180cf 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java @@ -22,10 +22,6 @@ public class PEInteractPacketTranslator implements IPEPacketTranslator { - public PEInteractPacketTranslator() { - - } - public Packet[] translate(UpstreamSession session, InteractPacket packet) { CachedEntity e = session.getEntityCache().getByLocalEID(packet.targetRtid); if (e == null) { @@ -39,7 +35,7 @@ public Packet[] translate(UpstreamSession session, InteractPacket packet) { return new Packet[]{new ClientPlayerInteractEntityPacket((int) (e.eid), InteractAction.INTERACT)}; } - System.out.println("InteractPacket type : " + packet.type + " on " + packet.targetRtid); +// System.out.println("InteractPacket type : " + packet.type + " on " + packet.targetRtid); return null; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java index 8f7a5f696..e19821af2 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java @@ -49,7 +49,7 @@ public Packet[] translate(UpstreamSession session, InventoryTransactionPacket pa switch (packet.transactionType) { case TYPE_NORMAL: //0 - System.out.println("TYPE_NORMAL"); +// System.out.println("TYPE_NORMAL"); List packets = new ArrayList(); for (InventoryTransactionAction action : packet.actions) { @@ -64,10 +64,10 @@ public Packet[] translate(UpstreamSession session, InventoryTransactionPacket pa } return packets.toArray(new Packet[]{}); case TYPE_MISMATCH: //1 - System.out.println("TYPE_MISMATCH"); +// System.out.println("TYPE_MISMATCH"); break; case TYPE_USE_ITEM: //2 - System.out.println("TYPE_USE_ITEM"); +// System.out.println("TYPE_USE_ITEM"); UseItemData useItemData = (UseItemData) packet.transactionData; if (useItemData.blockPos.equals(new BlockPosition(0, 0, 0))) { return null; @@ -98,7 +98,7 @@ public Packet[] translate(UpstreamSession session, InventoryTransactionPacket pa } case TYPE_USE_ITEM_ON_ENTITY: //3 - System.out.println("TYPE_USE_ITEM_ON_ENTITY"); +// System.out.println("TYPE_USE_ITEM_ON_ENTITY"); UseItemOnEntityData useItemOnEntityData = (UseItemOnEntityData) packet.transactionData; CachedEntity cachedEntity = session.getEntityCache().getByLocalEID(useItemOnEntityData.entityRuntimeId); if (cachedEntity == null) { @@ -114,7 +114,7 @@ public Packet[] translate(UpstreamSession session, InventoryTransactionPacket pa ); return new Packet[]{interractPacket}; case TYPE_RELEASE_ITEM: //4 - System.out.println("TYPE_RELEASE_ITEM"); +// System.out.println("TYPE_RELEASE_ITEM"); ReleaseItemData releaseItemData = (ReleaseItemData) packet.transactionData; // ClientPlayerActionPacket act = new ClientPlayerActionPacket( // com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java similarity index 96% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java index ae0ef78ff..4c3bf98dd 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java @@ -22,10 +22,6 @@ public class PEMovePlayerPacketTranslator implements IPEPacketTranslator { - public PEMovePlayerPacketTranslator() { - - } - public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) { ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, packet.position.y - Constants.PLAYER_HEAD_OFFSET, packet.position.z, packet.headYaw, diff --git a/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java new file mode 100644 index 000000000..4a6eb8f13 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerActionPacketTranslator.java @@ -0,0 +1,92 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view LICENCE file for details. + * + * @author The Dragonet Team + */ +package org.dragonet.proxy.network.translator.pe; + +import com.github.steveice10.mc.protocol.data.MagicValues; +import com.github.steveice10.mc.protocol.data.game.ClientRequest; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; +import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket; +import com.github.steveice10.packetlib.packet.Packet; +import org.dragonet.proxy.network.CacheKey; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.PlayerActionPacket; + +public class PEPlayerActionPacketTranslator implements IPEPacketTranslator { + + public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) { + if (packet.action == PlayerActionPacket.ACTION_RESPAWN) { + return new Packet[]{new ClientRequestPacket(ClientRequest.RESPAWN)}; + } + if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) { + ClientPlayerStatePacket stat = new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING); + return new Packet[]{stat}; + } + if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) { + ClientPlayerStatePacket stat = new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING); + return new Packet[]{stat}; + } + if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) { + ClientPlayerStatePacket stat = new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING); + return new Packet[]{stat}; + } + if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) { + ClientPlayerStatePacket stat = new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING); + return new Packet[]{stat}; + } + if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) { + ClientPlayerStatePacket stat = new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED); + return new Packet[]{stat}; + } + if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, + new Position(0, 0, 0), BlockFace.UP); + return new Packet[]{act}; + } + if (packet.action == PlayerActionPacket.ACTION_START_BREAK) { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, + new Position(packet.position.x, packet.position.y, packet.position.z), + MagicValues.key(BlockFace.class, packet.face)); + session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition()); + return new Packet[]{act}; + } + if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) { + if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, + (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), + MagicValues.key(BlockFace.class, packet.face)); + return new Packet[]{act}; + } + if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, + (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), + MagicValues.key(BlockFace.class, packet.face)); + return new Packet[]{act}; + } + } + return null; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java similarity index 90% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java index 87911602c..bffd8eca1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java @@ -25,24 +25,17 @@ import org.dragonet.proxy.protocol.packets.MobEquipmentPacket; public class PEPlayerEquipmentPacketTranslator implements IPEPacketTranslator { - // vars - // constructor - public PEPlayerEquipmentPacketTranslator() { - - } - - // public - public Packet[] translate(UpstreamSession session, MobEquipmentPacket packet) { + public Packet[] translate(UpstreamSession session, MobEquipmentPacket packet) { // System.out.println(org.dragonet.proxy.utilities.DebugTools.getAllFields(packet)); - if (packet.hotbarSlot > 8) { - return null; - } - if(packet.windowId == 0) { - return new Packet[] {new ClientPlayerChangeHeldItemPacket(packet.hotbarSlot)}; - } - return null; - /* + if (packet.hotbarSlot > 8) { + return null; + } + if (packet.windowId == 0) { + return new Packet[]{new ClientPlayerChangeHeldItemPacket(packet.hotbarSlot)}; + } + return null; + /* if (packet.inventorySlot == 0x28 || packet.inventorySlot == 0 || packet.inventorySlot == 255) { // That thing changed to air // TODO @@ -86,9 +79,6 @@ public Packet[] translate(UpstreamSession session, MobEquipmentPacket packet) { ClickItemParam.LEFT_CLICK); return new Packet[] { act1, act2 }; } - */ - } - - // private - + */ + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java similarity index 89% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java index c0469bf93..a325a2a88 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java @@ -19,18 +19,9 @@ import org.dragonet.proxy.utilities.DebugTools; public class PESoundEventPacketTranslator implements IPEPacketTranslator { - // vars - // constructor - public PESoundEventPacketTranslator() { - - } - - // public public Packet[] translate(UpstreamSession session, LevelSoundEventPacket packet) { System.out.println("LevelSoundEventPacket" + DebugTools.getAllFields(packet)); return null; } - - // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java similarity index 71% rename from proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java rename to src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java index b045f787a..e9851a71a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEWindowClosePacketTranslator.java @@ -19,21 +19,11 @@ import org.dragonet.proxy.protocol.packets.ContainerClosePacket; public class PEWindowClosePacketTranslator implements IPEPacketTranslator { - // vars - - // constructor - public PEWindowClosePacketTranslator() { - - } - - // public - public Packet[] translate(UpstreamSession session, ContainerClosePacket packet) { - session.getProxy().getGeneralThreadPool().execute(() -> { - InventoryTranslatorRegister.closeOpened(session, false); - }); - return null; - } - - // private + public Packet[] translate(UpstreamSession session, ContainerClosePacket packet) { + session.getProxy().getGeneralThreadPool().execute(() -> { + InventoryTranslatorRegister.closeOpened(session, false); + }); + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/PEPacket.java b/src/main/java/org/dragonet/proxy/protocol/PEPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/PEPacket.java rename to src/main/java/org/dragonet/proxy/protocol/PEPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java b/src/main/java/org/dragonet/proxy/protocol/Protocol.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java rename to src/main/java/org/dragonet/proxy/protocol/Protocol.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java b/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java rename to src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java similarity index 95% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java index dc426e101..9b1400296 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/AddEntityPacket.java @@ -1,7 +1,7 @@ package org.dragonet.proxy.protocol.packets; -import org.dragonet.proxy.entity.PEEntityAttribute; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.PEEntityAttribute; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; import org.dragonet.proxy.protocol.type.PEEntityLink; diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java similarity index 94% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java index e87aad077..0ab833427 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/AddItemEntityPacket.java @@ -1,6 +1,6 @@ package org.dragonet.proxy.protocol.packets; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; import org.dragonet.proxy.protocol.type.Slot; diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java similarity index 97% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java index e7c0523a1..98e85f943 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/AddPlayerPacket.java @@ -1,6 +1,6 @@ package org.dragonet.proxy.protocol.packets; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; import org.dragonet.proxy.protocol.type.PEEntityLink; diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockEntityDataPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/BlockEntityDataPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockEntityDataPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/BlockEntityDataPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ChangeDimensionPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ChangeDimensionPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ChangeDimensionPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ChangeDimensionPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ChunkRadiusUpdatedPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ChunkRadiusUpdatedPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ChunkRadiusUpdatedPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ChunkRadiusUpdatedPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/CommandRequestPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/CommandRequestPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/CommandRequestPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/CommandRequestPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ContainerClosePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ContainerClosePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ContainerClosePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ContainerClosePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ContainerOpenPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ContainerOpenPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ContainerOpenPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ContainerOpenPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/DisconnectPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/DisconnectPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/DisconnectPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/DisconnectPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/FullChunkDataPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/FullChunkDataPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/FullChunkDataPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/FullChunkDataPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryContentPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/InventoryContentPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryContentPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/InventoryContentPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventorySlotPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/InventorySlotPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventorySlotPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/InventorySlotPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelEventPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/LevelEventPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelEventPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/LevelEventPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LoginPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/LoginPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/LoginPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/LoginPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/MobEffectPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/MobEffectPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/MobEffectPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/MobEffectPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/MobEquipmentPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/MobEquipmentPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/MobEquipmentPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/MobEquipmentPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/MoveEntityPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/MoveEntityPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/MoveEntityPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/MoveEntityPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/MovePlayerPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/MovePlayerPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/MovePlayerPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/MovePlayerPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlaySoundPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlaySoundPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlaySoundPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlaySoundPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayStatusPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayStatusPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayStatusPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlayStatusPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerActionPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerActionPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerActionPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlayerActionPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerListPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerListPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerListPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlayerListPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerSkinPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerSkinPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerSkinPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/PlayerSkinPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/RemoveEntityPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/RemoveEntityPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/RemoveEntityPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/RemoveEntityPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/RequestChunkRadiusPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/RequestChunkRadiusPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/RequestChunkRadiusPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/RequestChunkRadiusPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackClientResponsePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackClientResponsePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackClientResponsePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackClientResponsePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackStackPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackStackPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackStackPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ResourcePackStackPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePacksInfoPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePacksInfoPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/ResourcePacksInfoPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/ResourcePacksInfoPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/RespawnPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/RespawnPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/RespawnPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/RespawnPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java similarity index 91% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java index 814b5a6ea..91248c09c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityDataPacket.java @@ -1,6 +1,6 @@ package org.dragonet.proxy.protocol.packets; -import org.dragonet.proxy.entity.meta.EntityMetaData; +import org.dragonet.proxy.data.entity.meta.EntityMetaData; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityMotionPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityMotionPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityMotionPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetEntityMotionPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetHealthPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetHealthPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetHealthPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetHealthPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetPlayerGameTypePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetPlayerGameTypePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetPlayerGameTypePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetPlayerGameTypePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetSpawnPositionPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetSpawnPositionPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetSpawnPositionPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetSpawnPositionPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetTimePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetTimePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetTimePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/SetTimePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/StartGamePacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/StartGamePacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/StartGamePacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/StartGamePacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/TextPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/TextPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/TextPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/TextPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java similarity index 93% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java index 269ffb8eb..0808cca7b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/UpdateAttributesPacket.java @@ -1,6 +1,6 @@ package org.dragonet.proxy.protocol.packets; -import org.dragonet.proxy.entity.PEEntityAttribute; +import org.dragonet.proxy.data.entity.PEEntityAttribute; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/UpdateBlockPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/UpdateBlockPacket.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/packets/UpdateBlockPacket.java rename to src/main/java/org/dragonet/proxy/protocol/packets/UpdateBlockPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java b/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java rename to src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/PEEntityLink.java b/src/main/java/org/dragonet/proxy/protocol/type/PEEntityLink.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/PEEntityLink.java rename to src/main/java/org/dragonet/proxy/protocol/type/PEEntityLink.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/PlayerListEntry.java b/src/main/java/org/dragonet/proxy/protocol/type/PlayerListEntry.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/PlayerListEntry.java rename to src/main/java/org/dragonet/proxy/protocol/type/PlayerListEntry.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/Skin.java b/src/main/java/org/dragonet/proxy/protocol/type/Skin.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/Skin.java rename to src/main/java/org/dragonet/proxy/protocol/type/Skin.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/Slot.java b/src/main/java/org/dragonet/proxy/protocol/type/Slot.java similarity index 93% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/Slot.java rename to src/main/java/org/dragonet/proxy/protocol/type/Slot.java index 7fa50fa9c..999f4bc36 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/type/Slot.java +++ b/src/main/java/org/dragonet/proxy/protocol/type/Slot.java @@ -1,7 +1,7 @@ package org.dragonet.proxy.protocol.type; -import org.dragonet.proxy.nbt.tag.CompoundTag; +import org.dragonet.proxy.data.nbt.tag.CompoundTag; /** * Created on 2017/10/21. diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/ChunkData.java b/src/main/java/org/dragonet/proxy/protocol/type/chunk/ChunkData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/ChunkData.java rename to src/main/java/org/dragonet/proxy/protocol/type/chunk/ChunkData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/ExtraData.java b/src/main/java/org/dragonet/proxy/protocol/type/chunk/ExtraData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/ExtraData.java rename to src/main/java/org/dragonet/proxy/protocol/type/chunk/ExtraData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/Section.java b/src/main/java/org/dragonet/proxy/protocol/type/chunk/Section.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/chunk/Section.java rename to src/main/java/org/dragonet/proxy/protocol/type/chunk/Section.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java b/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java rename to src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Binary.java b/src/main/java/org/dragonet/proxy/utilities/Binary.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Binary.java rename to src/main/java/org/dragonet/proxy/utilities/Binary.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/BinaryStream.java b/src/main/java/org/dragonet/proxy/utilities/BinaryStream.java similarity index 98% rename from proxy/src/main/java/org/dragonet/proxy/utilities/BinaryStream.java rename to src/main/java/org/dragonet/proxy/utilities/BinaryStream.java index 82dea7f32..45b8fa97f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/BinaryStream.java +++ b/src/main/java/org/dragonet/proxy/utilities/BinaryStream.java @@ -1,8 +1,8 @@ package org.dragonet.proxy.utilities; -import org.dragonet.proxy.entity.PEEntityAttribute; -import org.dragonet.proxy.nbt.NBTIO; -import org.dragonet.proxy.nbt.tag.CompoundTag; +import org.dragonet.proxy.data.entity.PEEntityAttribute; +import org.dragonet.proxy.data.nbt.NBTIO; +import org.dragonet.proxy.data.nbt.tag.CompoundTag; import org.dragonet.proxy.protocol.type.PEEntityLink; import org.dragonet.proxy.protocol.type.Slot; diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java b/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java rename to src/main/java/org/dragonet/proxy/utilities/BlockPosition.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Constants.java b/src/main/java/org/dragonet/proxy/utilities/Constants.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Constants.java rename to src/main/java/org/dragonet/proxy/utilities/Constants.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java b/src/main/java/org/dragonet/proxy/utilities/DebugTools.java similarity index 53% rename from proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java rename to src/main/java/org/dragonet/proxy/utilities/DebugTools.java index d677a652b..9383777e4 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java +++ b/src/main/java/org/dragonet/proxy/utilities/DebugTools.java @@ -38,17 +38,29 @@ public static String getAllFields(Object obj) { } Field[] fields = obj.getClass().getDeclaredFields(); String data = "INSTANCE OF " + obj.getClass().getName() + "\n"; - for(Field f : fields) { - if((f.getModifiers() & Modifier.STATIC) > 0) continue; - try { - if (isWrapperType(f.get(obj).getClass())) - data += f.getName() + " = " + f.get(obj).toString(); - else - data += f.getName() + " = " + getAllFields(f.get(obj)); - } catch (Exception e) { - data += ": " + f.getName() + " = ERROR"; + if (obj instanceof com.github.steveice10.opennbt.tag.builtin.CompoundTag) + { + data += ((com.github.steveice10.opennbt.tag.builtin.CompoundTag)obj).toString() + "\n"; + } + else if (obj instanceof org.dragonet.proxy.data.nbt.tag.CompoundTag) + { + data += ((org.dragonet.proxy.data.nbt.tag.CompoundTag)obj).toString() + "\n"; + } + else + { + for(Field f : fields) { + f.setAccessible(true); + if((f.getModifiers() & Modifier.STATIC) > 0) continue; + try { + if (isWrapperType(f.get(obj).getClass())) + data += f.getName() + " = " + f.get(obj).toString(); + else + data += f.getName() + " = " + getAllFields(f.get(obj)); + } catch (Exception e) { + data += ": " + f.getName() + " = ERROR"; + } + data += "\n"; } - data += "\n"; } return data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/DefaultSkin.java b/src/main/java/org/dragonet/proxy/utilities/DefaultSkin.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/DefaultSkin.java rename to src/main/java/org/dragonet/proxy/utilities/DefaultSkin.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/GameRule.java b/src/main/java/org/dragonet/proxy/utilities/GameRule.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/GameRule.java rename to src/main/java/org/dragonet/proxy/utilities/GameRule.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/HTTP.java b/src/main/java/org/dragonet/proxy/utilities/HTTP.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/HTTP.java rename to src/main/java/org/dragonet/proxy/utilities/HTTP.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Logger.java b/src/main/java/org/dragonet/proxy/utilities/Logger.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Logger.java rename to src/main/java/org/dragonet/proxy/utilities/Logger.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java b/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java rename to src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/MCColor.java b/src/main/java/org/dragonet/proxy/utilities/MCColor.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/MCColor.java rename to src/main/java/org/dragonet/proxy/utilities/MCColor.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/MCPESkin.java b/src/main/java/org/dragonet/proxy/utilities/MCPESkin.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/MCPESkin.java rename to src/main/java/org/dragonet/proxy/utilities/MCPESkin.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/NukkitMath.java b/src/main/java/org/dragonet/proxy/utilities/NukkitMath.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/NukkitMath.java rename to src/main/java/org/dragonet/proxy/utilities/NukkitMath.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/NukkitRandom.java b/src/main/java/org/dragonet/proxy/utilities/NukkitRandom.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/NukkitRandom.java rename to src/main/java/org/dragonet/proxy/utilities/NukkitRandom.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/NumberConversions.java b/src/main/java/org/dragonet/proxy/utilities/NumberConversions.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/NumberConversions.java rename to src/main/java/org/dragonet/proxy/utilities/NumberConversions.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/PatternChecker.java b/src/main/java/org/dragonet/proxy/utilities/PatternChecker.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/PatternChecker.java rename to src/main/java/org/dragonet/proxy/utilities/PatternChecker.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Terminal.java b/src/main/java/org/dragonet/proxy/utilities/Terminal.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Terminal.java rename to src/main/java/org/dragonet/proxy/utilities/Terminal.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/VarInt.java b/src/main/java/org/dragonet/proxy/utilities/VarInt.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/VarInt.java rename to src/main/java/org/dragonet/proxy/utilities/VarInt.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Vector3F.java b/src/main/java/org/dragonet/proxy/utilities/Vector3F.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Vector3F.java rename to src/main/java/org/dragonet/proxy/utilities/Vector3F.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Versioning.java b/src/main/java/org/dragonet/proxy/utilities/Versioning.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Versioning.java rename to src/main/java/org/dragonet/proxy/utilities/Versioning.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/Zlib.java b/src/main/java/org/dragonet/proxy/utilities/Zlib.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/Zlib.java rename to src/main/java/org/dragonet/proxy/utilities/Zlib.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/ArraySplitter.java b/src/main/java/org/dragonet/proxy/utilities/io/ArraySplitter.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/ArraySplitter.java rename to src/main/java/org/dragonet/proxy/utilities/io/ArraySplitter.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/ByteUtility.java b/src/main/java/org/dragonet/proxy/utilities/io/ByteUtility.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/ByteUtility.java rename to src/main/java/org/dragonet/proxy/utilities/io/ByteUtility.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/DataIOPair.java b/src/main/java/org/dragonet/proxy/utilities/io/DataIOPair.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/DataIOPair.java rename to src/main/java/org/dragonet/proxy/utilities/io/DataIOPair.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryReader.java b/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryReader.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryReader.java rename to src/main/java/org/dragonet/proxy/utilities/io/PEBinaryReader.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryUtils.java b/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryUtils.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryUtils.java rename to src/main/java/org/dragonet/proxy/utilities/io/PEBinaryUtils.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryWriter.java b/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryWriter.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/PEBinaryWriter.java rename to src/main/java/org/dragonet/proxy/utilities/io/PEBinaryWriter.java diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/io/SkinDownloader.java b/src/main/java/org/dragonet/proxy/utilities/io/SkinDownloader.java similarity index 100% rename from proxy/src/main/java/org/dragonet/proxy/utilities/io/SkinDownloader.java rename to src/main/java/org/dragonet/proxy/utilities/io/SkinDownloader.java diff --git a/proxy/src/main/resources/STEVE_SKIN_FULL_BINARY.bin b/src/main/resources/STEVE_SKIN_FULL_BINARY.bin similarity index 100% rename from proxy/src/main/resources/STEVE_SKIN_FULL_BINARY.bin rename to src/main/resources/STEVE_SKIN_FULL_BINARY.bin diff --git a/proxy/src/main/resources/config.yml b/src/main/resources/config.yml similarity index 100% rename from proxy/src/main/resources/config.yml rename to src/main/resources/config.yml diff --git a/proxy/src/main/resources/en_US.properties b/src/main/resources/en_US.properties similarity index 100% rename from proxy/src/main/resources/en_US.properties rename to src/main/resources/en_US.properties