From 2c9566769dc91bc1e6d5e03fa1e966dbdc6c3c70 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 7 Dec 2017 22:14:12 +0100 Subject: [PATCH 01/60] send MC|Brand & client settings (experimental) --- .../org/dragonet/proxy/network/CacheKey.java | 1 + .../dragonet/proxy/network/UpstreamSession.java | 2 ++ .../proxy/network/cache/EntityCache.java | 4 ++++ ...PCPlayerPositionRotationPacketTranslator.java | 16 ++++++++++++++++ .../proxy/utilities/LoginChainDecoder.java | 3 +++ 5 files changed, 26 insertions(+) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java b/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java index 31767f079..2e8d85748 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/CacheKey.java @@ -16,6 +16,7 @@ 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 diff --git a/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java b/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java index 444f436ef..3d02a6d0c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/UpstreamSession.java @@ -289,6 +289,8 @@ public void onLogin(LoginPacket packet) { 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) { diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java index 18b8da68f..141fe3b5a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java @@ -67,6 +67,10 @@ public CachedEntity getClientEntity() { } public CachedEntity getByRemoteEID(long eid) { + if (!mapRemoteToClient.containsKey(eid)) + { + return null; + } long proxyEid = mapRemoteToClient.get(eid); return entities.get(proxyEid); } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java index 0850e8e36..3db283caa 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java @@ -13,6 +13,11 @@ package org.dragonet.proxy.network.translator.pc; 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; +import com.github.steveice10.mc.protocol.data.game.setting.SkinPart; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket; 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; @@ -25,6 +30,8 @@ import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.network.translator.IPCPacketTranslator; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import org.dragonet.proxy.protocol.packets.*; import org.dragonet.proxy.utilities.BlockPosition; import org.dragonet.proxy.utilities.Constants; @@ -68,6 +75,15 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotatio ret.premiumWorldTemplateId = ""; session.sendPacket(ret); } + + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("DragonProxy"); + ClientPluginMessagePacket ClientPluginMessagePacket = new ClientPluginMessagePacket("MC|Brand" , out.toByteArray()); + ((PCDownstreamSession) session.getDownstream()).send(ClientPluginMessagePacket); + + LoginPacket loginpacket = (LoginPacket) session.getDataCache().remove(CacheKey.PACKET_LOGIN_PACKET); + ClientSettingsPacket ClientSettingsPacket = new ClientSettingsPacket(loginpacket.decoded.language, 8, ChatVisibility.FULL, false, new SkinPart[]{}, Hand.MAIN_HAND); + ((PCDownstreamSession) session.getDownstream()).send(ClientSettingsPacket); UpdateAttributesPacket attr = new UpdateAttributesPacket(); attr.rtid = 1L; diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java b/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java index 1012d6916..7d27fee7a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java @@ -21,6 +21,7 @@ public class LoginChainDecoder { public String username; public UUID clientUniqueId; public JsonObject clientData; + public String language; public Skin skin; // constructor @@ -57,6 +58,8 @@ public void decode() { // client data clientData = decodeToken(new String(clientDataJWT, StandardCharsets.UTF_8)); + + language = clientData.has("LanguageCode") ? clientData.get("LanguageCode").getAsString() : "en_US"; skin = new Skin( clientData.get("SkinId").getAsString(), From 9ea4626b08787a852a3b6d94de57e6d2d8f5a856 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:33:26 +0100 Subject: [PATCH 02/60] Add inventory transaction system (wip) --- .../transaction/InventoryTransaction.java | 24 ++ .../SimpleInventoryTransaction.java | 241 ++++++++++++++++++ .../action/CreativeInventoryAction.java | 23 ++ .../transaction/action/DropItemAction.java | 13 + .../transaction/action/InventoryAction.java | 44 ++++ .../transaction/action/SlotChangeAction.java | 26 ++ .../transaction/data/ReleaseItemData.java | 16 ++ .../transaction/data/TransactionData.java | 7 + .../type/transaction/data/UseItemData.java | 22 ++ .../transaction/data/UseItemOnEntityData.java | 19 ++ 10 files changed, 435 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java new file mode 100644 index 000000000..5fceb5494 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/InventoryTransaction.java @@ -0,0 +1,24 @@ +package org.dragonet.proxy.protocol.type.transaction; + +import java.util.Set; +import org.dragonet.proxy.protocol.type.transaction.action.InventoryAction; + +/** + * @author CreeperFace + */ +public interface InventoryTransaction { + + long getCreationTime(); + + Set getActions(); + + Set getInventories(); + + void addAction(InventoryAction action); + + boolean canExecute(); + + boolean execute(); + + boolean hasExecuted(); +} 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 new file mode 100644 index 000000000..3989a1370 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/SimpleInventoryTransaction.java @@ -0,0 +1,241 @@ +//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/protocol/type/transaction/action/CreativeInventoryAction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java new file mode 100644 index 000000000..5b55ef5ef --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/CreativeInventoryAction.java @@ -0,0 +1,23 @@ +package org.dragonet.proxy.protocol.type.transaction.action; + +import org.dragonet.proxy.protocol.type.Slot; + +/** + * @author CreeperFace + */ +public class CreativeInventoryAction extends InventoryAction { + /** + * Player put an item into the creative window to destroy it. + */ + public static final int TYPE_DELETE_ITEM = 0; + /** + * Player took an item from the creative window. + */ + public static final int TYPE_CREATE_ITEM = 1; + + protected int actionType; + + public CreativeInventoryAction(Slot source, Slot target, int action) { + super(source, target); + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java new file mode 100644 index 000000000..4c24205a4 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/DropItemAction.java @@ -0,0 +1,13 @@ +package org.dragonet.proxy.protocol.type.transaction.action; + +import org.dragonet.proxy.protocol.type.Slot; + +/** + * @author CreeperFace + */ +public class DropItemAction extends InventoryAction { + + public DropItemAction(Slot source, Slot target) { + super(source, target); + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java new file mode 100644 index 000000000..e6910620d --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/InventoryAction.java @@ -0,0 +1,44 @@ +package org.dragonet.proxy.protocol.type.transaction.action; + +import org.dragonet.proxy.protocol.type.Slot; + + +/** + * @author CreeperFace + */ +public abstract class InventoryAction { + + + private long creationTime; + + protected Slot sourceItem; + + protected Slot targetItem; + + public InventoryAction(Slot sourceItem, Slot targetItem) { + this.sourceItem = sourceItem; + this.targetItem = targetItem; + + this.creationTime = System.currentTimeMillis(); + } + + public long getCreationTime() { + return creationTime; + } + + /** + * Returns the item that was present before the action took place. + * + * @return Item + */ + public Slot getSourceItem() { + return sourceItem.clone(); + } + + /** + * Returns the item that the action attempted to replace the source item with. + */ + public Slot getTargetItem() { + return targetItem.clone(); + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java new file mode 100644 index 000000000..72c8f174d --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/action/SlotChangeAction.java @@ -0,0 +1,26 @@ +package org.dragonet.proxy.protocol.type.transaction.action; + +import java.util.HashSet; +import java.util.Set; +import org.dragonet.proxy.protocol.type.Slot; + +/** + * @author CreeperFace + */ +public class SlotChangeAction extends InventoryAction { + + protected int inventory; + private int inventorySlot; + + public SlotChangeAction(int inventory, int inventorySlot, Slot sourceItem, Slot targetItem) { + super(sourceItem, targetItem); + this.inventorySlot = inventorySlot; + } + + /** + * Returns the inventorySlot in the inventory which this action modified. + */ + public int getSlot() { + return inventorySlot; + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java new file mode 100644 index 000000000..2c4abe8fe --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/ReleaseItemData.java @@ -0,0 +1,16 @@ +package org.dragonet.proxy.protocol.type.transaction.data; + +import org.dragonet.proxy.protocol.type.Slot; +import org.dragonet.proxy.utilities.Vector3F; + + +/** + * @author CreeperFace + */ +public class ReleaseItemData implements TransactionData { + + public int actionType; + public int hotbarSlot; + public Slot itemInHand; + public Vector3F headRot; +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java new file mode 100644 index 000000000..330e78c8a --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/TransactionData.java @@ -0,0 +1,7 @@ +package org.dragonet.proxy.protocol.type.transaction.data; + +/** + * @author CreeperFace + */ +public interface TransactionData { +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java new file mode 100644 index 000000000..f38da2be0 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemData.java @@ -0,0 +1,22 @@ +package org.dragonet.proxy.protocol.type.transaction.data; + +import org.dragonet.proxy.protocol.type.Slot; +import org.dragonet.proxy.utilities.BlockPosition; +import org.dragonet.proxy.utilities.Vector3F; + + +/** + * @author CreeperFace + */ +public class UseItemData implements TransactionData { + + public int actionType; + public BlockPosition blockPos; + public int face; + public int hotbarSlot; + public Slot itemInHand; + public Vector3F playerPos; + //placement in block + public Vector3F clickPos; + +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java new file mode 100644 index 000000000..de4679e4b --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/transaction/data/UseItemOnEntityData.java @@ -0,0 +1,19 @@ +package org.dragonet.proxy.protocol.type.transaction.data; + +import org.dragonet.proxy.protocol.type.Slot; +import org.dragonet.proxy.protocol.type.transaction.data.TransactionData; +import org.dragonet.proxy.utilities.BlockPosition; + +/** + * @author CreeperFace + */ +public class UseItemOnEntityData implements TransactionData { + + public long entityRuntimeId; + public int actionType; + public int hotbarSlot; + public Slot itemInHand; + public BlockPosition vector1; + public BlockPosition vector2; + +} From 4bc1bb7c70bcc4d507a487eb77efa23ec618b37b Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:33:54 +0100 Subject: [PATCH 03/60] remove unused inventory transaction case --- .../proxy/protocol/type/InventoryTransactionAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java b/proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java index c0fa4f602..506ffd5d1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/type/InventoryTransactionAction.java @@ -85,7 +85,7 @@ public static InventoryTransactionAction read(InventoryTransactionPacket packet) switch (action.containerId) { case SOURCE_TYPE_CRAFTING_USE_INGREDIENT: case SOURCE_TYPE_CRAFTING_RESULT: - packet.craftingPart = true; +// packet.craftingPart = true; break; } break; From 3c210ef2d52d43a4910c03245cba3c83f88cf3fa Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:34:13 +0100 Subject: [PATCH 04/60] add packets --- .../proxy/protocol/packets/AnimatePacket.java | 47 ++++ .../packets/BlockPickRequestPacket.java | 34 +++ .../packets/LevelSoundEventPacket.java | 202 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java new file mode 100644 index 000000000..530fd8fb5 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java @@ -0,0 +1,47 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; + +public class AnimatePacket extends PEPacket { + //vars + + public static int ANIMATION_SWING_ARM = 1; + public static int ACTION_LEFT_CLICK = 2; + public static int ANIMATION_LEAVE_BED = 3; + public static int ACTION_MOUSE_HOVER = 4; + + public int action; + public long eid; + public float unknown; + + //constructor + public AnimatePacket() { + + } + + //public + public int pid() { + return ProtocolInfo.ANIMATE_PACKET; + } + + @Override + public void decodePayload() { + this.action = this.getVarInt(); + this.eid = getEntityRuntimeId(); + if ((this.action & 0x80) != 0) { + this.unknown = this.getLFloat(); + } + } + + @Override + public void encodePayload() { + this.putVarInt(this.action); + this.putEntityRuntimeId(this.eid); + if ((this.action & 0x80) != 0) { + this.putLFloat(this.unknown); + } + } + + //private +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java new file mode 100644 index 000000000..6fe986e59 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/BlockPickRequestPacket.java @@ -0,0 +1,34 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.utilities.BlockPosition; + +public class BlockPickRequestPacket extends PEPacket { + + public int x; + public int y; + public int z; + public boolean addUserData; + public int selectedSlot; + + @Override + public int pid() { + return ProtocolInfo.BLOCK_PICK_REQUEST_PACKET; + } + + @Override + public void decodePayload() { + BlockPosition v = this.getSignedBlockPosition(); + this.x = v.x; + this.y = v.y; + this.z = v.z; + this.putBoolean(this.addUserData); + this.selectedSlot = this.getByte(); + } + + @Override + public void encodePayload() { + + } +} diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java new file mode 100644 index 000000000..6342a6b10 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/LevelSoundEventPacket.java @@ -0,0 +1,202 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.utilities.Vector3F; + +public class LevelSoundEventPacket extends PEPacket { + + public static final int SOUND_ITEM_USE_ON = 0; + public static final int SOUND_HIT = 1; + public static final int SOUND_STEP = 2; + public static final int SOUND_FLY = 3; + public static final int SOUND_JUMP = 4; + public static final int SOUND_BREAK = 5; + public static final int SOUND_PLACE = 6; + public static final int SOUND_HEAVY_STEP = 7; + public static final int SOUND_GALLOP = 8; + public static final int SOUND_FALL = 9; + public static final int SOUND_AMBIENT = 10; + public static final int SOUND_AMBIENT_BABY = 11; + public static final int SOUND_AMBIENT_IN_WATER = 12; + public static final int SOUND_BREATHE = 13; + public static final int SOUND_DEATH = 14; + public static final int SOUND_DEATH_IN_WATER = 15; + public static final int SOUND_DEATH_TO_ZOMBIE = 16; + public static final int SOUND_HURT = 17; + public static final int SOUND_HURT_IN_WATER = 18; + public static final int SOUND_MAD = 19; + public static final int SOUND_BOOST = 20; + public static final int SOUND_BOW = 21; + public static final int SOUND_SQUISH_BIG = 22; + public static final int SOUND_SQUISH_SMALL = 23; + public static final int SOUND_FALL_BIG = 24; + public static final int SOUND_FALL_SMALL = 25; + public static final int SOUND_SPLASH = 26; + public static final int SOUND_FIZZ = 27; + public static final int SOUND_FLAP = 28; + public static final int SOUND_SWIM = 29; + public static final int SOUND_DRINK = 30; + public static final int SOUND_EAT = 31; + public static final int SOUND_TAKEOFF = 32; + public static final int SOUND_SHAKE = 33; + public static final int SOUND_PLOP = 34; + public static final int SOUND_LAND = 35; + public static final int SOUND_SADDLE = 36; + public static final int SOUND_ARMOR = 37; + public static final int SOUND_ADD_CHEST = 38; + public static final int SOUND_THROW = 39; + public static final int SOUND_ATTACK = 40; + public static final int SOUND_ATTACK_NODAMAGE = 41; + public static final int SOUND_WARN = 42; + public static final int SOUND_SHEAR = 43; + public static final int SOUND_MILK = 44; + public static final int SOUND_THUNDER = 45; + public static final int SOUND_EXPLODE = 46; + public static final int SOUND_FIRE = 47; + public static final int SOUND_IGNITE = 48; + public static final int SOUND_FUSE = 49; + public static final int SOUND_STARE = 50; + public static final int SOUND_SPAWN = 51; + public static final int SOUND_SHOOT = 52; + public static final int SOUND_BREAK_BLOCK = 53; + public static final int SOUND_LAUNCH = 54; + public static final int SOUND_BLAST = 55; + public static final int SOUND_LARGE_BLAST = 56; + public static final int SOUND_TWINKLE = 57; + public static final int SOUND_REMEDY = 58; + public static final int SOUND_UNFECT = 59; + public static final int SOUND_LEVELUP = 60; + public static final int SOUND_BOW_HIT = 61; + public static final int SOUND_BULLET_HIT = 62; + public static final int SOUND_EXTINGUISH_FIRE = 63; + public static final int SOUND_ITEM_FIZZ = 64; + public static final int SOUND_CHEST_OPEN = 65; + public static final int SOUND_CHEST_CLOSED = 66; + public static final int SOUND_SHULKERBOX_OPEN = 67; + public static final int SOUND_SHULKERBOX_CLOSED = 68; + public static final int SOUND_POWER_ON = 69; + public static final int SOUND_POWER_OFF = 70; + public static final int SOUND_ATTACH = 71; + public static final int SOUND_DETACH = 72; + public static final int SOUND_DENY = 73; + public static final int SOUND_TRIPOD = 74; + public static final int SOUND_POP = 75; + public static final int SOUND_DROP_SLOT = 76; + public static final int SOUND_NOTE = 77; + public static final int SOUND_THORNS = 78; + public static final int SOUND_PISTON_IN = 79; + public static final int SOUND_PISTON_OUT = 80; + public static final int SOUND_PORTAL = 81; + public static final int SOUND_WATER = 82; + public static final int SOUND_LAVA_POP = 83; + public static final int SOUND_LAVA = 84; + public static final int SOUND_BURP = 85; + public static final int SOUND_BUCKET_FILL_WATER = 86; + public static final int SOUND_BUCKET_FILL_LAVA = 87; + public static final int SOUND_BUCKET_EMPTY_WATER = 88; + public static final int SOUND_BUCKET_EMPTY_LAVA = 89; + public static final int SOUND_RECORD_13 = 90; + public static final int SOUND_RECORD_CAT = 91; + public static final int SOUND_RECORD_BLOCKS = 92; + public static final int SOUND_RECORD_CHIRP = 93; + public static final int SOUND_RECORD_FAR = 94; + public static final int SOUND_RECORD_MALL = 95; + public static final int SOUND_RECORD_MELLOHI = 96; + public static final int SOUND_RECORD_STAL = 97; + public static final int SOUND_RECORD_STRAD = 98; + public static final int SOUND_RECORD_WARD = 99; + public static final int SOUND_RECORD_11 = 100; + public static final int SOUND_RECORD_WAIT = 101; + public static final int SOUND_GUARDIAN_FLOP = 103; + public static final int SOUND_ELDERGUARDIAN_CURSE = 104; + public static final int SOUND_MOB_WARNING = 105; + public static final int SOUND_MOB_WARNING_BABY = 106; + public static final int SOUND_TELEPORT = 107; + public static final int SOUND_SHULKER_OPEN = 108; + public static final int SOUND_SHULKER_CLOSE = 109; + public static final int SOUND_HAGGLE = 110; + public static final int SOUND_HAGGLE_YES = 111; + public static final int SOUND_HAGGLE_NO = 112; + public static final int SOUND_HAGGLE_IDLE = 113; + public static final int SOUND_CHORUSGROW = 114; + public static final int SOUND_CHORUSDEATH = 115; + public static final int SOUND_GLASS = 116; + public static final int SOUND_CAST_SPELL = 117; + public static final int SOUND_PREPARE_ATTACK = 118; + public static final int SOUND_PREPARE_SUMMON = 119; + public static final int SOUND_PREPARE_WOLOLO = 120; + public static final int SOUND_FANG = 121; + public static final int SOUND_CHARGE = 122; + public static final int SOUND_CAMERA_TAKE_PICTURE = 123; + public static final int SOUND_LEASHKNOT_PLACE = 124; + public static final int SOUND_LEASHKNOT_BREAK = 125; + public static final int SOUND_GROWL = 126; + public static final int SOUND_WHINE = 127; + public static final int SOUND_PANT = 128; + public static final int SOUND_PURR = 129; + public static final int SOUND_PURREOW = 130; + public static final int SOUND_DEATH_MIN_VOLUME = 131; + public static final int SOUND_DEATH_MID_VOLUME = 132; + public static final int SOUND_IMITATE_BLAZE = 133; + public static final int SOUND_IMITATE_CAVE_SPIDER = 134; + public static final int SOUND_IMITATE_CREEPER = 135; + public static final int SOUND_IMITATE_ELDER_GUARDIAN = 136; + public static final int SOUND_IMITATE_ENDER_DRAGON = 137; + public static final int SOUND_IMITATE_ENDERMAN = 138; + public static final int SOUND_IMITATE_EVOCATION_ILLAGER = 140; + public static final int SOUND_IMITATE_GHAST = 141; + public static final int SOUND_IMITATE_HUSK = 142; + public static final int SOUND_IMITATE_ILLUSION_ILLAGER = 143; + public static final int SOUND_IMITATE_MAGMA_CUBE = 144; + public static final int SOUND_IMITATE_POLAR_BEAR = 145; + public static final int SOUND_IMITATE_SHULKER = 146; + public static final int SOUND_IMITATE_SILVERFISH = 147; + public static final int SOUND_IMITATE_SKELETON = 148; + public static final int SOUND_IMITATE_SLIME = 149; + public static final int SOUND_IMITATE_SPIDER = 150; + public static final int SOUND_IMITATE_STRAY = 151; + public static final int SOUND_IMITATE_VEX = 152; + public static final int SOUND_IMITATE_VINDICATION_ILLAGER = 153; + public static final int SOUND_IMITATE_WITCH = 154; + public static final int SOUND_IMITATE_WITHER = 155; + public static final int SOUND_IMITATE_WITHER_SKELETON = 156; + public static final int SOUND_IMITATE_WOLF = 157; + public static final int SOUND_IMITATE_ZOMBIE = 158; + public static final int SOUND_IMITATE_ZOMBIE_PIGMAN = 159; + public static final int SOUND_IMITATE_ZOMBIE_VILLAGER = 160; + public static final int SOUND_DEFAULT = 161; + public static final int SOUND_UNDEFINED = 162; + + public int sound; + public Vector3F position; + public int extraData = -1; //TODO: Check name + public int pitch = 1; //TODO: Check name + public boolean isBabyMob; + public boolean isGlobal; + + @Override + public int pid() { + return ProtocolInfo.LEVEL_SOUND_EVENT_PACKET; + } + + @Override + public void decodePayload() { + this.sound = getByte(); + this.position = getVector3F(); + this.extraData = getVarInt(); + this.pitch = getVarInt(); + this.isBabyMob = getBoolean(); + this.isGlobal = getBoolean(); + } + + @Override + public void encodePayload() { + putByte((byte) this.sound); + putVector3F(this.position); + putVarInt(this.extraData); + putVarInt(this.pitch); + putBoolean(this.isBabyMob); + putBoolean(this.isGlobal); + } +} From f0831279f5690dc992d8611d0d9b0cc918bbbaa2 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:34:41 +0100 Subject: [PATCH 05/60] add actions to interact packet --- .../org/dragonet/proxy/protocol/packets/InteractPacket.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java index 8be30f0ac..1e1e7dd59 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InteractPacket.java @@ -9,6 +9,8 @@ */ public class InteractPacket extends PEPacket { //vars + public static final byte ACTION_RIGHT_CLICK = 1; + public static final byte ACTION_LEFT_CLICK = 2; public static final byte ACTION_LEAVE_VEHICLE = 3; public static final byte ACTION_MOUSEOVER = 4; public static final byte ACTION_OPEN_INVENTORY = 6; From 3e6b00a83db128d45bf605efad26c62870e90914 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:35:18 +0100 Subject: [PATCH 06/60] fix bad name in adventure settings packet --- .../proxy/protocol/packets/AdventureSettingsPacket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java index 70995e320..3013cb75f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java @@ -16,7 +16,7 @@ public class AdventureSettingsPacket extends PEPacket { public static final int LEVEL_PERMISSION_VISITOR = 0; public static final int LEVEL_PERMISSION_MEMBER = 1; - public static final int LEVEL_ERMISSION_OPERATOR = 2; + public static final int LEVEL_PERMISSION_OPERATOR = 2; public static final int LEVEL_PERMISSION_CUSTOM = 3; /** From 8fab72d92df8861b8ea0d4e557625ba60ca4a4df Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:35:44 +0100 Subject: [PATCH 07/60] add recursivity in debug tool --- .../dragonet/proxy/utilities/DebugTools.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java b/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java index 956579af7..a5760fa2b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java @@ -2,11 +2,35 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.HashSet; +import java.util.Set; /** * Created on 2017/12/3. */ public class DebugTools { + + private static final Set> WRAPPER_TYPES = getWrapperTypes(); + + public static boolean isWrapperType(Class clazz) + { + return WRAPPER_TYPES.contains(clazz); + } + + private static Set> getWrapperTypes() + { + Set> ret = new HashSet>(); + ret.add(Boolean.class); + ret.add(Character.class); + ret.add(Byte.class); + ret.add(Short.class); + ret.add(Integer.class); + ret.add(Long.class); + ret.add(Float.class); + ret.add(Double.class); + ret.add(Void.class); + return ret; + } public static String getAllFields(Object obj) { if(obj == null) { @@ -17,7 +41,10 @@ public static String getAllFields(Object obj) { for(Field f : fields) { if((f.getModifiers() & Modifier.STATIC) > 0) continue; try { - data += ": " + f.getName() + " = " + f.get(obj).toString(); + if (isWrapperType(f.get(obj).getClass())) + data += ": " + f.getName() + " = " + f.get(obj).toString(); + else + data += ": " + getAllFields(f.get(obj)); } catch (Exception e) { data += ": " + f.getName() + " = ERROR"; } From b8f51a96a9c88cb019815498bb7e8beb359a6b55 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:36:05 +0100 Subject: [PATCH 08/60] add new packets to protocol --- .../org/dragonet/proxy/protocol/Protocol.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java index 567a301ba..1176f2b82 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java @@ -49,6 +49,9 @@ public final class Protocol { packets.put(SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket.class); packets.put(SET_PLAYER_GAME_TYPE_PACKET, SetPlayerGameTypePacket.class); packets.put(ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket.class); + packets.put(ANIMATE_PACKET, AnimatePacket.class); + packets.put(LEVEL_SOUND_EVENT_PACKET, LevelSoundEventPacket.class); + packets.put(BLOCK_PICK_REQUEST_PACKET, BlockPickRequestPacket.class); packets.put(SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket.class); packets.put(LEVEL_EVENT_PACKET, LevelEventPacket.class); packets.put(PLAY_SOUND_PACKET, PlaySoundPacket.class); @@ -113,12 +116,12 @@ public static PEPacket[] decode(byte[] data) throws Exception { // private private static PEPacket decodeSingle(byte[] buffer) { - try { - FileOutputStream fos = new FileOutputStream("raw_" + System.currentTimeMillis() + ".bin"); - fos.write(buffer); - fos.close(); - } catch (Exception e) { - } +// try { +// FileOutputStream fos = new FileOutputStream("raw_" + System.currentTimeMillis() + ".bin"); +// fos.write(buffer); +// fos.close(); +// } catch (Exception e) { +// } byte pid = (byte) new BinaryStream(buffer).getUnsignedVarInt(); if (packets.containsKey(pid)) { Class c = packets.get(pid); From 8d8207e36e37968619ccf5546694ee1bffd5e93d Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:36:20 +0100 Subject: [PATCH 09/60] update inventory transaction packet --- .../packets/InventoryTransactionPacket.java | 194 +++++++++++++----- 1 file changed, 139 insertions(+), 55 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java index bdff9a076..05c469892 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/InventoryTransactionPacket.java @@ -3,65 +3,149 @@ import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.ProtocolInfo; import org.dragonet.proxy.protocol.type.InventoryTransactionAction; +import org.dragonet.proxy.protocol.type.transaction.data.ReleaseItemData; +import org.dragonet.proxy.protocol.type.transaction.data.TransactionData; +import org.dragonet.proxy.protocol.type.transaction.data.UseItemData; +import org.dragonet.proxy.protocol.type.transaction.data.UseItemOnEntityData; /** * Created on 2017/10/21. */ -public class InventoryTransactionPacket extends PEPacket { - //vars - public static final int TYPE_NORMAL = 0; - public static final int TYPE_MISMATCH = 1; - public static final int TYPE_USE_ITEM = 2; - public static final int TYPE_USE_ITEM_ON_ENTITY = 3; - public static final int TYPE_RELEASE_ITEM = 4; - - public static final int USE_ITEM_ACTION_CLICK_BLOCK = 0; - public static final int USE_ITEM_ACTION_CLICK_AIR = 1; - public static final int USE_ITEM_ACTION_BREAK_BLOCK = 2; - - public static final int RELEASE_ITEM_ACTION_RELEASE = 0; // bow shoot - public static final int RELEASE_ITEM_ACTION_CONSUME = 1; // eat food, drink potion - - public static final int USE_ITEM_ON_ENTITY_ACTION_INTERACT = 0; - public static final int USE_ITEM_ON_ENTITY_ACTION_ATTACK = 1; - - public int type; - public boolean craftingPart; - public InventoryTransactionAction[] actions; - - //constructor - public InventoryTransactionPacket() { - - } - - //public - public int pid() { - return ProtocolInfo.INVENTORY_TRANSACTION_PACKET; - } - - public void encodePayload() { - putUnsignedVarInt(type); - if (actions != null && actions.length > 0) { - putUnsignedVarInt(actions.length); - for (InventoryTransactionAction action : actions) { - action.write(this); - } - } else { - putUnsignedVarInt(0); - } - } - public void decodePayload() { - type = (int) getUnsignedVarInt(); - int len = (int) getUnsignedVarInt(); - actions = new InventoryTransactionAction[len]; - if (len > 0) { - for (int i = 0; i < len; i++) { - actions[i] = InventoryTransactionAction.read(this); - } - } - - // TODO: more to be added LATER - } +public class InventoryTransactionPacket extends PEPacket +{ + public static final int TYPE_NORMAL = 0; + public static final int TYPE_MISMATCH = 1; + public static final int TYPE_USE_ITEM = 2; + public static final int TYPE_USE_ITEM_ON_ENTITY = 3; + public static final int TYPE_RELEASE_ITEM = 4; + + public static final int USE_ITEM_ACTION_CLICK_BLOCK = 0; + public static final int USE_ITEM_ACTION_CLICK_AIR = 1; + public static final int USE_ITEM_ACTION_BREAK_BLOCK = 2; + + public static final int RELEASE_ITEM_ACTION_RELEASE = 0; //bow shoot + public static final int RELEASE_ITEM_ACTION_CONSUME = 1; //eat food, drink potion + + public static final int USE_ITEM_ON_ENTITY_ACTION_INTERACT = 0; + public static final int USE_ITEM_ON_ENTITY_ACTION_ATTACK = 1; + + + public static final int ACTION_MAGIC_SLOT_DROP_ITEM = 0; + public static final int ACTION_MAGIC_SLOT_PICKUP_ITEM = 1; + + public static final int ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM = 0; + public static final int ACTION_MAGIC_SLOT_CREATIVE_CREATE_ITEM = 1; + + public int transactionType; + public InventoryTransactionAction[] actions; + public TransactionData transactionData; + + @Override + public int pid() { + return ProtocolInfo.INVENTORY_TRANSACTION_PACKET; + } + + @Override + public void encodePayload() { + this.reset(); + this.putUnsignedVarInt(this.transactionType); + + this.putUnsignedVarInt(this.actions.length); + for (InventoryTransactionAction action : this.actions) { + action.write(this); + } + + switch (this.transactionType) { + case TYPE_NORMAL: + case TYPE_MISMATCH: + break; + case TYPE_USE_ITEM: + UseItemData useItemData = (UseItemData) this.transactionData; + + this.putUnsignedVarInt(useItemData.actionType); + this.putBlockPosition(useItemData.blockPos); + this.putVarInt(useItemData.face); + this.putVarInt(useItemData.hotbarSlot); + this.putSlot(useItemData.itemInHand); + this.putVector3F(useItemData.playerPos); //TODO check + this.putVector3F(useItemData.clickPos); + break; + case TYPE_USE_ITEM_ON_ENTITY: + UseItemOnEntityData useItemOnEntityData = (UseItemOnEntityData) this.transactionData; + + this.putEntityRuntimeId(useItemOnEntityData.entityRuntimeId); + this.putUnsignedVarInt(useItemOnEntityData.actionType); + this.putVarInt(useItemOnEntityData.hotbarSlot); + this.putSlot(useItemOnEntityData.itemInHand); + this.putBlockPosition(useItemOnEntityData.vector1); + this.putBlockPosition(useItemOnEntityData.vector2); + break; + case TYPE_RELEASE_ITEM: + ReleaseItemData releaseItemData = (ReleaseItemData) this.transactionData; + + this.putUnsignedVarInt(releaseItemData.actionType); + this.putVarInt(releaseItemData.hotbarSlot); + this.putSlot(releaseItemData.itemInHand); + this.putVector3F(releaseItemData.headRot); + break; + default: + throw new RuntimeException("Unknown transaction type " + this.transactionType); + } + } + + @Override + public void decodePayload() { + this.transactionType = (int) this.getUnsignedVarInt(); + + this.actions = new InventoryTransactionAction[(int) this.getUnsignedVarInt()]; + for (int i = 0; i < this.actions.length; i++) { + this.actions[i] = new InventoryTransactionAction().read(this); + } + + switch (this.transactionType) { + case TYPE_NORMAL: + case TYPE_MISMATCH: + //Regular ComplexInventoryTransaction doesn't read any extra data + break; + case TYPE_USE_ITEM: + UseItemData itemData = new UseItemData(); + + itemData.actionType = (int) this.getUnsignedVarInt(); + itemData.blockPos = this.getBlockPosition(); + itemData.face = this.getVarInt(); + itemData.hotbarSlot = this.getVarInt(); + itemData.itemInHand = this.getSlot(); + itemData.playerPos = this.getVector3F(); + itemData.clickPos = this.getVector3F(); + + this.transactionData = itemData; + break; + case TYPE_USE_ITEM_ON_ENTITY: + UseItemOnEntityData useItemOnEntityData = new UseItemOnEntityData(); + + useItemOnEntityData.entityRuntimeId = this.getEntityRuntimeId(); + useItemOnEntityData.actionType = (int) this.getUnsignedVarInt(); + useItemOnEntityData.hotbarSlot = this.getVarInt(); + useItemOnEntityData.itemInHand = this.getSlot(); + useItemOnEntityData.vector1 = this.getBlockPosition(); + useItemOnEntityData.vector2 = this.getBlockPosition(); + + this.transactionData = useItemOnEntityData; + break; + case TYPE_RELEASE_ITEM: + ReleaseItemData releaseItemData = new ReleaseItemData(); + + releaseItemData.actionType = (int) getUnsignedVarInt(); + releaseItemData.hotbarSlot = getVarInt(); + releaseItemData.itemInHand = getSlot(); + releaseItemData.headRot = this.getVector3F(); + + this.transactionData = releaseItemData; + break; + default: + throw new RuntimeException("Unknown transaction type " + this.transactionType); + } + } //private From 3d68979ea537da5ee2afac8300f6359d6388db97 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:36:58 +0100 Subject: [PATCH 10/60] remove "UPSTREAMING >> bla bla" message --- .../java/org/dragonet/proxy/network/PCDownstreamSession.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java b/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java index 22641f7da..ee465662e 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java @@ -127,7 +127,7 @@ public void send(Packet... packets) { public void send(Packet packet) { if (packet == null) return; - System.out.println("UPSTREAMING >> " + packet.getClass().getSimpleName()); +// System.out.println("UPSTREAMING >> " + packet.getClass().getSimpleName()); remoteClient.getSession().send(packet); } From bbece08936e751283ddbca3be82630139fe971f9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:37:26 +0100 Subject: [PATCH 11/60] disable error in chunk translator --- .../translator/pc/PCMultiChunkDataPacketTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index abcfdbd8f..968be650a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -79,8 +79,8 @@ private void processChunkSection(Chunk[] pc, ChunkData pe) { section.blockIds[index(x, y, z)] = (byte) (entry.id & 0xFF); - section.blockMetas[index(x, y, - z)] = entry.damage.byteValue(); +// section.blockMetas[index(x, y, +// z)] = entry.damage.byteValue(); } } } From 7c930c53147d80c942e8bfa120eb4e558b7eb8ef Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:38:52 +0100 Subject: [PATCH 12/60] add sound translator (not tested) --- .../pc/PCSoundEventPacketTranslator.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java new file mode 100644 index 000000000..2444503d0 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java @@ -0,0 +1,64 @@ +/* + * 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.packet.ingame.server.world.ServerPlayBuiltinSoundPacket; +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.LevelSoundEventPacket; +import org.dragonet.proxy.utilities.Vector3F; + +public class PCSoundEventPacketTranslator implements IPCPacketTranslator { + // vars + + // constructor + public PCSoundEventPacketTranslator() { + + } + + // public + public PEPacket[] translate(UpstreamSession session, ServerPlayBuiltinSoundPacket packet) { + LevelSoundEventPacket pk = new LevelSoundEventPacket(); + pk.position = new Vector3F((float)packet.getX(), (float)packet.getY(), (float)packet.getZ()); + pk.pitch = (int)packet.getPitch(); + switch(packet.getSound()) + { + case BLOCK_GRASS_BREAK: + pk.sound = LevelSoundEventPacket.SOUND_BREAK; + break; + case BLOCK_GRASS_PLACE: + pk.sound = LevelSoundEventPacket.SOUND_PLACE; + break; + case BLOCK_GRASS_FALL: + pk.sound = LevelSoundEventPacket.SOUND_FALL_SMALL; + break; + case BLOCK_CHEST_OPEN: + pk.sound = LevelSoundEventPacket.SOUND_CHEST_OPEN; + break; + case BLOCK_CHEST_CLOSE: + pk.sound = LevelSoundEventPacket.SOUND_CHEST_CLOSED; + break; + case ENTITY_ARROW_SHOOT: + pk.sound = LevelSoundEventPacket.SOUND_BOW; + break; + } + pk.isGlobal = false; + pk.isBabyMob = false; + pk.extraData = 0; + pk.offset = 0; + return new PEPacket[]{pk}; + } + + // private +} From b456ea3066f0d0c2b3ae631392e3f968ee4c8b94 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:39:07 +0100 Subject: [PATCH 13/60] add animation translator (not tested) --- .../pc/PCAnimationPacketTranslator.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java new file mode 100644 index 000000000..b41363a57 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.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 com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket; +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.AnimatePacket; + +public class PCAnimationPacketTranslator implements IPCPacketTranslator { + // vars + + // constructor + public PCAnimationPacketTranslator() { + + } + + // public + public PEPacket[] translate(UpstreamSession session, ServerEntityAnimationPacket packet) { + + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + return null; + } + AnimatePacket pk = new AnimatePacket(); + pk.action = packet.getAnimation().ordinal(); + pk.eid = entity.proxyEid; + System.out.println(packet.getAnimation().name()); + return new PEPacket[] { pk }; + } + + // private + +} From bf81d63e7b2151d18c6fb748e6726ae662b8868a Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:39:36 +0100 Subject: [PATCH 14/60] add pick block request translator (not tested) --- .../PEBlockPickRequestPacketTranslator.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java new file mode 100644 index 000000000..d806e6e89 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEBlockPickRequestPacketTranslator.java @@ -0,0 +1,37 @@ +/* + * 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.packetlib.packet.Packet; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.BlockPickRequestPacket; +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)); + + return null; + } + + // private +} From 17acef246e9fb86c79845e90989352afb801a9c3 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:40:11 +0100 Subject: [PATCH 15/60] add sond event packet translator : client side (not tested) --- .../pe/PESoundEventPacketTranslator.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java new file mode 100644 index 000000000..c0469bf93 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PESoundEventPacketTranslator.java @@ -0,0 +1,36 @@ +/* + * 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.packetlib.packet.Packet; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.LevelSoundEventPacket; +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 +} From f132a7d35ca84cdf2e9ca4c7ec16ec0cb040dc4e Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:41:09 +0100 Subject: [PATCH 16/60] work on inventory transaction translator (not working) --- ...EInventoryTransactionPacketTranslator.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java index 048820554..423802ed1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java @@ -1,13 +1,16 @@ package org.dragonet.proxy.network.translator.pe; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.github.steveice10.packetlib.packet.Packet; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.IPEPacketTranslator; import org.dragonet.proxy.protocol.packets.InventoryTransactionPacket; +import static org.dragonet.proxy.protocol.packets.InventoryTransactionPacket.*; import org.dragonet.proxy.protocol.type.InventoryTransactionAction; +import org.dragonet.proxy.protocol.type.transaction.data.TransactionData; import org.dragonet.proxy.utilities.DebugTools; /** @@ -17,12 +20,28 @@ public class PEInventoryTransactionPacketTranslator implements IPEPacketTranslat @Override public Packet[] translate(UpstreamSession session, InventoryTransactionPacket packet) { - if(packet.type == InventoryTransactionPacket.TYPE_USE_ITEM) { - return new Packet[] { new ClientPlayerSwingArmPacket(Hand.MAIN_HAND), new ClientPlayerUseItemPacket(Hand.MAIN_HAND) }; - } + System.out.println("InventoryTransactionPacket type : " + DebugTools.getAllFields(packet)); for(InventoryTransactionAction action : packet.actions) { System.out.println(DebugTools.getAllFields(action)); } + switch(packet.transactionType) + { + case TYPE_NORMAL: + System.out.println("TYPE_NORMAL"); + break; + case TYPE_MISMATCH: + System.out.println("TYPE_MISMATCH"); + break; + case TYPE_USE_ITEM: + System.out.println("TYPE_USE_ITEM"); + return new Packet[] { new ClientPlayerSwingArmPacket(Hand.MAIN_HAND), new ClientPlayerUseItemPacket(Hand.MAIN_HAND)}; + case TYPE_USE_ITEM_ON_ENTITY: + System.out.println("TYPE_USE_ITEM_ON_ENTITY"); + break; + case TYPE_RELEASE_ITEM: + System.out.println("TYPE_RELEASE_ITEM"); + break; + } return null; } From 94beb68354baf1c9233853f8a875051802c7c36c Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:42:13 +0100 Subject: [PATCH 17/60] add getByLocalEID in entity cache --- .../org/dragonet/proxy/network/cache/EntityCache.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java index 4c633bcf6..357eed941 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java @@ -75,6 +75,14 @@ public CachedEntity getByRemoteEID(long eid) { return entities.get(proxyEid); } + public CachedEntity getByLocalEID(long eid) { + if (!mapClientToRemote.containsKey(eid)) + { + return null; + } + return entities.get(eid); + } + public CachedEntity removeByRemoteEID(long eid) { if (!mapRemoteToClient.containsKey(eid)) { From dc97f432162f14e160f640da52655496278cc279 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:42:38 +0100 Subject: [PATCH 18/60] start working on interact packet translator --- .../pe/PEInteractPacketTranslator.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java index 59c034b34..742913c99 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java @@ -17,23 +17,35 @@ import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.IPEPacketTranslator; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; +import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.protocol.packets.InteractPacket; public class PEInteractPacketTranslator implements IPEPacketTranslator { - // vars + // vars - // constructor - public PEInteractPacketTranslator() { + // constructor + public PEInteractPacketTranslator() { - } + } - // public - public Packet[] translate(UpstreamSession session, InteractPacket packet) { - ClientPlayerInteractEntityPacket pk = new ClientPlayerInteractEntityPacket( - (int) (packet.targetRtid & 0xFFFFFFFF), InteractAction.ATTACK); - return new Packet[] { pk }; - } + // public + public Packet[] translate(UpstreamSession session, InteractPacket packet) { + CachedEntity e = session.getEntityCache().getByLocalEID(packet.targetRtid); + if (e == null) { + return null; + } - // private + switch (packet.type) { + case InteractPacket.ACTION_RIGHT_CLICK: + return new Packet[]{new ClientPlayerInteractEntityPacket((int) (e.eid), InteractAction.ATTACK)}; + case InteractPacket.ACTION_LEFT_CLICK: + return new Packet[]{new ClientPlayerInteractEntityPacket((int) (e.eid), InteractAction.INTERACT)}; + } + System.out.println("InteractPacket type : " + packet.type + " on " + packet.targetRtid); + + return null; + } + + // private } From f6984756ea3fa142873d84dfc2005c81cf7af6de Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:43:41 +0100 Subject: [PATCH 19/60] add new translators --- .../dragonet/proxy/network/PacketTranslatorRegister.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java index 9da2e5459..76488071d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -61,8 +61,7 @@ public final class PacketTranslatorRegister { 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()); + PC_TO_PE_TRANSLATOR.put(ServerPlaySoundPacket.class, new PCPlaySoundPacketTranslator()); // // // Entity PC_TO_PE_TRANSLATOR.put(ServerPlayerPositionRotationPacket.class, new PCPlayerPositionRotationPacketTranslator()); @@ -79,6 +78,7 @@ public final class PacketTranslatorRegister { 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()); // // //Inventory PC_TO_PE_TRANSLATOR.put(ServerOpenWindowPacket.class, new PCOpenWindowPacketTranslator()); @@ -91,6 +91,9 @@ public final class PacketTranslatorRegister { * 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()); @@ -105,6 +108,7 @@ public final class PacketTranslatorRegister { 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 From 969de8fbdb926e6a4fd70b9f7b2704564ae9457a Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 00:58:56 +0100 Subject: [PATCH 20/60] change in intem block translator (move byte in translator) --- .../proxy/network/translator/ItemBlockTranslator.java | 2 +- .../network/translator/pc/PCBlockChangePacketTranslator.java | 4 ++-- .../translator/pc/PCMultiBlockChangePacketTranslator.java | 3 +-- .../translator/pc/PCMultiChunkDataPacketTranslator.java | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index c4228adbd..bf2628142 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -102,7 +102,7 @@ public ItemBlockTranslator() { // public // Query handler public static ItemEntry translateToPE(int pcItemBlockId, int damage) { - ItemEntry entry = new ItemEntry(pcItemBlockId, damage); + ItemEntry entry = new ItemEntry(pcItemBlockId & 0xFF, damage & 0xf); if (!PC_TO_PE_OVERRIDE.containsKey(pcItemBlockId)) { return entry; diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java index e3a5162c9..a8f6c5ad5 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCBlockChangePacketTranslator.java @@ -33,10 +33,10 @@ public PCBlockChangePacketTranslator() { 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() & 0xf); + ItemEntry entry = ItemBlockTranslator.translateToPE(packet.getRecord().getBlock().getId(), packet.getRecord().getBlock().getData()); pk.data = entry.damage; - pk.id = (byte) (entry.id & 0xFF); + 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/PCMultiBlockChangePacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java index 136f109ba..8066fb763 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiBlockChangePacketTranslator.java @@ -44,8 +44,7 @@ public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacke BlockState block = packet.getRecords()[i].getBlock(); ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); - packets[i].id = (byte) (entry.id - & 0xFF); + packets[i].id = entry.id; packets[i].flags = generalFlag; packets[i].data = entry.damage; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index 968be650a..7f47a9e0d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -77,7 +77,7 @@ private void processChunkSection(Chunk[] pc, ChunkData pe) { Section section = pe.sections[cy]; section.blockIds[index(x, y, - z)] = (byte) (entry.id & 0xFF); + z)] = entry.id.byteValue(); // section.blockMetas[index(x, y, // z)] = entry.damage.byteValue(); From bb7d0c524c0ac665fa79c6d9718316d79e9635cb Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 12:00:17 +0100 Subject: [PATCH 21/60] add clientbound edventure settings packet translator --- .../network/PacketTranslatorRegister.java | 1 + .../PEAdventureSettingsPacketTranslator.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java index 76488071d..39d00cb92 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -103,6 +103,7 @@ public final class PacketTranslatorRegister { 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()); diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java new file mode 100644 index 000000000..41c1d1d0c --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java @@ -0,0 +1,37 @@ +/* + * 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.packetlib.packet.Packet; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.AdventureSettingsPacket; +import org.dragonet.proxy.utilities.DebugTools; + +public class PEAdventureSettingsPacketTranslator implements IPEPacketTranslator { + // vars + + // constructor + public PEAdventureSettingsPacketTranslator() { + + } + + // public + public Packet[] translate(UpstreamSession session, AdventureSettingsPacket packet) { + System.out.println(DebugTools.getAllFields(packet)); + + return null; + } + + // private +} From 08b5f6974e962b297feaf4e17ffa1428ece01894 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 12:40:08 +0100 Subject: [PATCH 22/60] fix adventure settings packet, error in set flag method --- .../packets/AdventureSettingsPacket.java | 206 +++++++++--------- 1 file changed, 102 insertions(+), 104 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java index 3013cb75f..3d4d372d6 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java @@ -7,108 +7,106 @@ * Created on 2017/10/21. */ public class AdventureSettingsPacket extends PEPacket { - //vars - public static final int PERMISSION_NORMAL = 0; - public static final int PERMISSION_OPERATOR = 1; - public static final int PERMISSION_HOST = 2; - public static final int PERMISSION_AUTOMATION = 3; - public static final int PERMISSION_ADMIN = 4; - - public static final int LEVEL_PERMISSION_VISITOR = 0; - public static final int LEVEL_PERMISSION_MEMBER = 1; - public static final int LEVEL_PERMISSION_OPERATOR = 2; - public static final int LEVEL_PERMISSION_CUSTOM = 3; - - /** - * This constant is used to identify flags that should be set on the second - * field. In a sensible world, these flags would all be set on the same packet - * field, but as of MCPE 1.2, the new abilities flags have for some reason been - * assigned a separate field. - */ - public static final int BITFLAG_SECOND_SET = 1 << 16; - - public static final int WORLD_IMMUTABLE = 0x01; - public static final int NO_PVP = 0x02; - - public static final int AUTO_JUMP = 0x20; - public static final int ALLOW_FLIGHT = 0x40; - public static final int NO_CLIP = 0x80; - public static final int WORLD_BUILDER = 0x100; - public static final int FLYING = 0x200; - public static final int MUTED = 0x400; - - public static final int BUILD_AND_MINE = 0x01 | BITFLAG_SECOND_SET; - public static final int DOORS_AND_SWITCHES = 0x02 | BITFLAG_SECOND_SET; - public static final int OPEN_CONTAINERS = 0x04 | BITFLAG_SECOND_SET; - public static final int ATTACK_PLAYERS = 0x08 | BITFLAG_SECOND_SET; - public static final int ATTACK_MOBS = 0x10 | BITFLAG_SECOND_SET; - public static final int OPERATOR = 0x20 | BITFLAG_SECOND_SET; - public static final int TELEPORT = 0x80 | BITFLAG_SECOND_SET; - - public int flags; - public int commandsPermission; - public int actionPermissions; - public int playerPermission; // 0: , 1: , 2: , 3: - public int customFlags; - public long eid; - - //constructor - public AdventureSettingsPacket() { - - } - - //public - public int pid() { - return ProtocolInfo.ADVENTURE_SETTINGS_PACKET; - } - - public void encodePayload() { - putUnsignedVarInt(flags); - putUnsignedVarInt(commandsPermission); - putUnsignedVarInt(actionPermissions); - putUnsignedVarInt(playerPermission); - putUnsignedVarInt(customFlags); - putLLong(eid); - } - public void decodePayload() { - flags = (int) getUnsignedVarInt(); - commandsPermission = (int) getUnsignedVarInt(); - actionPermissions = (int) getUnsignedVarInt(); - playerPermission = (int) getUnsignedVarInt(); - customFlags = (int) getUnsignedVarInt(); - eid = getLLong(); - } - - public boolean getFlag(int flag) { - if ((flag & BITFLAG_SECOND_SET) != 0) { - return (this.actionPermissions & flag) != 0; - } - - return (this.flags & flag) != 0; - } - public void setFlag(int flag, boolean value) { - int flagSet = 0; - boolean second = false; - if ((flag & BITFLAG_SECOND_SET) != 0) { - flagSet &= this.actionPermissions; - second = true; - } else { - flagSet &= this.flags; - } - - if (value) { - flagSet |= flag; - } else { - flagSet &= ~flag; - } - - if (second) { - actionPermissions = flagSet; - } else { - flags = flagSet; - } - } - - //private - + //vars + + public static final int PERMISSION_NORMAL = 0; + public static final int PERMISSION_OPERATOR = 1; + public static final int PERMISSION_HOST = 2; + public static final int PERMISSION_AUTOMATION = 3; + public static final int PERMISSION_ADMIN = 4; + + public static final int LEVEL_PERMISSION_VISITOR = 0; + public static final int LEVEL_PERMISSION_MEMBER = 1; + public static final int LEVEL_PERMISSION_OPERATOR = 2; + public static final int LEVEL_PERMISSION_CUSTOM = 3; + + /** + * This constant is used to identify flags that should be set on the second + * field. In a sensible world, these flags would all be set on the same + * packet field, but as of MCPE 1.2, the new abilities flags have for some + * reason been assigned a separate field. + */ + public static final int BITFLAG_SECOND_SET = 1 << 16; + + //flags + public static final int WORLD_IMMUTABLE = 0x01; + public static final int NO_PVP = 0x02; + public static final int AUTO_JUMP = 0x20; + public static final int ALLOW_FLIGHT = 0x40; + public static final int NO_CLIP = 0x80; + public static final int WORLD_BUILDER = 0x100; + public static final int FLYING = 0x200; + public static final int MUTED = 0x400; + + //custom flags + public static final int BUILD_AND_MINE = 0x01 | BITFLAG_SECOND_SET; + public static final int DOORS_AND_SWITCHES = 0x02 | BITFLAG_SECOND_SET; + public static final int OPEN_CONTAINERS = 0x04 | BITFLAG_SECOND_SET; + public static final int ATTACK_PLAYERS = 0x08 | BITFLAG_SECOND_SET; + public static final int ATTACK_MOBS = 0x10 | BITFLAG_SECOND_SET; + public static final int OPERATOR = 0x20 | BITFLAG_SECOND_SET; + public static final int TELEPORT = 0x80 | BITFLAG_SECOND_SET; + + public int flags; + public int commandsPermission; + public int actionPermissions; + public int playerPermission; + public int customFlags; + public long eid; + + //constructor + public AdventureSettingsPacket() { + + } + + //public + public int pid() { + return ProtocolInfo.ADVENTURE_SETTINGS_PACKET; + } + + public void encodePayload() { + putUnsignedVarInt(flags); + putUnsignedVarInt(commandsPermission); + putUnsignedVarInt(actionPermissions); + putUnsignedVarInt(playerPermission); + putUnsignedVarInt(customFlags); + putLLong(eid); + } + + public void decodePayload() { + flags = (int) getUnsignedVarInt(); + commandsPermission = (int) getUnsignedVarInt(); + actionPermissions = (int) getUnsignedVarInt(); + playerPermission = (int) getUnsignedVarInt(); + customFlags = (int) getUnsignedVarInt(); + eid = getLLong(); + } + + public boolean getFlag(int flag) { + if ((flag & BITFLAG_SECOND_SET) != 0) { + return (this.actionPermissions & flag) != 0; + } + + return (this.flags & flag) != 0; + } + + public void setFlag(int flag, boolean value) { + boolean flags = (flag & BITFLAG_SECOND_SET) != 0; + + if (value) { + if (flags) { + this.actionPermissions |= flag; + } else { + this.flags |= flag; + } + } else { + if (flags) { + this.actionPermissions &= ~flag; + } else { + this.flags &= ~flag; + } + } + } + + //private } From f7de84737cbc58f5b39bd43a77bcc0ebeef33258 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 13 Dec 2017 12:53:08 +0100 Subject: [PATCH 23/60] fix spawn pitch yaw in offline mode, fix player permission on join --- ...layerPositionRotationPacketTranslator.java | 29 +++++++++++++------ .../packets/AdventureSettingsPacket.java | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java index c2fd13f82..54fc5c287 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java @@ -62,14 +62,16 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotatio if (!session.getProxy().getAuthMode().equalsIgnoreCase("online")) { StartGamePacket ret = new StartGamePacket(); ret.rtid = 1L; - ret.eid = 1L; // Use EID 0 for easier management - ret.dimension = 0; + ret.eid = 1L; + ret.dimension = restored.getDimension(); ret.seed = 0; ret.generator = 1; ret.gamemode = restored.getGameMode() == GameMode.CREATIVE ? 1 : 0; ret.spawnPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ()); ret.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, (float) packet.getZ()); + ret.yaw = packet.getYaw(); + ret.pitch = packet.getPitch(); ret.levelId = ""; ret.worldName = "World"; ret.commandsEnabled = true; @@ -90,15 +92,24 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotatio session.sendPacket(attr); AdventureSettingsPacket adv = new AdventureSettingsPacket(); - adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.SPECTATOR)); - // adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, true); - adv.setFlag(AdventureSettingsPacket.ATTACK_PLAYERS, true); - adv.setFlag(AdventureSettingsPacket.ATTACK_MOBS, true); - adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true); - adv.setFlag(AdventureSettingsPacket.OPERATOR, true); - adv.setFlag(AdventureSettingsPacket.TELEPORT, true); + //flags + adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.ADVENTURE)); +// adv.setFlag(AdventureSettingsPacket.NO_PVP, true); +// adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true); + adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, restored.getGameMode().equals(GameMode.CREATIVE) || restored.getGameMode().equals(GameMode.SPECTATOR)); adv.setFlag(AdventureSettingsPacket.NO_CLIP, restored.getGameMode().equals(GameMode.SPECTATOR)); + adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !restored.getGameMode().equals(GameMode.SPECTATOR) || !restored.getGameMode().equals(GameMode.ADVENTURE)); adv.setFlag(AdventureSettingsPacket.FLYING, false); + adv.setFlag(AdventureSettingsPacket.MUTED, false); + //custom permission flags (not necessary for now when using LEVEL_PERMISSION setting) +// adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true); +// adv.setFlag(AdventureSettingsPacket.DOORS_AND_SWITCHES, true); +// adv.setFlag(AdventureSettingsPacket.OPEN_CONTAINERS, true); +// adv.setFlag(AdventureSettingsPacket.ATTACK_PLAYERS, true); +// adv.setFlag(AdventureSettingsPacket.ATTACK_MOBS, true); +// adv.setFlag(AdventureSettingsPacket.OPERATOR, true); +// adv.setFlag(AdventureSettingsPacket.TELEPORT, true); + adv.eid = 1L; adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL; //TODO update this with server configiration adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER; //TODO update this with server configiration session.sendPacket(adv); diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java index 3d4d372d6..49353e1bb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AdventureSettingsPacket.java @@ -38,7 +38,7 @@ public class AdventureSettingsPacket extends PEPacket { public static final int FLYING = 0x200; public static final int MUTED = 0x400; - //custom flags + //custom flags (not necessary when using LEVEL_PERMISSION_*) public static final int BUILD_AND_MINE = 0x01 | BITFLAG_SECOND_SET; public static final int DOORS_AND_SWITCHES = 0x02 | BITFLAG_SECOND_SET; public static final int OPEN_CONTAINERS = 0x04 | BITFLAG_SECOND_SET; From 1748f679adb4a57f3c80eaa5f05ac079c1a04a9c Mon Sep 17 00:00:00 2001 From: CreeperFace Date: Wed, 13 Dec 2017 14:03:07 +0100 Subject: [PATCH 24/60] Fix block metadata --- .../org/dragonet/proxy/commands/ConsoleCommandReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java b/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java index 853e8596d..4c2366266 100644 --- a/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java +++ b/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java @@ -28,7 +28,7 @@ public ConsoleCommandReader(DragonProxy proxy) { // public public void startConsole() { - Thread thread = new Thread(new Runnable() { + /*Thread thread = new Thread(new Runnable() { public void run() { String command = ""; while (!proxy.isShuttingDown()) { @@ -51,7 +51,7 @@ public void run() { thread.setName("ConsoleCommandThread"); thread.setDaemon(true); - thread.start(); + thread.start();*/ } // private From 7e1452839d2a69b2aaa7c4f5d14707678e16dc7b Mon Sep 17 00:00:00 2001 From: CreeperFace Date: Wed, 13 Dec 2017 14:03:57 +0100 Subject: [PATCH 25/60] ops --- .../translator/pc/PCEntityEffectPacketTranslator.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 index 94c993eb1..a9f7bed06 100644 --- 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 @@ -21,6 +21,7 @@ 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 @@ -38,10 +39,16 @@ public PEPacket[] translate(UpstreamSession session, ServerEntityEffectPacket pa } 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 = PocketPotionEffect.getByID(effectId).getEffect(); + eff.effectId = effect.getEffect(); if (entity.effects.contains(effectId)) { eff.eventId = MobEffectPacket.EVENT_MODIFY; } else { From 2703e148180c14977ae166bd9e8657916cddeb96 Mon Sep 17 00:00:00 2001 From: CreeperFace Date: Wed, 13 Dec 2017 17:39:28 +0100 Subject: [PATCH 26/60] Ops (reader read console output so that was the reason..) --- .../org/dragonet/proxy/commands/ConsoleCommandReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java b/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java index 4c2366266..853e8596d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java +++ b/proxy/src/main/java/org/dragonet/proxy/commands/ConsoleCommandReader.java @@ -28,7 +28,7 @@ public ConsoleCommandReader(DragonProxy proxy) { // public public void startConsole() { - /*Thread thread = new Thread(new Runnable() { + Thread thread = new Thread(new Runnable() { public void run() { String command = ""; while (!proxy.isShuttingDown()) { @@ -51,7 +51,7 @@ public void run() { thread.setName("ConsoleCommandThread"); thread.setDaemon(true); - thread.start();*/ + thread.start(); } // private From b7496276f9ed3015db51cdd57b198472d4cca3ca Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 14 Dec 2017 12:31:11 +0000 Subject: [PATCH 27/60] Minor refactor --- README.md | 12 ++--- pom.xml | 3 +- wiki/HowTo-CLS.md | 20 -------- wiki/HowTo-Online.md | 11 ---- wiki/NetworkExamples.md | 15 ------ wiki/Packets.md | 109 ---------------------------------------- wiki/Schema-CLS.md | 37 -------------- wiki/Usage.md | 1 - wiki/Welcome.md | 49 ------------------ 9 files changed, 4 insertions(+), 253 deletions(-) delete mode 100644 wiki/HowTo-CLS.md delete mode 100644 wiki/HowTo-Online.md delete mode 100644 wiki/NetworkExamples.md delete mode 100644 wiki/Packets.md delete mode 100644 wiki/Schema-CLS.md delete mode 100644 wiki/Usage.md delete mode 100644 wiki/Welcome.md diff --git a/README.md b/README.md index fcfe25437..36a212362 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ DragonProxy =========== +A proxy for to allow **Minecraft: Bedrock** clients to connect to **Minecraft: Java Edition** servers. ## WE ARE BACK - Currently supporting 1.2.x - Chat supported -- Chunk supported +- Chunks supported - Movement supported - Inventory WIP -A proxy for **Minecraft Bedrock** connecting to **Minecraft - Java Edition** servers. - Video by **[@MrPowerGamerBR](https://github.com/MrPowerGamerBR)** (On an older version): https://www.youtube.com/watch?v=oRSKQMzZYDE ![Screenshot](https://github.com/DragonetMC/DragonProxy/raw/master/screenshots/performium-factions.jpg) -Wanna donate to help us? Go to http://dragonet.org/donate.php ## Installation [Download](https://github.com/DragonetMC/DragonProxy/releases) @@ -26,11 +24,7 @@ See the tutorial in the [wiki](https://github.com/DragonetMC/DragonProxy/wiki). #### Supported Remote Server Types - For Java Edition Servers: `Bukkit`/`Spigot`/`Glowstone`/`SpongeVanilla`/`BungeeCord` - For Bedrock Servers: `MiNET`, `Nukkit`, `PocketMine-MP (and all forks)` -- Not listed is **NOT** mean unsupported, just **untested**. - -## Community -**Website:** [http://dragonet.org](http://dragonet.org) -**Forums:** [http://forums.dragonet.org](http://forums.dragonet.org) +- Not listed does **NOT** mean unsupported, just **untested**. ## Libraries Used * JRakNet by the MarfGamer @ [Link](https://github.com/JRakNet/JRakNet) diff --git a/pom.xml b/pom.xml index 4d16a2013..ddedbd9ac 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.dragonet.proxy DragonProxy-parent - 1.0.0 + 0.2.2.1 pom DragonProxy @@ -10,7 +10,6 @@ package - proxy diff --git a/wiki/HowTo-CLS.md b/wiki/HowTo-CLS.md deleted file mode 100644 index a59981c63..000000000 --- a/wiki/HowTo-CLS.md +++ /dev/null @@ -1,20 +0,0 @@ -## How to Login vis CLS -#### 1. Register/Login to CLS system -Login or register to Dragonet CLS system at http://auth.dragonet.org . - -#### 2. Add your Minecraft account -If your account is already listed, click `Login & View`. -If your account isn't added before, click `add` and then go to **step 4**. - -#### 3. Authenticate your Minecraft account -Type in your Minecraft account info and click `Register`. -**WARNING: **Do NOT try to login to a same account too many times within one hour or Mojang will block you from loggin in via our service for 2-3 hours. - -#### 4. Get and set your special username for MCPE -Your special username will be displayed as huge blue text in the center of the page. -Follow the instructions on the page to set up your MCPE client. -**Note: **If you leaked your special username in accident, you can generate a new one on the information page. - -#### 5. Join servers -Enjoy your game without typing your password everytime. - diff --git a/wiki/HowTo-Online.md b/wiki/HowTo-Online.md deleted file mode 100644 index b3d4176a5..000000000 --- a/wiki/HowTo-Online.md +++ /dev/null @@ -1,11 +0,0 @@ -#### If you have online mode enabled in the configuration file you will be prompted to login. -## Step 1. If you connect to your proxy you should see this: -![Screenshot](https://raw.githubusercontent.com/DragonetMC/DragonProxy/master/screenshots/online-login.png) - -## Step 2. Send your e-mail address in the chat.  -## Step 3. Send your password in the chat. (Don't worry, the server won't show it) -#### WARNING: We can't guarantee that hackers aren't using an edited version of DragonProxy to capture your password, so be careful and only join trusted servers. - -## Step 4. Wait for the joining process to complete. -#### If you are notified that the login has failed, try to disconnect and retry. - diff --git a/wiki/NetworkExamples.md b/wiki/NetworkExamples.md deleted file mode 100644 index e41f090ca..000000000 --- a/wiki/NetworkExamples.md +++ /dev/null @@ -1,15 +0,0 @@ -Network Example -=============== - -## Example. Single->Multiple -`DragonProxy` <=> `PC Server 1`,`PC Server 2`,`PE Server 3`,`PE Server 4` -or -`DragonProxy` <=> `Spigot Server`,`Spigot Server`,`PocketMine Server`,`Nukkit Server`,`MiNet Server` - -## Example 2. Single->BungeeCord -`DragonProxy` <=> `BungeeCord` <=> `Spigot Server`,`Spigot Server` - -## Example 3. Multiple->Single->More -`DragonProxy 1`,`DragonProxy 2` <=> `DragonProxy Main` <=> `...` -or -`DragonProxy 1`,`DragonProxy 2` <=> `BungeeCord` <=> `...` diff --git a/wiki/Packets.md b/wiki/Packets.md deleted file mode 100644 index df4d359f8..000000000 --- a/wiki/Packets.md +++ /dev/null @@ -1,109 +0,0 @@ -## Packets translator - -Current versions : -- PC : 1.12.1 (338) -- PE : 1.2.3 (137) - -| PE Packet | ID (hex) | ID (dec) | Cached | Bound | PC Packet | ID (hex) | ID (dec) | -| --- |--- | --- | --- | --- | --- | --- | --- | -| Login | 0x01 | 1 | | | | | | -| Play Status | 0x02 | 2 | | | | | | -| Server To Client Handshake | 0x03 | 3 | | | | | | -| Client To Server Handshake | 0x04 | 4 | | | | | | -| Disconnect | 0x05 | 5 | | | | | | -| Resource Packs Info | 0x06 | 6 | | | | | | -| Resource Pack Stack | 0x07 | 7 | | | | | | -| Resource Pack Client Response | 0x08 | 8 | | | | | | -| Text | 0x09 | 9 | | both | ClientChat | 0x0F | | -| Set Time | 0x0a | 10 | | S => C | Time Update | 0x48 | | -| Start Game | 0x0b | 11 | | S => C | Join Game | 0x23 | | -| Add Player | 0x0c | 12 | | S => C | Spawn Player | 0x05 | | -| Add Entity | 0x0d | 13 | | S => C | Spawn Mob | 0x03 | | -| Remove Entity | 0x0e | 14 | | S => C | Destroy Entities | 0x32 | | -| Add Item Entity | 0x0f | 15 | | S => C | Collect Item | 0x4B | | -| Take Item Entity | 0x11 | 17 | | | | | | -| Move Entity | 0x12 | 18 | | S => C | Entity Relative Move | 0x26 | | -| Move Player | 0x13 | 19 | | S => C | ClientPlayerPositionRotation | 0x2F | | -| Rider Jump | 0x14 | 20 | | | | | | -| Update Block | 0x15 | 21 | | S => C | Block Change | 0x0B | | -| Add Painting | 0x16 | 22 | | S => C | Spawn Painting | 0x04 | | -| Explode | 0x17 | 2 | | | | | | -| Level Sound Event | 0x18 | 24 | | | | | | -| Level Event | 0x19 | 25 | | | | | | -| Block Event | 0x1a | 26 | | S => C | Block Action | 0x0A | | -| Entity Event | 0x1b | 27 | | | | | | -| Mob Effect | 0x1c | 28 | | S => C | Entity Effect | 0x4F | | -| Update Attributes | 0x1d | 29 | | | | | | -| Inventory Transaction | 0x1e | 30 | | C => S | Click Window | 0x07 | | -| Mob Equipment | 0x1f | 31 | | S => C | Entity Equipment | 0x3F | | -| Mob Armor Equipment | 0x20 | 32 | | | | | | -| Interact | 0x21 | 33 | | C => S | Use Entity | 0x0A | | -| Block Pick Request | 0x22 | 34 | | | | | | -| Entity Pick Request | 0x23 | 35 | | | | | | -| Player Action | 0x24 | 36 | | | | | | -| Entity Fall | 0x25 | 37 | | | | | | -| Hurt Armor | 0x26 | 38 | | | | | | -| Set Entity Data | 0x27 | 39 | | S => C | Entity Properties | 0x4E | | -| Set Entity Motion | 0x28 | 40 | | | | | | -| Set Entity Link | 0x29 | 41 | | S => C | Set Passengers | 0x43 | | -| Set Health | 0x2a | 42 | | S => C | Update Health | 0x41 | | -| Set Spawn Position | 0x2b | 43 | | S => C | Spawn Position | 0x46 | | -| Animate | 0x2c | 44 | | S => C | Animation | 0x06 | | -| Respawn | 0x2d | 45 | | S => C | Respawn | 0x35 | | -| Container Open | 0x2e | 46 | | S => C | Open Window | 0x13 | | -| Container Close | 0x2f | 47 | | S => C | Close Window | 0x12 | | -| Player Hotbar | 0x30 | 48 | | | | | | -| Inventory Content | 0x31 | 49 | | S => C | Window Items | 0x14 | | -| Inventory Slot | 0x32 | 50 | | S => C | Set Slot | 0x16 | | -| Container Set Data | 0x33 | 51 | | S => C | Window Property | 0x15 | | -| Crafting Data | 0x34 | 52 | | | | | | -| Crafting Event | 0x35 | 53 | | | | | | -| Gui Data Pick Item | 0x36 | 54 | | | | | | -| Adventure Settings | 0x37 | 55 | | S => C | Change Game State | 0x1E | | -| Block Entity Data | 0x38 | 56 | | S => C | Update Block Entity | 0x09 | | -| Player Input | 0x39 | 57 | | C => S | Steer Vehicle | 0x16 | | -| Full Ch Data | 0x3a | 58 | | S => C | Chunk Data | 0x20 | | -| Set Commands Enabled | 0x3b | 59 | | | | | | -| Set Difficulty | 0x3c | 60 | | S => C | Server Difficulty | 0x0D | | -| Change Dimension | 0x3d | 61 | | S => C | Respawn | 0x35 | | -| Set Player Game Type | 0x3e | 62 | | | | | | -| Player List | 0x3f | 63 | | S => C | Player List Item | 0x2E | | -| Simple Event | 0x40 | 64 | | | | | | -| Telemetry Event | 0x41 | 65 | | | | | | -| Spawn Experience Orb | 0x42 | 66 | | S => C | Spawn Experience Orb | 0x01 | | -| Clientbound Map Item Data | 0x43 | 67 | | | | | | -| Map Info Request | 0x44 | 68 | | | | | | -| Request Ch Radius | 0x45 | 69 | | | | | | -| Ch Radius Update | 0x46 | 70 | | | | | | -| Item Frame Drop Item | 0x47 | 71 | | | | | | -| Game Rules Changed | 0x48 | 72 | | | | | | -| Camera | 0x49 | 73 | | S => C | Camera | 0x39 | | -| Boss Event | 0x4a | 74 | | S => C | Boss Bar | 0x0C | | -| Show Credits | 0x4b | 75 | | | Change Game State | 0x1E | | -| Available Commands | 0x4c | 76 | | S => C | Tab-Complete | 0x0E | | -| Command Request | 0x4d | 77 | | | | | | -| Command Block Update | 0x4e | 78 | | | | | | -| Command Output | 0x4f | 79 | | | | | | -| Update Trade | 0x50 | 80 | | | | | | -| Update Equipment | 0x51 | 81 | | S => C | Entity Equipment | 0x3F | | -| Resource Pack Data Info | 0x52 | 82 | | | | | | -| Resource Pack Ch Data | 0x53 | 83 | | | | | | -| Resource Pack Ch Request | 0x54 | 84 | | | | | | -| Transfer | 0x55 | 85 | | | | | | -| Play Sound | 0x56 | 86 | | S => C | Sound Effect | 0x49 | | -| Stop Sound | 0x57 | 87 | | | | | | -| Set Title | 0x58 | 88 | | S => C | Title | 0x48 | | -| Add Behavior Tree | 0x59 | 89 | | | | | | -| Structure Block Update | 0x5a | 90 | | | | | | -| Show Store Offer | 0x5b | 91 | | | | | | -| Purchase Receipt | 0x5c | 92 | | | | | | -| Player Skin | 0x5d | 93 | | | | | | -| Sub Client Login | 0x5e | 94 | | | | | | -| Initiate Web Socket Connection | 0x5f | 95 | | | | | | -| Set Last Hurt By | 0x60 | 96 | | | | | | -| Book Edit | 0x61 | 97 | | C => S | Crafting Book Data | 0x17 | | -| Npc Request | 0x62 | 98 | | | | | | -| Modal Form Request | 0x64 | 100 | | | | | | -| Modal Form Response | 0x65 | 101 | | | | | | -| Server Settings Request | 0x66 | 102 | | | | | | -| Server Settings Response | 0x67 | 103 | | | | | | \ No newline at end of file diff --git a/wiki/Schema-CLS.md b/wiki/Schema-CLS.md deleted file mode 100644 index 655f91ec8..000000000 --- a/wiki/Schema-CLS.md +++ /dev/null @@ -1,37 +0,0 @@ -## CLS Login Schema -#### Default endpoint: `http://api.dragonet.org/cls` -Please note that queries are sent using GET method and returned with JSON data.
- -#### Definitions -Custom usernames are USER_ID and KeyCode with underscore(`_`) in the middle of it.
-As for `1234_d6a5f0`, `1234` is USER_ID and `d6a5f0` is the KeyCode.
- -### Endpoints -#### `/query_token.php` -**Query**: `/query_token.php?username=USER_ID&keycode=KeyCode`
-**Warning**: The confusing part in this query is that `username` field is the CLS USER_ID not player's IGN.
-**Result**:
-```text -{ - "status": "success", //Success or not - //Following fields only appears if success - "ign": "USERNAME", //The in-game name(username). - "client": "CLIENT_TOKEN", //Client ID - "token": "ACCESS_TOKEN", //The access token. -} -``` -**Note**: -Once you get it, you have to refresh the access token(call to `/refresh` method on MojangAPI) and get a new access token that bind to your server's IP address and upload that token back using `/update_token.php` method on CLS or the player sometimes will expirience `bad login` error.
- -#### `/update_token.php` -**Query**: `/update_token.php?username=PLAYER_IGN&oldtoken=OLD_TOKEN&newtoken=NEW_TOKEN`
-**Warning**: This time `username` field IS the actual player's IGN.
-**Result**:
-```text -{ - "status": "success", //Success or not -} -``` -**Note**: -Although it returns something but you can't do anything about it if it fails, it can be server's problem so you may wanna just leave the result alone. - diff --git a/wiki/Usage.md b/wiki/Usage.md deleted file mode 100644 index 9c558e357..000000000 --- a/wiki/Usage.md +++ /dev/null @@ -1 +0,0 @@ -. diff --git a/wiki/Welcome.md b/wiki/Welcome.md deleted file mode 100644 index 363854993..000000000 --- a/wiki/Welcome.md +++ /dev/null @@ -1,49 +0,0 @@ -## Welcome to DragonProxy wiki - -### 1. Presentation -DragonProxy is the only Minecraft: Bedrock Edition <=> Minecraft: Java Edition bridge, based on protocol translation.
-With this proxy, PE players (W10, Android / IOS) can join PC servers.
-This is probably the future of Minecraft servers, as Microsoft does not provide featured PE server publicly ! - -### 2. How it works -Here is a small description of the protocol translator :
- -- 1. [JRakNet](https://github.com/JRakNet/JRakNet)
-This is a java based Raknet protocole implementation. - -- 2. [RaknetInterface](../../../blob/master/proxy/src/main/java/org/dragonet/proxy/network/RaknetInterface.java)
-This is a light Minecraft PE server. - -- 3. [UpStreamSession](../../../blob/master/proxy/src/main/java/org/dragonet/proxy/network/UpStreamSession.java)
-This class manage the PE packets listener / sender. - -- 4. [PacketTranslator + cache](Packets.md))
-The packet translator PE <=> PC with caching for later use of the data. - -- 5. [DownStreamSession](../../../blob/master/proxy/src/main/java/org/dragonet/proxy/network/PCDownstreamSession.java)
-This class manage the PC packets listener / sender. - -- 6. [MCProtocolLib](https://github.com/Steveice10/MCProtocolLib)
-This library is used to create a Minecraft PC client for connecting to PC servers. - -### 3. Features -- [x] Connect -- [x] Load chunks -- [x] Chat / commands -- [x] Move -- [ ] Inventory -- [ ] Entities -- [ ] Damages -- [ ] Interact - -### 4. Future -- Online mode (auth gui based) -- Scoreboard - -### 5. Compile -To compile, simply run in proxy module : ```mvn package``` or Compile in IDE - -### 6. Resources -[Wiki.vg](http://wiki.vg/)
-[MiNET](https://github.com/NiclasOlofsson/MiNET/)
-[Nukkit](https://github.com/Nukkit/Nukkit) \ No newline at end of file From 9ca7bbe19dde0c8a3c722fc482c0e7b83f714141 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 14 Dec 2017 12:36:10 +0000 Subject: [PATCH 28/60] Fix incorrect version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ddedbd9ac..ab593faa7 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.dragonet.proxy DragonProxy-parent - 0.2.2.1 + 1.0.0 pom DragonProxy From 409b953aca4d372128b13623c618cc5458a3f336 Mon Sep 17 00:00:00 2001 From: Creeperface01 Date: Thu, 14 Dec 2017 18:07:33 +0100 Subject: [PATCH 29/60] Fix block metadata --- .../pc/PCMultiChunkDataPacketTranslator.java | 141 ++++++++++-------- 1 file changed, 78 insertions(+), 63 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index abcfdbd8f..572f7c653 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -26,67 +26,82 @@ 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 { - - FullChunkDataPacket pePacket = new FullChunkDataPacket(); - pePacket.x = packet.getColumn().getX(); - pePacket.z = packet.getColumn().getZ(); - - ChunkData chunk = new ChunkData(); - processChunkSection(packet.getColumn().getChunks(), chunk); - chunk.encode(); - pePacket.payload = chunk.getBuffer(); - - session.putCachePacket(pePacket); - } catch (Exception e) { - e.printStackTrace(); - } - }); - return null; - } - - // private - private void processChunkSection(Chunk[] pc, ChunkData pe) { - /* - * pe.sections = new Section[16]; for(int i = 0; i < 16; i++) { pe.sections[i] = - * new Section(); if(i < 2) Arrays.fill(pe.sections[i].blockIds, (byte)1); } - */ - pe.sections = new Section[16]; - for (int i = 0; i < 16; i++) { - pe.sections[i] = new Section(); - } - for (int y = 0; y < 256; y++) { - int cy = y >> 4; - if (pc[cy] == null || pc[cy].isEmpty()) - continue; - BlockStorage blocks = pc[cy].getBlocks(); - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - BlockState block = blocks.get(x, y & 0xF, z); - ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); - - Section section = pe.sections[cy]; - section.blockIds[index(x, y, - z)] = (byte) (entry.id & 0xFF); - - section.blockMetas[index(x, y, - z)] = entry.damage.byteValue(); - } - } - } - } - - private static int index(int x, int y, int z) { - return (x << 8) | (z << 4) | (y & 0xF); - } + // vars + + // constructor + public PCMultiChunkDataPacketTranslator() { + + } + + // public + public PEPacket[] translate(UpstreamSession session, ServerChunkDataPacket packet) { + session.getProxy().getGeneralThreadPool().execute(() -> { + try { + + FullChunkDataPacket pePacket = new FullChunkDataPacket(); + pePacket.x = packet.getColumn().getX(); + pePacket.z = packet.getColumn().getZ(); + + ChunkData chunk = new ChunkData(); + processChunkSection(packet.getColumn().getChunks(), chunk); + chunk.encode(); + pePacket.payload = chunk.getBuffer(); + + session.putCachePacket(pePacket); + } catch (Exception e) { + e.printStackTrace(); + } + }); + return null; + } + + // private + private void processChunkSection(Chunk[] pc, ChunkData pe) { + /* + * pe.sections = new Section[16]; for(int i = 0; i < 16; i++) { pe.sections[i] = + * new Section(); if(i < 2) Arrays.fill(pe.sections[i].blockIds, (byte)1); } + */ + pe.sections = new Section[16]; + for (int i = 0; i < 16; i++) { + pe.sections[i] = new Section(); + } + for (int y = 0; y < 256; y++) { + int cy = y >> 4; + + Chunk c = pc[cy]; + if (c == null || c.isEmpty()) + continue; + BlockStorage blocks = c.getBlocks(); + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + BlockState block = blocks.get(x, y & 0xF, z); + ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); + + Section section = pe.sections[cy]; + section.blockIds[index(x, y, + z)] = (byte) (entry.id & 0xFF); + + int i = dataIndex(x, y, z); + byte data = section.blockMetas[i]; + int newValue = entry.damage.byteValue(); + + if ((y & 1) == 0) { + data = (byte) ((data & 0xf0) | (newValue & 0x0f)); + } else { + data = (byte) (((newValue & 0x0f) << 4) | (data & 0x0f)); + } + + section.blockMetas[i] = data; + } + } + } + } + + private static int index(int x, int y, int z) { + return (x << 8) | (z << 4) | (y & 0xF); + } + + private static int dataIndex(int x, int y, int z) { + return (x << 7) | (z << 3) | ((y & 0xF) >> 1); + } } From 76929873883e8568115cf0256ab6abc51283ca17 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 09:57:59 +0100 Subject: [PATCH 30/60] Update protocole to 1.2.7 --- .../main/java/org/dragonet/proxy/protocol/ProtocolInfo.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java b/proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java index 41d88c08d..3124a388b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/ProtocolInfo.java @@ -10,16 +10,16 @@ public class ProtocolInfo { /** * Actual Minecraft: PE protocol version */ - public static final int CURRENT_PROTOCOL = 150; + public static final int CURRENT_PROTOCOL = 160; /** * Current Minecraft PE version reported by the server. This is usually the * earliest currently supported version. */ - public static final String MINECRAFT_VERSION = "v1.2.6"; + public static final String MINECRAFT_VERSION = "v1.2.7"; /** * Version number sent to clients in ping responses. */ - public static final String MINECRAFT_VERSION_NETWORK = "1.2.6"; + public static final String MINECRAFT_VERSION_NETWORK = "1.2.7"; public static final byte LOGIN_PACKET = (byte) 0x01; public static final byte PLAY_STATUS_PACKET = (byte) 0x02; From c3b9422f44dc77334d7e690d656025bcdfad40d5 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 21:29:29 +0100 Subject: [PATCH 31/60] Update ItemBlockTranslator : - set swap items ids - add dropper translator - rewrite simple NBT translator --- .../translator/ItemBlockTranslator.java | 480 ++++++++++-------- 1 file changed, 262 insertions(+), 218 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index bf2628142..75e778e28 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -19,226 +19,270 @@ 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 com.github.steveice10.opennbt.tag.builtin.Tag; +import org.dragonet.proxy.nbt.tag.ListTag; +import java.util.List; import org.dragonet.proxy.protocol.type.Slot; public class ItemBlockTranslator { - // vars - public static final int UNSUPPORTED_BLOCK_ID = 165; - public static final String DRAGONET_COMPOUND = "DragonetNBT"; - public static final Map PC_TO_PE_OVERRIDE = new HashMap<>(); - public static final Map PE_TO_PC_OVERRIDE = new HashMap<>(); - public static final Map NAME_OVERRIDES = new HashMap<>(); - - static { - swap(125, 157); // Double Slab <-> Activator Rail - toPEOverride(126, 158); // Slab <-> NULL - toPEOverride(157, 126); //activator rail - toPEOverride(198, 208); //end rod - toPEOverride(199, 240); //chorus plant - toPEOverride(202, 201); //purpur pillar -> purpu block - toPEOverride(208, 198); //grass path - toPEOverride(210, 188); //repeating command block - toPEOverride(211, 189); //chain command block - toPEOverride(95, 241); // Stained Glass - toPEOverride(36, 248); - toPEOverride(166, 95); //barrier -> invisible bedrock - toPEOverride(188, new ItemEntry(85, 1)); - toPEOverride(189, new ItemEntry(85, 2)); - toPEOverride(190, new ItemEntry(85, 3)); - toPEOverride(191, new ItemEntry(85, 5)); - toPEOverride(192, new ItemEntry(85, 4)); - toPEOverride(203, 202); //purpur stairs - toPEOverride(205, 248); //purpur slab -> unknown - - toPEOverride(219, new ItemEntry(218, 0)); //shulker boxes - toPEOverride(220, new ItemEntry(218,1)); - toPEOverride(221, new ItemEntry(218, 2)); - toPEOverride(222, new ItemEntry(218, 3)); - toPEOverride(223, new ItemEntry(218, 4)); - toPEOverride(224, new ItemEntry(218, 5)); - toPEOverride(225, new ItemEntry(218, 6)); - toPEOverride(226, new ItemEntry(218, 7)); - toPEOverride(227, new ItemEntry(218, 8)); - toPEOverride(228, new ItemEntry(218, 9)); - toPEOverride(229, new ItemEntry(218, 10)); - toPEOverride(230, new ItemEntry(218, 11)); - toPEOverride(231, new ItemEntry(218, 12)); - toPEOverride(232, new ItemEntry(218, 13)); - toPEOverride(233, new ItemEntry(218, 14)); - toPEOverride(234, new ItemEntry(218, 15)); - - toPEOverride(235, 220); //glazed terracota - toPEOverride(236, 221); - toPEOverride(237, 222); - toPEOverride(238, 223); - toPEOverride(239, 224); - toPEOverride(240, 225); - toPEOverride(241, 226); - toPEOverride(242, 227); - toPEOverride(243, 228); - toPEOverride(244, 229); - toPEOverride(245, 230); - toPEOverride(246, 231); - toPEOverride(247, 232); - toPEOverride(248, 233); - toPEOverride(249, 234); - toPEOverride(250, 235); - - toPEOverride(251, 236); //concrete - toPEOverride(252, 237); //concrete powder - - toPEOverride(218, 251); //observer - toPEOverride(255, 252); //structure block - - //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); - - if (!PC_TO_PE_OVERRIDE.containsKey(pcItemBlockId)) { - return entry; - } - entry = PC_TO_PE_OVERRIDE.get(pcItemBlockId); - if(entry.damage == null) { - entry.damage = damage; - } - - if (pcItemBlockId >= 255 && entry.id == UNSUPPORTED_BLOCK_ID) { - entry.id = 0; // Unsupported item becomes air - entry.damage = 0; - } - return entry; - } - - public static ItemEntry translateToPC(int peItemBlockId, int damage) { - ItemEntry entry = new ItemEntry(peItemBlockId, damage); - - if (!PE_TO_PC_OVERRIDE.containsKey(peItemBlockId)) { - return entry; - } - - entry = PE_TO_PC_OVERRIDE.get(peItemBlockId); - - return entry; - } - - @SuppressWarnings("unchecked") - public static org.dragonet.proxy.nbt.tag.CompoundTag translateNBT(int id, CompoundTag pcTag, org.dragonet.proxy.nbt.tag.CompoundTag target) { - if (pcTag != null && pcTag.contains("display")) { - CompoundTag pcDisplay = pcTag.get("display"); - org.dragonet.proxy.nbt.tag.CompoundTag peDisplay; - if(target.contains("display")) { - peDisplay = target.getCompound("display"); - } else { - peDisplay = new org.dragonet.proxy.nbt.tag.CompoundTag(); - target.put("display", peDisplay); - } - if (pcDisplay.contains("Name")) { - peDisplay.put("Name", new org.dragonet.proxy.nbt.tag.StringTag("Name", - ((StringTag)pcDisplay.get("Name")).getValue())); - } - } else { - if (NAME_OVERRIDES.containsKey(id)) { - org.dragonet.proxy.nbt.tag.CompoundTag peDisplay; - if(target.contains("display")) { - peDisplay = target.getCompound("display"); - } else { - peDisplay = new org.dragonet.proxy.nbt.tag.CompoundTag(); - target.put("display", peDisplay); - } - target.put("display", peDisplay); - peDisplay.put("Name", new org.dragonet.proxy.nbt.tag.StringTag("Name", NAME_OVERRIDES.get(id))); - } - } - return target; - } - - public static Slot translateSlotToPE(ItemStack item) { - if (item == null || item.getId() == 0) - return null; - Slot inv = new Slot(); - - ItemEntry entry = translateToPE(item.getId(), item.getData()); - inv.id = entry.id; - inv.damage = entry.damage != null ? entry.damage : item.getData(); - inv.count = (item.getAmount() & 0xff); - org.dragonet.proxy.nbt.tag.CompoundTag tag = new org.dragonet.proxy.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(); - rootTag.put(DRAGONET_COMPOUND, tag); - inv.tag = rootTag; - translateNBT(item.getId(), item.getNBT(), inv.tag); - return inv; - } - - public static ItemStack translateToPC(Slot slot) { - ItemStack item; - org.dragonet.proxy.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"), - tag.getCompound(DRAGONET_COMPOUND).getShort("data")); - } else { - ItemEntry entry = translateToPC(slot.id, slot.damage); - item = new ItemStack(entry.id, slot.count, entry.damage != null ? entry.damage : slot.damage); - } - - return item; - } - - // 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)); - } - - private static void toPEOverride(int fromPc, int toPe, String nameOverride) { - toPEOverride(fromPc, toPe); - if (nameOverride != null) { - NAME_OVERRIDES.put(fromPc, nameOverride); - } - } - - private static void toPEOverride(int fromPc, int toPe) { - toPEOverride(fromPc, new ItemEntry(toPe, null)); - } - - private static void toPEOverride(int fromPc, ItemEntry toPe) { - PC_TO_PE_OVERRIDE.put(fromPc, toPe); - } - - public static CompoundTag newTileTag(String id, int x, int y, int z) { - CompoundTag t = new CompoundTag(null); - t.put(new StringTag("id", id)); - t.put(new IntTag("x", x)); - t.put(new IntTag("y", y)); - t.put(new IntTag("z", z)); - return t; - } - - public static class ItemEntry { - - public Integer id; - public Integer damage; - - public ItemEntry(Integer id) { - this(id, null); - } - - public ItemEntry(Integer id, Integer damage) { - this.id = id; - this.damage = damage; - } - } + // vars + + public static final int UNSUPPORTED_BLOCK_ID = 248; + public static final String DRAGONET_COMPOUND = "DragonetNBT"; + public static final Map PC_TO_PE_OVERRIDE = new HashMap<>(); + public static final Map PE_TO_PC_OVERRIDE = new HashMap<>(); + public static final Map NAME_OVERRIDES = new HashMap<>(); + + static { + toPEOverride(36, 248); //unkown block + swap(125, 157); // double_wooden_slab + swap(126, 158); // wooden_slab + swap(157, 126); //activator_rail + swap(198, 208); //end_rod + swap(199, 240); //chorus_plant + swap(202, 201); //purpur_pillar -> purpur_block + swap(208, 198); //grass_path + swap(210, 188); //repeating_command_block + swap(211, 189); //chain_command_block + swap(95, 241); //stained_glass + swap(158, 125); //dropper + swap(160, 248); //stained_glass_pane + swap(166, 95); //barrier -> invisiblebedrock + swap(188, new ItemEntry(85, 1)); //spruce_fence + swap(189, new ItemEntry(85, 2)); //birch_fence + swap(190, new ItemEntry(85, 3)); //jungle_fence + swap(191, new ItemEntry(85, 5)); //dark_oak_fence + swap(192, new ItemEntry(85, 4)); //acacia_fence + swap(203, 202); //purpur_stairs + swap(205, 248); //purpur_slab -> unknown + + //shulker_box + swap(219, new ItemEntry(218, 0)); //white + swap(220, new ItemEntry(218, 1)); //orange + swap(221, new ItemEntry(218, 2)); //magenta + swap(222, new ItemEntry(218, 3)); //light blue + swap(223, new ItemEntry(218, 4)); //yellow + swap(224, new ItemEntry(218, 5)); //lime + swap(225, new ItemEntry(218, 6)); //pink + swap(226, new ItemEntry(218, 7)); //gray + swap(227, new ItemEntry(218, 8)); //light gray + swap(228, new ItemEntry(218, 9)); //cyan + swap(229, new ItemEntry(218, 10)); //purple + swap(230, new ItemEntry(218, 11)); //blue + swap(231, new ItemEntry(218, 12)); //brown + swap(232, new ItemEntry(218, 13)); //green + swap(233, new ItemEntry(218, 14)); //red + swap(234, new ItemEntry(218, 15)); //black + + //glazed terracota + swap(235, 220); //white + swap(236, 221); //orange + swap(237, 222); //magenta + swap(238, 223); //light blue + swap(239, 224); //yellow + swap(240, 225); //lime + swap(241, 226); //pink + swap(242, 227); //gray + swap(243, 228); //light gray + swap(244, 229); //cyan + swap(245, 230); //purple + swap(246, 231); //blue + swap(247, 232); //brown + swap(248, 233); //green + swap(249, 234); //red + swap(250, 235); //black + + swap(251, 236); //concrete + swap(252, 237); //concretepowder + + swap(218, 251); //observer + swap(207, 244); //beetroots + swap(255, 252); //structure_block + + //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); + + if (!PC_TO_PE_OVERRIDE.containsKey(pcItemBlockId)) { + return entry; + } + entry = PC_TO_PE_OVERRIDE.get(pcItemBlockId); + if (entry.damage == null) { + entry.damage = damage; + } + + if (pcItemBlockId >= 255 && entry.id == UNSUPPORTED_BLOCK_ID) { + entry.id = UNSUPPORTED_BLOCK_ID; // Unsupported item becomes air + entry.damage = 0; + } + return entry; + } + + public static ItemEntry translateToPC(int peItemBlockId, int damage) { + ItemEntry entry = new ItemEntry(peItemBlockId, damage); + + if (!PE_TO_PC_OVERRIDE.containsKey(peItemBlockId)) { + return entry; + } + + entry = PE_TO_PC_OVERRIDE.get(peItemBlockId); + + return entry; + } + + @SuppressWarnings("unchecked") + public static org.dragonet.proxy.nbt.tag.CompoundTag translateNBT(int id, Tag pcTag, org.dragonet.proxy.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); + } + switch(pcTag.getClass().getSimpleName()) + { + case "ByteArrayTag": + target.putByteArray(name, (byte[])pcTag.getValue()); + break; + case "ByteTag": + target.putByte(name, (byte)pcTag.getValue()); + break; + case "DoubleTag": + target.putDouble(name, (double)pcTag.getValue()); + break; + case "FloatTag": + target.putFloat(name, (float)pcTag.getValue()); + break; + case "IntArrayTag": + target.putIntArray(name, (int[])pcTag.getValue()); + break; + case "IntTag": + target.putInt(name, (int)pcTag.getValue()); + break; + case "LongTag": + target.putLong(name, (long)pcTag.getValue()); + break; + case "ShortTag": + target.putShort(name, (short)pcTag.getValue()); + break; + case "StringTag": + target.putString(name, (String)pcTag.getValue()); + break; + case "CompoundTag": + for(String subName : ((CompoundTag)pcTag).getValue().keySet()) + { + translateNBT(0, ((CompoundTag)pcTag).getValue().get(subName), target); + } + break; + case "ListTag": + ListTag listTag = new ListTag(); + for(Tag subTag : (List)pcTag.getValue()) + { + listTag.add(translateNBT(0, subTag, new org.dragonet.proxy.nbt.tag.CompoundTag())); + } + target.putList(listTag); + break; + default: + System.out.println("TAG not implemented : " + pcTag.getClass().getSimpleName()); + break; + } + } + return target; + } + + public static Slot translateSlotToPE(ItemStack item) { + if (item == null || item.getId() == 0) { + return null; + } + Slot inv = new Slot(); + + ItemEntry entry = translateToPE(item.getId(), item.getData()); + inv.id = entry.id; + inv.damage = entry.damage != null ? entry.damage : item.getData(); + inv.count = (item.getAmount() & 0xff); + org.dragonet.proxy.nbt.tag.CompoundTag tag = new org.dragonet.proxy.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(); + rootTag.put(DRAGONET_COMPOUND, tag); + inv.tag = rootTag; + translateNBT(item.getId(), item.getNBT(), inv.tag); + return inv; + } + + public static ItemStack translateToPC(Slot slot) { + ItemStack item; + org.dragonet.proxy.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"), + tag.getCompound(DRAGONET_COMPOUND).getShort("data")); + } else { + ItemEntry entry = translateToPC(slot.id, slot.damage); + item = new ItemStack(entry.id, slot.count, entry.damage != null ? entry.damage : slot.damage); + } + + return item; + } + + // 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)); + } + + private static void swap(int pcId, ItemEntry toPe) { + PC_TO_PE_OVERRIDE.put(pcId, toPe); + PE_TO_PC_OVERRIDE.put(toPe.id, new ItemEntry(pcId)); + } + + private static void toPEOverride(int fromPc, int toPe, String nameOverride) { + toPEOverride(fromPc, toPe); + if (nameOverride != null) { + NAME_OVERRIDES.put(fromPc, nameOverride); + } + } + + private static void toPEOverride(int fromPc, int toPe) { + toPEOverride(fromPc, new ItemEntry(toPe, null)); + } + + private static void toPEOverride(int fromPc, ItemEntry toPe) { + PC_TO_PE_OVERRIDE.put(fromPc, toPe); + } + + public static CompoundTag newTileTag(String id, int x, int y, int z) { + CompoundTag t = new CompoundTag(null); + t.put(new StringTag("id", id)); + t.put(new IntTag("x", x)); + t.put(new IntTag("y", y)); + t.put(new IntTag("z", z)); + return t; + } + + public static class ItemEntry { + + public Integer id; + public Integer damage; + + public ItemEntry(Integer id) { + this(id, null); + } + + public ItemEntry(Integer id, Integer damage) { + this.id = id; + this.damage = damage; + } + } } From eb6d6d0539683f6c1e7b4e543a9b49a06eaf4c0f Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 21:30:21 +0100 Subject: [PATCH 32/60] Set NBT toString() (human can read NBT) --- .../dragonet/proxy/nbt/tag/ByteArrayTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/ByteTag.java | 11 +++----- .../dragonet/proxy/nbt/tag/CompoundTag.java | 8 ++++-- .../org/dragonet/proxy/nbt/tag/DoubleTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/EndTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/FloatTag.java | 7 +++-- .../dragonet/proxy/nbt/tag/IntArrayTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/IntTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/ListTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/LongTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/ShortTag.java | 7 +++-- .../org/dragonet/proxy/nbt/tag/StringTag.java | 7 +++-- .../java/org/dragonet/proxy/nbt/tag/Tag.java | 28 ++++++++++++++++++- 13 files changed, 76 insertions(+), 41 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java index 6a13a2fe3..06187839d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java @@ -40,10 +40,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Byte_Array; } - + @Override - public String toString() { - return "ByteArrayTag " + this.getName() + " (data: 0x" + Binary.bytesToHexString(data, true) + " [" + data.length + " bytes])"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java index ece51f4be..92738f73e 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java @@ -41,14 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Byte; } - + @Override - public String toString() { - String hex = Integer.toHexString(this.data); - if (hex.length() < 2) { - hex = "0" + hex; - } - return "ByteTag " + this.getName() + " (data: 0x" + hex + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java index f676cbbd6..c753cf989 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java @@ -199,9 +199,11 @@ public Map getTags() { public boolean getBoolean(String name) { return getByte(name) != 0; } - - public String toString() { - return "CompoundTag " + this.getName() + " (" + tags.size() + " entries)"; + + @Override + public Object getValue() + { + return this.tags; } public void print(String prefix, PrintStream out) { diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java index e92dfe60d..d2f743e06 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java @@ -41,10 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Double; } - + @Override - public String toString() { - return "DoubleTag " + this.getName() + " (data: " + data + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java index 176a80a80..a8b407a10 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java @@ -23,10 +23,11 @@ void write(NBTOutputStream dos) throws IOException { public byte getId() { return TAG_End; } - + @Override - public String toString() { - return "EndTag"; + public Object getValue() + { + return null; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java index 9a414d6cb..85e0bdb7f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java @@ -41,10 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Float; } - + @Override - public String toString() { - return "FloatTag " + this.getName() + " (data: " + data + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java index 5ee840bc1..7bf96a725 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java @@ -39,10 +39,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Int_Array; } - + @Override - public String toString() { - return "IntArrayTag " + this.getName() + " [" + data.length + " bytes]"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java index e201b543b..0576c5e7c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java @@ -41,10 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Int; } - + @Override - public String toString() { - return "IntTag" + this.getName() + "(data: " + data + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java index 227ddc349..121e16197 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java @@ -51,10 +51,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_List; } - + @Override - public String toString() { - return "ListTag " + this.getName() + " [" + list.size() + " entries of type " + Tag.getTagName(type) + "]"; + public Object getValue() + { + return this.list; } public void print(String prefix, PrintStream out) { diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java index 7592f43db..0f496aa1a 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java @@ -41,10 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Long; } - + @Override - public String toString() { - return "LongTag" + this.getName() + " (data:" + data + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java index 3f21aea43..8ff776c11 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ShortTag.java @@ -41,10 +41,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_Short; } - + @Override - public String toString() { - return "" + data; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java index fe350e74f..1bc1d5591 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java @@ -32,10 +32,11 @@ void load(NBTInputStream dis) throws IOException { public byte getId() { return TAG_String; } - + @Override - public String toString() { - return "StringTag " + this.getName() + " (data: " + data + ")"; + public Object getValue() + { + return this.data; } @Override diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java index aa1f6c1cc..a5618bbe2 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/Tag.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.PrintStream; +import java.lang.reflect.Array; public abstract class Tag { public static final byte TAG_End = 0; @@ -26,7 +27,7 @@ public abstract class Tag { abstract void load(NBTInputStream dis) throws IOException; - public abstract String toString(); + public abstract Object getValue(); public abstract byte getId(); @@ -156,6 +157,31 @@ public static String getTagName(byte type) { } return "UNKNOWN"; } + + @Override + public String toString() { + String name = this.getName() != null && !this.getName().equals("") ? "(" + this.getName() + ")" : ""; + String value = ""; + if(this.getValue() != null) { + value = this.getValue().toString(); + if(this.getValue().getClass().isArray()) { + StringBuilder build = new StringBuilder(); + build.append("["); + for(int index = 0; index < Array.getLength(this.getValue()); index++) { + if(index > 0) { + build.append(", "); + } + + build.append(Array.get(this.getValue(), index)); + } + + build.append("]"); + value = build.toString(); + } + } + + return this.getClass().getSimpleName() + name + " { " + value + " }"; + } public abstract Tag copy(); From a6cddeb1371f0d149bb06c70b29b49229f36899e Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 21:32:16 +0100 Subject: [PATCH 33/60] Add block entity translation (WIP) --- .../pc/PCMultiChunkDataPacketTranslator.java | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index 572f7c653..209504a2e 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -14,8 +14,18 @@ import com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage; import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; +import com.github.steveice10.mc.protocol.data.game.chunk.Column; +import com.github.steveice10.mc.protocol.data.game.chunk.FlexibleStorage; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteOrder; +import java.util.logging.Level; +import java.util.logging.Logger; +import ninja.egg82.lib.javassist.bytecode.ByteArray; +import org.dragonet.proxy.nbt.NBTIO; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.ItemBlockTranslator; import org.dragonet.proxy.network.translator.IPCPacketTranslator; @@ -24,6 +34,7 @@ import org.dragonet.proxy.protocol.packets.FullChunkDataPacket; import org.dragonet.proxy.protocol.type.chunk.ChunkData; import org.dragonet.proxy.protocol.type.chunk.Section; +import org.dragonet.proxy.utilities.DebugTools; public class PCMultiChunkDataPacketTranslator implements IPCPacketTranslator { // vars @@ -43,7 +54,7 @@ public PEPacket[] translate(UpstreamSession session, ServerChunkDataPacket packe pePacket.z = packet.getColumn().getZ(); ChunkData chunk = new ChunkData(); - processChunkSection(packet.getColumn().getChunks(), chunk); + processChunkSection(packet.getColumn(), chunk); chunk.encode(); pePacket.payload = chunk.getBuffer(); @@ -56,7 +67,7 @@ public PEPacket[] translate(UpstreamSession session, ServerChunkDataPacket packe } // private - private void processChunkSection(Chunk[] pc, ChunkData pe) { + private void processChunkSection(Column pc, ChunkData pe) { /* * pe.sections = new Section[16]; for(int i = 0; i < 16; i++) { pe.sections[i] = * new Section(); if(i < 2) Arrays.fill(pe.sections[i].blockIds, (byte)1); } @@ -65,10 +76,11 @@ private void processChunkSection(Chunk[] pc, ChunkData pe) { for (int i = 0; i < 16; i++) { pe.sections[i] = new Section(); } + // Blocks for (int y = 0; y < 256; y++) { int cy = y >> 4; - Chunk c = pc[cy]; + Chunk c = pc.getChunks()[cy]; if (c == null || c.isEmpty()) continue; BlockStorage blocks = c.getBlocks(); @@ -78,9 +90,10 @@ private void processChunkSection(Chunk[] pc, ChunkData pe) { ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData()); Section section = pe.sections[cy]; - section.blockIds[index(x, y, - z)] = (byte) (entry.id & 0xFF); + //Block id + section.blockIds[index(x, y, z)] = (byte) (entry.id & 0xFF); + //Data value int i = dataIndex(x, y, z); byte data = section.blockMetas[i]; int newValue = entry.damage.byteValue(); @@ -95,6 +108,20 @@ private void processChunkSection(Chunk[] pc, ChunkData pe) { } } } + // Blocks entities + 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.translateNBT(0, pc.getTileEntities()[i], null); + pe.blockEntities = NBTIO.write(peTag); + } + } + catch (IOException ex) + { + Logger.getLogger(PCMultiChunkDataPacketTranslator.class.getName()).log(Level.SEVERE, null, ex); + } } private static int index(int x, int y, int z) { From c68fdbe9718be343dbbdab5cc21d865fb6d7ed33 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 21:33:39 +0100 Subject: [PATCH 34/60] Fix typo in DebugTools --- .../main/java/org/dragonet/proxy/utilities/DebugTools.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java b/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java index a5760fa2b..d677a652b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/DebugTools.java @@ -42,9 +42,9 @@ public static String getAllFields(Object obj) { if((f.getModifiers() & Modifier.STATIC) > 0) continue; try { if (isWrapperType(f.get(obj).getClass())) - data += ": " + f.getName() + " = " + f.get(obj).toString(); - else - data += ": " + getAllFields(f.get(obj)); + data += f.getName() + " = " + f.get(obj).toString(); + else + data += f.getName() + " = " + getAllFields(f.get(obj)); } catch (Exception e) { data += ": " + f.getName() + " = ERROR"; } @@ -52,5 +52,4 @@ public static String getAllFields(Object obj) { } return data; } - } From 1b10b9d185751d9c26ed088439b36eaed2182333 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Fri, 15 Dec 2017 21:38:26 +0100 Subject: [PATCH 35/60] Fix bad import after merge --- .../translator/pc/PCMultiChunkDataPacketTranslator.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index 209504a2e..d197cddeb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -15,16 +15,11 @@ import com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage; import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; import com.github.steveice10.mc.protocol.data.game.chunk.Column; -import com.github.steveice10.mc.protocol.data.game.chunk.FlexibleStorage; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.ByteOrder; import java.util.logging.Level; import java.util.logging.Logger; -import ninja.egg82.lib.javassist.bytecode.ByteArray; import org.dragonet.proxy.nbt.NBTIO; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.ItemBlockTranslator; @@ -34,7 +29,6 @@ import org.dragonet.proxy.protocol.packets.FullChunkDataPacket; import org.dragonet.proxy.protocol.type.chunk.ChunkData; import org.dragonet.proxy.protocol.type.chunk.Section; -import org.dragonet.proxy.utilities.DebugTools; public class PCMultiChunkDataPacketTranslator implements IPCPacketTranslator { // vars From 302911c12942868fa43f30de0ee91ab6625d3aa3 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 15:59:25 +0100 Subject: [PATCH 36/60] Add BlockEntities translate methode (WIP) --- .../network/translator/pc/PCMultiChunkDataPacketTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java index d197cddeb..d7189ee73 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCMultiChunkDataPacketTranslator.java @@ -108,7 +108,7 @@ private void processChunkSection(Column pc, ChunkData pe) { pe.blockEntities = new byte[pc.getTileEntities().length]; for (int i = 0; i < pc.getTileEntities().length; i++) { - org.dragonet.proxy.nbt.tag.CompoundTag peTag = ItemBlockTranslator.translateNBT(0, pc.getTileEntities()[i], null); + org.dragonet.proxy.nbt.tag.CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(pc.getTileEntities()[i]); pe.blockEntities = NBTIO.write(peTag); } } From 1103d3e85a6fe8d9ad419289dbdd3fcc360de7dd Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 16:09:48 +0100 Subject: [PATCH 37/60] Add BlockEntities translate methode (WIP) --- .../translator/ItemBlockTranslator.java | 131 +++++++++++++++--- 1 file changed, 109 insertions(+), 22 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index 75e778e28..99f27d4d2 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -20,8 +20,8 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import org.dragonet.proxy.nbt.tag.ListTag; import java.util.List; +import org.dragonet.proxy.nbt.tag.ListTag; import org.dragonet.proxy.protocol.type.Slot; @@ -140,8 +140,30 @@ public static ItemEntry translateToPC(int peItemBlockId, int damage) { return entry; } + public static Slot translateSlotToPE(ItemStack item) { + if (item == null || item.getId() == 0) { + return null; + } + Slot slot = new Slot(); + + ItemEntry entry = translateToPE(item.getId(), item.getData()); + 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(); + 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(); + rootTag.put(DRAGONET_COMPOUND, tag); + slot.tag = rootTag; + translateRawNBT(item.getId(), item.getNBT(), slot.tag); + return slot; + } + @SuppressWarnings("unchecked") - public static org.dragonet.proxy.nbt.tag.CompoundTag translateNBT(int id, Tag pcTag, org.dragonet.proxy.nbt.tag.CompoundTag target) { + public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag pcTag, org.dragonet.proxy.nbt.tag.CompoundTag target) + { if (pcTag != null) { String name = pcTag.getName() != null ? pcTag.getName() : ""; @@ -181,14 +203,14 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateNBT(int id, Tag pc case "CompoundTag": for(String subName : ((CompoundTag)pcTag).getValue().keySet()) { - translateNBT(0, ((CompoundTag)pcTag).getValue().get(subName), target); + translateRawNBT(0, ((CompoundTag)pcTag).getValue().get(subName), target); } break; case "ListTag": ListTag listTag = new ListTag(); for(Tag subTag : (List)pcTag.getValue()) { - listTag.add(translateNBT(0, subTag, new org.dragonet.proxy.nbt.tag.CompoundTag())); + listTag.add(translateRawNBT(0, subTag, new org.dragonet.proxy.nbt.tag.CompoundTag())); } target.putList(listTag); break; @@ -199,26 +221,91 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateNBT(int id, Tag pc } return target; } - - public static Slot translateSlotToPE(ItemStack item) { - if (item == null || item.getId() == 0) { + + //WIP + public static org.dragonet.proxy.nbt.tag.CompoundTag translateBlockEntityToPE(com.github.steveice10.opennbt.tag.builtin.CompoundTag input) { + if (input == null) { return null; } - Slot inv = new Slot(); - - ItemEntry entry = translateToPE(item.getId(), item.getData()); - inv.id = entry.id; - inv.damage = entry.damage != null ? entry.damage : item.getData(); - inv.count = (item.getAmount() & 0xff); - org.dragonet.proxy.nbt.tag.CompoundTag tag = new org.dragonet.proxy.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(); - rootTag.put(DRAGONET_COMPOUND, tag); - inv.tag = rootTag; - translateNBT(item.getId(), item.getNBT(), inv.tag); - return inv; + org.dragonet.proxy.nbt.tag.CompoundTag output = translateRawNBT(0, input, null); + if (output.contains("id")) + { + switch(output.getString("id")) + { + case "minecraft:bed": + output.putString("id", "Bed"); + output.putByte("color", output.getInt("color")); //TODO check colors + break; + case "minecraft:chest": + output.putString("id", "Chest"); + break; + case "minecraft:ender_chest": + output.putString("id", "EnderChest"); + break; + case "minecraft:command_block": + output.putString("id", "CommandBlock"); + break; + case "minecraft:sign": + output.putString("id", "Sign"); + break; + case "minecraft:flower_pot": + output.putString("id", "FlowerPot"); + break; + case "minecraft:hopper": + output.putString("id", "Hopper"); + break; + case "minecraft:dropper": + output.putString("id", "Dropper"); + break; + case "minecraft:dispenser": + output.putString("id", "Dispenser"); + break; + case "minecraft:daylight_detector": + output.putString("id", "DaylightDetector"); + break; + case "minecraft:shulker_box": + output.putString("id", "ShulkerBox"); + break; + case "minecraft:furnace": + output.putString("id", "Furnace"); + break; + case "minecraft:structure_block": + output.putString("id", "StructureBlock"); + break; + case "minecraft:end_gateway": + output.putString("id", "EndGateway"); + break; + case "minecraft:beacon": + output.putString("id", "Beacon"); + break; + case "minecraft:end_portal": + output.putString("id", "EndPortal"); + break; + case "minecraft:mob_spawner": + output.putString("id", "MobSpawner"); + break; + case "minecraft:skull": + output.putString("id", "Skull"); + break; + case "minecraft:banner": + output.putString("id", "Banner"); + break; + case "minecraft:comparator": + output.putString("id", "Comparator"); + break; + case "minecraft:item_frame": + output.putString("id", "ItemFrame"); + break; + case "minecraft:jukebox": + output.putString("id", "Jukebox"); + break; + case "minecraft:piston": + output.putString("id", "PistonArm"); + break; + } + } + output.putBoolean("isMovable", false); + return output; } public static ItemStack translateToPC(Slot slot) { From be6ca01ea619529579238e05fd7fb72b8edb1b63 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 16 Dec 2017 15:40:55 +0000 Subject: [PATCH 38/60] Fix brace style --- .../src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java | 3 +-- .../src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java | 3 +-- .../src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java | 3 +-- proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java | 3 +-- 11 files changed, 11 insertions(+), 22 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java index 06187839d..634cdd452 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteArrayTag.java @@ -42,8 +42,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java index 92738f73e..b58aa3198 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ByteTag.java @@ -43,8 +43,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java index c753cf989..350fe764f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/CompoundTag.java @@ -201,8 +201,7 @@ public boolean getBoolean(String name) { } @Override - public Object getValue() - { + public Object getValue() { return this.tags; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java index d2f743e06..5a225b4ab 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/DoubleTag.java @@ -43,8 +43,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java index a8b407a10..389eebc1f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/EndTag.java @@ -25,8 +25,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return null; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java index 85e0bdb7f..62cdbe89d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/FloatTag.java @@ -43,8 +43,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java index 7bf96a725..b7923d94c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntArrayTag.java @@ -41,8 +41,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java index 0576c5e7c..d55766a49 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/IntTag.java @@ -43,8 +43,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java index 121e16197..30fc1cd47 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/ListTag.java @@ -53,8 +53,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.list; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java index 0f496aa1a..e217d8000 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/LongTag.java @@ -43,8 +43,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } diff --git a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java index 1bc1d5591..e15526ab2 100644 --- a/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java +++ b/proxy/src/main/java/org/dragonet/proxy/nbt/tag/StringTag.java @@ -34,8 +34,7 @@ public byte getId() { } @Override - public Object getValue() - { + public Object getValue() { return this.data; } From deda745881e55ed8a0a846ace0c1dc84d5985d62 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 16:21:48 +0100 Subject: [PATCH 39/60] Add player hotbar packet --- .../org/dragonet/proxy/protocol/Protocol.java | 1 + .../protocol/packets/PlayerHotbarPacket.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java index 1176f2b82..4593d49e1 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java @@ -67,6 +67,7 @@ public final class Protocol { packets.put(MOB_EQUIPMENT_PACKET, MobEquipmentPacket.class); packets.put(SET_ENTITY_DATA_PACKET, SetEntityDataPacket.class); packets.put(PLAYER_SKIN_PACKET, PlayerSkinPacket.class); + packets.put(PLAYER_HOTBAR_PACKET, PlayerHotbarPacket.class); packets.put(CONTAINER_OPEN_PACKET, ContainerOpenPacket.class); packets.put(CONTAINER_CLOSE_PACKET, ContainerClosePacket.class); diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java new file mode 100644 index 000000000..081cc77bc --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/PlayerHotbarPacket.java @@ -0,0 +1,47 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.utilities.Binary; + + +public class PlayerHotbarPacket extends PEPacket { + + public int selectedHotbarSlot; + public int windowId = -1; + + public int[] slots; + + public boolean selectHotbarSlot = true; + + @Override + public int pid() { + return ProtocolInfo.PLAYER_HOTBAR_PACKET; + } + + @Override + public void decodePayload() { + this.selectedHotbarSlot = (int) this.getUnsignedVarInt(); + this.windowId = this.getByte(); + int count = (int) this.getUnsignedVarInt(); + slots = new int[count]; + + for (int i = 0; i < count; ++i) { + this.slots[i] = Binary.signInt((int) this.getUnsignedVarInt()); + } + this.selectHotbarSlot = this.getBoolean(); + } + + @Override + public void encodePayload() { + this.reset(); + this.putUnsignedVarInt(this.selectedHotbarSlot); + this.putByte((byte) this.windowId); + this.putUnsignedVarInt(this.slots.length); + for (int i : slots) { + this.putUnsignedVarInt(i); + } + + this.putBoolean(this.selectHotbarSlot); + } +} From 428f681ee689f4e549761364fa972189e54c010e Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 17:06:17 +0100 Subject: [PATCH 40/60] Add BlocFace traslation --- .../proxy/network/translator/ItemBlockTranslator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index 99f27d4d2..af9d91497 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -16,6 +16,7 @@ import java.util.Map; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; @@ -322,6 +323,11 @@ public static ItemStack translateToPC(Slot slot) { return item; } + + public static BlockFace translateToPC(int face) + { + return BlockFace.values()[Math.abs(face % 6)]; + } // private private static void swap(int pcId, int peId) { From 79ef192ae567a052cff4be5738639823d5d9b80d Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 19:08:37 +0100 Subject: [PATCH 41/60] remove buggy debug --- .../translator/pe/PEPlayerEquipmentPacketTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java index 72583e547..87911602c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerEquipmentPacketTranslator.java @@ -34,7 +34,7 @@ public PEPlayerEquipmentPacketTranslator() { // public public Packet[] translate(UpstreamSession session, MobEquipmentPacket packet) { - System.out.println(org.dragonet.proxy.utilities.DebugTools.getAllFields(packet)); +// System.out.println(org.dragonet.proxy.utilities.DebugTools.getAllFields(packet)); if (packet.hotbarSlot > 8) { return null; } From 00245b405fc7a613458ac71bf8a4f48cbeca9118 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 19:09:29 +0100 Subject: [PATCH 42/60] add equals() method to BlockPosition --- .../proxy/utilities/BlockPosition.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java b/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java index 85dbf6546..e02315b46 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java @@ -4,24 +4,29 @@ * Created on 2017/10/21. */ public class BlockPosition { - // vars - public int x; - public int y; - public int z; - // constructor - public BlockPosition() { + public int x; + public int y; + public int z; - } + public BlockPosition() { - public BlockPosition(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } + } - // public + public BlockPosition(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } - // private + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BlockPosition)) { + return false; + } + BlockPosition other = (BlockPosition) obj; + + return this.x == other.x && this.y == other.y && this.z == other.z; + } } From 95d91a751b5a630e95b14d2742066a52705183fc Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 19:10:41 +0100 Subject: [PATCH 43/60] Implements block place / break / drop (tested only in creative) --- ...EInventoryTransactionPacketTranslator.java | 122 +++++++++++++++--- 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java index 423802ed1..8f7a5f696 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInventoryTransactionPacketTranslator.java @@ -1,17 +1,38 @@ package org.dragonet.proxy.network.translator.pe; +import com.github.steveice10.mc.protocol.data.MagicValues; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; +import com.github.steveice10.mc.protocol.data.game.window.DropItemParam; +import com.github.steveice10.mc.protocol.data.game.window.WindowAction; +import com.github.steveice10.mc.protocol.data.game.window.WindowActionParam; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket; import com.github.steveice10.packetlib.packet.Packet; +import java.util.ArrayList; +import java.util.List; +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.IPEPacketTranslator; +import org.dragonet.proxy.network.translator.ItemBlockTranslator; import org.dragonet.proxy.protocol.packets.InventoryTransactionPacket; import static org.dragonet.proxy.protocol.packets.InventoryTransactionPacket.*; import org.dragonet.proxy.protocol.type.InventoryTransactionAction; +import org.dragonet.proxy.protocol.type.Slot; +import org.dragonet.proxy.protocol.type.transaction.data.ReleaseItemData; import org.dragonet.proxy.protocol.type.transaction.data.TransactionData; +import org.dragonet.proxy.protocol.type.transaction.data.UseItemData; +import org.dragonet.proxy.protocol.type.transaction.data.UseItemOnEntityData; +import org.dragonet.proxy.utilities.BlockPosition; import org.dragonet.proxy.utilities.DebugTools; +import org.dragonet.proxy.utilities.NukkitMath; /** * Created on 2017/12/3. @@ -20,27 +41,98 @@ public class PEInventoryTransactionPacketTranslator implements IPEPacketTranslat @Override public Packet[] translate(UpstreamSession session, InventoryTransactionPacket packet) { - System.out.println("InventoryTransactionPacket type : " + DebugTools.getAllFields(packet)); - for(InventoryTransactionAction action : packet.actions) { - System.out.println(DebugTools.getAllFields(action)); - } - switch(packet.transactionType) - { - case TYPE_NORMAL: + //debug +// System.out.println("InventoryTransactionPacket type : " + DebugTools.getAllFields(packet)); +// for(InventoryTransactionAction action : packet.actions) { +// System.out.println(DebugTools.getAllFields(action)); +// } + + switch (packet.transactionType) { + case TYPE_NORMAL: //0 System.out.println("TYPE_NORMAL"); - break; - case TYPE_MISMATCH: + List packets = new ArrayList(); + + for (InventoryTransactionAction action : packet.actions) { + if (action.sourceType == InventoryTransactionAction.SOURCE_WORLD) //main inventory + { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, + new Position(0, 0, 0), + BlockFace.DOWN); + packets.add(act); + } + } + return packets.toArray(new Packet[]{}); + case TYPE_MISMATCH: //1 System.out.println("TYPE_MISMATCH"); break; - case TYPE_USE_ITEM: + case TYPE_USE_ITEM: //2 System.out.println("TYPE_USE_ITEM"); - return new Packet[] { new ClientPlayerSwingArmPacket(Hand.MAIN_HAND), new ClientPlayerUseItemPacket(Hand.MAIN_HAND)}; - case TYPE_USE_ITEM_ON_ENTITY: + UseItemData useItemData = (UseItemData) packet.transactionData; + if (useItemData.blockPos.equals(new BlockPosition(0, 0, 0))) { + return null; + } + switch (useItemData.actionType) { + case InventoryTransactionPacket.USE_ITEM_ACTION_BREAK_BLOCK: //2 + { + ClientPlayerActionPacket act = new ClientPlayerActionPacket( + com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, + new Position(useItemData.blockPos.x, useItemData.blockPos.y, useItemData.blockPos.z), + MagicValues.key(BlockFace.class, useItemData.face)); + session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition()); + return new Packet[]{act}; + } + case InventoryTransactionPacket.USE_ITEM_ACTION_CLICK_BLOCK: //0 + case InventoryTransactionPacket.USE_ITEM_ACTION_CLICK_AIR: //1 + { + ClientPlayerPlaceBlockPacket placePacket = new ClientPlayerPlaceBlockPacket( + new Position(useItemData.blockPos.x, useItemData.blockPos.y, useItemData.blockPos.z), + ItemBlockTranslator.translateToPC(useItemData.face), + Hand.MAIN_HAND, + useItemData.clickPos.x, + useItemData.clickPos.y, + useItemData.clickPos.z + ); + return new Packet[]{placePacket, new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)}; + } + + } + case TYPE_USE_ITEM_ON_ENTITY: //3 System.out.println("TYPE_USE_ITEM_ON_ENTITY"); - break; - case TYPE_RELEASE_ITEM: + UseItemOnEntityData useItemOnEntityData = (UseItemOnEntityData) packet.transactionData; + CachedEntity cachedEntity = session.getEntityCache().getByLocalEID(useItemOnEntityData.entityRuntimeId); + if (cachedEntity == null) { + return null; + } + InteractAction interractAction = InteractAction.INTERACT; + if (useItemOnEntityData.actionType == InventoryTransactionPacket.USE_ITEM_ON_ENTITY_ACTION_ATTACK) { + interractAction = InteractAction.ATTACK; + } + ClientPlayerInteractEntityPacket interractPacket = new ClientPlayerInteractEntityPacket( + (int) cachedEntity.eid, + interractAction + ); + return new Packet[]{interractPacket}; + case TYPE_RELEASE_ITEM: //4 System.out.println("TYPE_RELEASE_ITEM"); - break; + ReleaseItemData releaseItemData = (ReleaseItemData) packet.transactionData; +// ClientPlayerActionPacket act = new ClientPlayerActionPacket( +// com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, +// new Position( +// (int)session.getEntityCache().getClientEntity().x, +// (int)session.getEntityCache().getClientEntity().y, +// (int)session.getEntityCache().getClientEntity().z +// ), +// BlockFace.UP); +// ClientWindowActionPacket windowPacket = new ClientWindowActionPacket( +// 0, +// 0, //transaction id +// releaseItemData.hotbarSlot, +// ItemBlockTranslator.translateToPC(releaseItemData.itemInHand), +// WindowAction.DROP_ITEM, +// (WindowActionParam)DropItemParam.DROP_FROM_SELECTED +// ); +// return new Packet[] {act, windowPacket}; } return null; } From 9f60e601ca810498f94f9055530780dadc8d1be6 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sat, 16 Dec 2017 23:13:56 +0100 Subject: [PATCH 44/60] add encoding datas to pom --- proxy/pom.xml | 290 +++++++++++++++++++++++++------------------------- 1 file changed, 147 insertions(+), 143 deletions(-) diff --git a/proxy/pom.xml b/proxy/pom.xml index 05b518bbb..312df8678 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -1,149 +1,153 @@ - 4.0.0 - proxy - 0.2.2.1 - proxy + 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 - - - - - - - - + + 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 - + + 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 - - + + + 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 - - + + + 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 + From a5a04deae8aab71296ba2d24cfb59ba137507958 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 12:37:28 +0100 Subject: [PATCH 45/60] add Position to BlockPosition --- .../java/org/dragonet/proxy/utilities/BlockPosition.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java b/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java index e02315b46..0da4fa36b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/BlockPosition.java @@ -1,5 +1,7 @@ package org.dragonet.proxy.utilities; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; + /** * Created on 2017/10/21. */ @@ -18,6 +20,13 @@ public BlockPosition(int x, int y, int z) { this.y = y; this.z = z; } + + public BlockPosition(Position pos) + { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + } @Override public boolean equals(Object obj) { From ef4b6f6afa5070d8245c5ab794391cc77352703c Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 12:45:55 +0100 Subject: [PATCH 46/60] TranslatedChatCompenent WIP --- .../translator/pc/PCChatPacketTranslator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java index 1e2adf388..8aa16a04d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCChatPacketTranslator.java @@ -12,6 +12,7 @@ */ package org.dragonet.proxy.network.translator.pc; +import com.github.steveice10.mc.protocol.data.message.TranslationMessage; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.MessageTranslator; @@ -38,8 +39,16 @@ public PCChatPacketTranslator() { // public public PEPacket[] translate(UpstreamSession session, ServerChatPacket packet) { TextPacket pe = new TextPacket(); - pe.type = TYPE_RAW; - pe.message = MessageTranslator.translate(packet.getMessage()); + 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 }; From 8a21ca7d2ab99a7acf5113555c08ea4ed20a81e1 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 12:49:26 +0100 Subject: [PATCH 47/60] add non Item entity Objects in cache --- .../proxy/network/cache/EntityCache.java | 318 ++++++++++-------- 1 file changed, 169 insertions(+), 149 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java index 357eed941..f48324721 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/cache/EntityCache.java @@ -16,164 +16,184 @@ import java.util.concurrent.atomic.AtomicLong; 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.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; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import org.dragonet.proxy.network.translator.EntityMetaTranslator; public final class EntityCache { - // vars - private final UpstreamSession upstream; - // proxy eid -> entity - private final Map entities = Collections - .synchronizedMap(new HashMap<>()); - // pro - private final Set playerEntities = Collections.synchronizedSet(new HashSet()); - - // 1 is for client - private final AtomicLong nextClientEntityId = new AtomicLong(2L); - private final Map mapRemoteToClient = Collections.synchronizedMap(new HashMap<>()); - private final Map mapClientToRemote= Collections.synchronizedMap(new HashMap<>()); - - // constructor - public EntityCache(UpstreamSession upstream) { - this.upstream = upstream; - reset(false); - } - - // public - public UpstreamSession getUpstream() { - return upstream; - } - - public Map getEntities() { - return entities; - } - - public void reset(boolean clear) { - if (clear) { - entities.clear(); - mapRemoteToClient.clear(); - mapClientToRemote.clear(); - } - CachedEntity clientEntity = new CachedEntity(1L, 1L, -1, null, null, true, null); - entities.put(1L, clientEntity); - } - - public CachedEntity getClientEntity() { - return entities.get(1L); - } - - public CachedEntity getByRemoteEID(long eid) { - if (!mapRemoteToClient.containsKey(eid)) - { - return null; - } - long proxyEid = mapRemoteToClient.get(eid); - return entities.get(proxyEid); - } - - public CachedEntity getByLocalEID(long eid) { - if (!mapClientToRemote.containsKey(eid)) - { - return null; - } - return entities.get(eid); - } - - public CachedEntity removeByRemoteEID(long eid) { - if (!mapRemoteToClient.containsKey(eid)) - { - return null; - } - long proxyEid = mapRemoteToClient.get(eid); - CachedEntity e = entities.remove(proxyEid); - if (e == null) { - return null; - } - mapClientToRemote.remove(proxyEid); - playerEntities.remove(e.proxyEid); - return e; - } - - /** - * Cache a new entity by its spawn packet. - * - * @param packet - * @return Returns null if that entity isn't supported on MCPE yet. - */ - public CachedEntity newEntity(ServerSpawnMobPacket packet) { - EntityType peType = EntityType.convertToPE(packet.getType()); - if (peType == null) { - return null; // Not supported - } - - CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), MagicValues.value(Integer.class, packet.getType()), - peType, null, false, null); - e.x = packet.getX(); - e.y = packet.getY(); - e.z = packet.getZ(); - e.motionX = packet.getMotionX(); - e.motionY = packet.getMotionY(); - e.motionZ = packet.getMotionZ(); - e.yaw = packet.getYaw(); - e.pitch = packet.getPitch(); - e.pcMeta = packet.getMetadata(); - e.spawned = true; - entities.put(e.proxyEid, e); - mapClientToRemote.put(e.proxyEid, e.eid); - mapRemoteToClient.put(e.eid, e.proxyEid); - return e; - } - - public CachedEntity newPlayer(ServerSpawnPlayerPacket packet) { - CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), -1, EntityType.PLAYER, null, true, packet.getUUID()); - e.x = packet.getX(); - e.y = packet.getY(); - e.z = packet.getZ(); - e.yaw = packet.getYaw(); - e.pitch = packet.getPitch(); - e.pcMeta = packet.getMetadata(); - e.spawned = true; - entities.put(e.proxyEid, e); - mapClientToRemote.put(e.proxyEid, e.eid); - mapRemoteToClient.put(e.eid, e.proxyEid); - playerEntities.add(e.proxyEid); - return e; - } - - public CachedEntity newObject(ServerSpawnObjectPacket packet) { - CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), -1, EntityType.ITEM, packet.getType(), false, null); - e.x = packet.getX(); - e.y = packet.getY(); - e.z = packet.getZ(); - e.motionX = packet.getMotionX(); - e.motionY = packet.getMotionY(); - e.motionZ = packet.getMotionZ(); - e.yaw = packet.getYaw(); - e.pitch = packet.getPitch(); - e.spawned = false; // Server will update its data then we can send it. - entities.put(e.proxyEid, e); - mapClientToRemote.put(e.proxyEid, e.eid); - mapRemoteToClient.put(e.eid, e.proxyEid); - return e; - } - - public boolean isRemoteEIDPlayerEntity(long eid) { - long proxyEid = mapRemoteToClient.get(eid); - return playerEntities.contains(proxyEid); - } - - public void onTick() { - // Disabled this for now - /* + // vars + + private final UpstreamSession upstream; + // proxy eid -> entity + private final Map entities = Collections + .synchronizedMap(new HashMap<>()); + // pro + private final Set playerEntities = Collections.synchronizedSet(new HashSet()); + + // 1 is for client + private final AtomicLong nextClientEntityId = new AtomicLong(2L); + private final Map mapRemoteToClient = Collections.synchronizedMap(new HashMap<>()); + private final Map mapClientToRemote = Collections.synchronizedMap(new HashMap<>()); + + // constructor + public EntityCache(UpstreamSession upstream) { + this.upstream = upstream; + reset(false); + } + + // public + public UpstreamSession getUpstream() { + return upstream; + } + + public Map getEntities() { + return entities; + } + + public void reset(boolean clear) { + if (clear) { + entities.clear(); + mapRemoteToClient.clear(); + mapClientToRemote.clear(); + } + CachedEntity clientEntity = new CachedEntity(1L, 1L, -1, null, null, true, null); + entities.put(1L, clientEntity); + } + + public CachedEntity getClientEntity() { + return entities.get(1L); + } + + public CachedEntity getByRemoteEID(long eid) { + if (!mapRemoteToClient.containsKey(eid)) { + return null; + } + long proxyEid = mapRemoteToClient.get(eid); + return entities.get(proxyEid); + } + + public CachedEntity getByLocalEID(long eid) { + if (!mapClientToRemote.containsKey(eid)) { + return null; + } + return entities.get(eid); + } + + public CachedEntity removeByRemoteEID(long eid) { + if (!mapRemoteToClient.containsKey(eid)) { + return null; + } + long proxyEid = mapRemoteToClient.get(eid); + CachedEntity e = entities.remove(proxyEid); + if (e == null) { + return null; + } + mapClientToRemote.remove(proxyEid); + playerEntities.remove(e.proxyEid); + return e; + } + + /** + * Cache a new entity by its spawn packet. + * + * @param packet + * @return Returns null if that entity isn't supported on MCPE yet. + */ + public CachedEntity newEntity(ServerSpawnMobPacket packet) { + EntityType peType = EntityType.convertToPE(packet.getType()); + if (peType == null) { + return null; // Not supported + } + + CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), MagicValues.value(Integer.class, packet.getType()), + peType, null, false, null); + e.x = packet.getX(); + e.y = packet.getY(); + e.z = packet.getZ(); + e.motionX = packet.getMotionX(); + e.motionY = packet.getMotionY(); + e.motionZ = packet.getMotionZ(); + e.yaw = packet.getYaw(); + e.pitch = packet.getPitch(); + e.pcMeta = packet.getMetadata(); + e.spawned = false; + entities.put(e.proxyEid, e); + mapClientToRemote.put(e.proxyEid, e.eid); + mapRemoteToClient.put(e.eid, e.proxyEid); + return e; + } + + public CachedEntity newPlayer(ServerSpawnPlayerPacket packet) { + CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), -1, EntityType.PLAYER, null, true, packet.getUUID()); + e.x = packet.getX(); + e.y = packet.getY(); + e.z = packet.getZ(); + e.yaw = packet.getYaw(); + e.pitch = packet.getPitch(); + e.pcMeta = packet.getMetadata(); + e.spawned = true; + entities.put(e.proxyEid, e); + mapClientToRemote.put(e.proxyEid, e.eid); + mapRemoteToClient.put(e.eid, e.proxyEid); + playerEntities.add(e.proxyEid); + return e; + } + + public CachedEntity newObject(ServerSpawnObjectPacket packet) { + CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), -1, EntityType.ITEM, packet.getType(), + false, null); + e.x = packet.getX(); + e.y = packet.getY(); + e.z = packet.getZ(); + e.motionX = packet.getMotionX(); + e.motionY = packet.getMotionY(); + e.motionZ = packet.getMotionZ(); + e.yaw = packet.getYaw(); + e.pitch = packet.getPitch(); + e.spawned = false; // Server will update its data then we can send it. + entities.put(e.proxyEid, e); + mapClientToRemote.put(e.proxyEid, e.eid); + mapRemoteToClient.put(e.eid, e.proxyEid); + return e; + } + + //special for Object that are not items + public CachedEntity newEntity(ServerSpawnObjectPacket packet) { + EntityType peType = EntityMetaTranslator.translateToPE(packet.getType()); + CachedEntity e = new CachedEntity(packet.getEntityId(), nextClientEntityId.getAndIncrement(), MagicValues.value(Integer.class, packet.getType()), + peType, packet.getType(), false, null); + e.x = packet.getX(); + e.y = packet.getY(); + e.z = packet.getZ(); + e.motionX = packet.getMotionX(); + e.motionY = packet.getMotionY(); + e.motionZ = packet.getMotionZ(); + e.yaw = packet.getYaw(); + e.pitch = packet.getPitch(); + e.spawned = false; // Server will update its data then we can send it. + entities.put(e.proxyEid, e); + mapClientToRemote.put(e.proxyEid, e.eid); + mapRemoteToClient.put(e.eid, e.proxyEid); + return e; + } + + public boolean isRemoteEIDPlayerEntity(long eid) { + long proxyEid = mapRemoteToClient.get(eid); + return playerEntities.contains(proxyEid); + } + + public void onTick() { + // Disabled this for now + /* * entities.values().stream().map((e) -> { e.x += e.motionX; e.y += e.motionY; * e.z += e.motionZ; return e; }); - */ - } - - // private + */ + } + // private } From f938e516cd77ec5be0ea776f833eff144483d8c3 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 13:37:12 +0100 Subject: [PATCH 48/60] implements some data values for entity metadatas --- .../translator/EntityMetaTranslator.java | 585 ++++++++++-------- 1 file changed, 334 insertions(+), 251 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java index b5d376133..a731ba306 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/EntityMetaTranslator.java @@ -15,271 +15,354 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; 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.protocol.type.Slot; +import org.dragonet.proxy.utilities.BlockPosition; public final class EntityMetaTranslator { - // vars + // vars - // constructor - public EntityMetaTranslator() { + // constructor + public EntityMetaTranslator() { - } + } - // public - public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType type) { - /* - * Following format was fetched from http://wiki.vg/Entities#Entity_meta_Format - */ - EntityMetaData peMeta = EntityMetaData.createDefault(); - if (pcMeta == null) - return peMeta; - for (EntityMetadata m : pcMeta) { - if (m == null) { - continue; - } - switch (m.getId()) { - case 0:// Flags - byte pcFlags = ((byte) m.getValue()); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ONFIRE, (pcFlags & 0x01) > 0); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SNEAKING, (pcFlags & 0x02) > 0); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_RIDING, (pcFlags & 0x04) > 0); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SPRINTING, (pcFlags & 0x08) > 0); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ACTION, (pcFlags & 0x10) > 0); - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_INVISIBLE, (pcFlags & 0x20) > 0); -// peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLOWING, (pcFlags & 0x40) > 0); //Not implemented - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLIDING, (pcFlags & 0x80) > 0); - break; - case 1:// Air - peMeta.set(EntityMetaData.Constants.DATA_AIR, new ShortMeta(((Integer) m.getValue()).shortValue())); - break; - case 2:// Name tag - if ((String) m.getValue() != "") - peMeta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta((String) m.getValue())); - break; - case 3:// Always show name tag - byte data; - if (m.getType() == MetadataType.BYTE) { - data = (byte) m.getValue(); - } else if (m.getType() == MetadataType.INT) { - data = (byte) (((int) m.getValue()) & 0xFF); - } else { - data = 1; - } - peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_CAN_SHOW_NAMETAG, data > 0); - break; - case 4://Boolean : Is silent - peMeta.set(EntityMetaData.Constants.DATA_FLAG_SILENT, new ByteMeta((byte)(((boolean)m.getValue()) ? 0x00 : 0x01))); - break; - case 5://Boolean : No gravity - peMeta.set(EntityMetaData.Constants.DATA_FLAG_AFFECTED_BY_GRAVITY, new ByteMeta((byte)(((boolean)m.getValue()) ? 0x01 : 0x00)));// need ! - break; - case 6: - switch(type) - { - //case MINECART: //VarInt : Shaking power - //peMeta.map.put(EntityMetaData.Constants.DATA_HEALTH, new IntegerMeta((int) m.getValue())); - //case PRIMED_TNT: //VarInt : Fuse time - //peMeta.map.put(EntityMetaData.Constants.DATA_FLAG_IGNITED, new IntegerMeta((int) m.getValue())); - //case POTION: //Slot : Potion which is thrown - //case FALLING_BLOCK: //Position : spawn position - //case AREA_EFFECT_CLOUD: //Float : Radius - //peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_RADIUS, new FloatMeta((float) m.getValue())); - //case FISHING_HOOK: //VarInt : Hooked entity id + 1, or 0 if there is no hooked entity - case ARROW: //Byte : is critical - peMeta.set(EntityMetaData.Constants.DATA_FLAG_CRITICAL, new ByteMeta((byte) m.getValue())); - break; - //case TIPPED_ARROW: //VarInt : Color (-1 for no particles) - //case BOAT: //VarInt : Time since last hit - //case ENDER_CRISTAL: //OptPosition : Beam target - //case WITHER_SKULL: //Boolean Invulnerable - //case FIREWORKS: //Slot : Firework info -// case ITEM_FRAME: //Slot : Item - case ITEM: //Slot : Item - peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta((Slot) ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue()))); - break; - default: // (all LIVING) Byte : Hand states, used to trigger blocking/eating/drinking animation. - break; - } - break; - case 7: - switch(type) - { - //case MINECART: //VarInt : Shaking direction - //case AREA_EFFECT_CLOUD: //VarInt : Color (only for mob spell particle) - //peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_WAITING, new IntegerMeta((int) m.getValue())); - //case BOAT: //VarInt : Forward direction - //case ENDER_CRISTAL: //Boolean : Show bottom - //case FIREWORKS: //VarInt : Entity ID of entity which used firework (for elytra boosting) - //case ITEM_FRAME: //VarInt : Rotation - default: // (all LIVING) Float : Health + // public + public static EntityMetaData translateToPE(EntityMetadata[] pcMeta, EntityType type) { + /* + * Following format was fetched from http://wiki.vg/Entities#Entity_meta_Format + */ + EntityMetaData peMeta = EntityMetaData.createDefault(); + if (pcMeta == null) { + return peMeta; + } + System.out.println("Entity + " + type); + for (EntityMetadata m : pcMeta) { + System.out.println(m); + if (m == null) { + continue; + } + switch (m.getId()) { + case 0:// Flags + byte pcFlags = ((byte) m.getValue()); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ONFIRE, (pcFlags & 0x01) > 0); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SNEAKING, (pcFlags & 0x02) > 0); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_RIDING, (pcFlags & 0x04) > 0); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SPRINTING, (pcFlags & 0x08) > 0); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ACTION, (pcFlags & 0x10) > 0); + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_INVISIBLE, (pcFlags & 0x20) > 0); + //peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLOWING, (pcFlags & 0x40) > 0); //Not implemented (possible with potions) + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLIDING, (pcFlags & 0x80) > 0); + break; + case 1:// Air + peMeta.set(EntityMetaData.Constants.DATA_AIR, new ShortMeta(((Integer) m.getValue()).shortValue())); + break; + case 2:// Name tag + if ((String) m.getValue() != "") { + peMeta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta((String) m.getValue())); + } + break; + case 3:// Always show name tag + byte data; + if (m.getType() == MetadataType.BYTE) { + data = (byte) m.getValue(); + } else if (m.getType() == MetadataType.INT) { + data = (byte) (((int) m.getValue()) & 0xFF); + } else { + data = 1; + } + peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_CAN_SHOW_NAMETAG, data > 0); + break; + case 4://Boolean : Is silent + peMeta.set(EntityMetaData.Constants.DATA_FLAG_SILENT, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + case 5://Boolean : No gravity + peMeta.set(EntityMetaData.Constants.DATA_FLAG_AFFECTED_BY_GRAVITY, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x00 : 0x01)));// need ! + break; + case 6: + switch (type) { + case MINECART: //VarInt : Shaking power + peMeta.map.put(EntityMetaData.Constants.DATA_HURT_TIME, new IntegerMeta((int) m.getValue())); + break; + case PRIMED_TNT: //VarInt : Fuse time + peMeta.map.put(EntityMetaData.Constants.DATA_FLAG_IGNITED, new IntegerMeta((int) m.getValue())); + break; + case POTION: //Slot : Potion which is thrown + peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta((Slot) ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue()))); + break; + case FALLING_BLOCK: //Position : spawn position + peMeta.map.put(EntityMetaData.Constants.DATA_BLOCK_TARGET, new BlockPositionMeta(new BlockPosition((Position) m.getValue()))); + break; + case AREA_EFFECT_CLOUD: //Float : Radius + peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_RADIUS, new FloatMeta((float) m.getValue())); + break; + //case FISHING_HOOK: //VarInt : Hooked entity id + 1, or 0 if there is no hooked entity + case ARROW: //Byte : is critical + peMeta.set(EntityMetaData.Constants.DATA_FLAG_CRITICAL, new ByteMeta((byte) m.getValue())); + break; + //case TIPPED_ARROW: //VarInt : Color (-1 for no particles) + case BOAT: //VarInt : Time since last hit + peMeta.map.put(EntityMetaData.Constants.DATA_HURT_TIME, new IntegerMeta((int) m.getValue())); + break; + case ENDER_CRYSTAL: //OptPosition : Beam target + peMeta.map.put(EntityMetaData.Constants.DATA_BLOCK_TARGET, new BlockPositionMeta(new BlockPosition((Position) m.getValue()))); + break; + case WITHER_SKULL: //Boolean Invulnerable + peMeta.set(EntityMetaData.Constants.DATA_WITHER_INVULNERABLE_TICKS, new IntegerMeta((int) m.getValue())); + break; + case FIREWORKS_ROCKET: //Slot : Firework info + peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta((Slot) ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue()))); + break; + //case ITEM_FRAME: //Slot : Item + case ITEM: //Slot : Item + peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta((Slot) ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue()))); + break; + default: // (all LIVING) Byte : Hand states, used to trigger blocking/eating/drinking animation. + break; + } + break; + case 7: + switch (type) { + case BOAT: //VarInt : Forward direction + case MINECART: //VarInt : Shaking direction + peMeta.map.put(EntityMetaData.Constants.DATA_HURT_DIRECTION, new IntegerMeta((int) m.getValue())); + break; + case AREA_EFFECT_CLOUD: //VarInt : Color (only for mob spell particle) + peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_WAITING, new IntegerMeta((int) m.getValue())); + break; + //case ENDER_CRISTAL: //Boolean : Show bottom + case FIREWORKS_ROCKET: //VarInt : Entity ID of entity which used firework (for elytra boosting) + peMeta.map.put(EntityMetaData.Constants.DATA_OWNER_EID, new IntegerMeta((int) m.getValue())); +// case ITEM_FRAME: //VarInt : Rotation +// peMeta.map.put(EntityMetaData.Constants.DATA_, new IntegerMeta((int) m.getValue())); +// break; + default: // (all LIVING) Float : Health // peMeta.map.put(EntityMetaData.Constants.DATA_HEALTH, new IntegerMeta((int) m.getValue())); - break; - } - break; - case 8: - switch(type) - { - //case MINECART: //Float : Shaking multiplier - //case AREA_EFFECT_CLOUD: //Boolean : Ignore radius and show effect as single point, not area - //case BOAT: //Float : Damage taken - default: // (all LIVING) VarInt : Potion effect color (or 0 if there is no effect) - peMeta.set(EntityMetaData.Constants.DATA_POTION_COLOR, new ByteMeta((byte) ((int) m.getValue() & 0xFF))); - break; - } - break; - case 9: - switch(type) - { - //case MINECART: //VarInt : Custom block ID and damage - //case AREA_EFFECT_CLOUD: //VarInt : Particle ID - //peMeta.map.put(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_PARTICLE_ID, new IntegerMeta((int) m.getValue())); - //case BOAT: //VarInt : Type (0=oak, 1=spruce, 2=birch, 3=jungle, 4=acacia, 5=dark oak) - 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()) ? 0x00 : 0x01))); - break; - } - break; - case 10: - switch(type) - { - //case MINECART: //VarInt : Custom block Y position (in 16ths of a block) - //case AREA_EFFECT_CLOUD: //VarInt : Particle parameter 1 - //case BOAT: //Boolean : Right paddle turning - default: //(all LIVING) VarInt : Number of arrows in entity - // Not supported yet - break; - } - break; - case 11: - switch(type) - { - //case MINECART: //Boolean : Show custom block - //case AREA_EFFECT_CLOUD: //VarInt : Particle parameter 2 - //case BOAT: //Boolean : Left paddle turning - //case ARMOR_STAND: //Byte : see http://wiki.vg/Entity_metadata#ArmorStand - //case INSENTIENT: //Byte : (0x01 = NoAI, 0x02 = Left handed) - case PLAYER: //Float : Additional Hearts - // Not supported yet - break; - } - break; - case 12: - switch(type) - { - //case MINECART_FURNACE: //Boolean : Is powered - //case MINECART_COMMAND_BLOCK: //String : Command - //case ARMOR_STAND: //Rotation : Head rotation - //case BAT: //Byte : Is hanging - //case AGEABLE: //Boolean : Is baby - //case IRONGOLEM: //Byte : Is player-created - //case SNOWMAN: //Byte : has no pumpkin hat - //case SHULKER: //Direction : Facing direction - //case BLAZE: //Byte : 0x01 = Is on fire - //case CREEPER: //VarInt State (-1 = idle, 1 = fuse) - //case EVOCATOR: //Byte Spell (0: none, 1: summon vex, 2: attack, 3: wololo) - //case VEX: //Byte : 0x01 = Is in attack mode - //case VINDICATOR: //Byte : 0x01 = Has target (aggressive state) - //case SKELETON: //Boolean : Is swinging arms - //case SPIDER: //Byte : 0x01 = Is climbing - //case WITCH: //Boolean : Is drinking potion - //case WITHER: //VarInt : Center head's target (entity ID, or 0 if no target) - //case ZOMBIE: //Boolean : Is baby - //case ENDERMAN: //Opt BlockID : Carried block - //case ENDER_DRAGON: //VarInt : Dragon phase - //case GHAST: //Boolean : Is attacking - //case SLIME : //VarInt : Size - case PLAYER: //VarInt : Score - // Not supported yet - break; - } - break; - case 13: - switch(type) - { - //case MINECART_COMMAND_BLOCK: //Chat : Last output - //case ARMOR_STAND: //Rotation : Body rotation - //case HORSE: //Byte : see http://wiki.vg/Entity_metadata#AbstractHorse - //case PIG: //Boolean : Has saddle - //case RABBIT: //VarInt : Type - //case POLAR_BEAR: //Boolean : Standing up - //case SHEEP: //Byte : see http://wiki.vg/Entity_metadata#Sheep - //case TAMEABLE_ANIMAL: //Byte : see http://wiki.vg/Entity_metadata#TameableAnimal - //case VILLAGER: //VarInt : Profession (Farmer = 0, Librarian = 1, Priest = 2, Blacksmith = 3, Butcher = 4, Nitwit = 5) - //case SHULKER: //OptPosition : Attachment position - //case CREEPER: //Boolean : Is charged - //case WITHER: //VarInt : Left(?) head's target (entity ID, or 0 if no target) - //case ZOMBIE: //VarInt : Unused (previously type) - //case ENDERMAN: //Boolean : Is screaming - case PLAYER: //Byte : The Displayed Skin Parts bit mask that is sent in Client Settings - // Not supported yet - break; - } - break; - case 14: - switch(type) - { - //case ARMOR_STAND: //Rotation : Left arm rotation - //case HORSE: //OptUUID : Owner - //case PIG: //VarInt : Total time to "boost" with a carrot on a stick for - //case TAMEABLE_ANIMAL: //OptUUID : Owner - //case SHULKER: //Byte : Shield height - //case CREEPER: //Boolean : Is ignited - //case WITHER: //VarInt : Right(?) head's target (entity ID, or 0 if no target) - //case ZOMBIE: //Boolean : Are hands held up - case PLAYER: //Byte : Main hand (0 : Left, 1 : Right) - // Not supported yet - break; - } - break; - case 15: - switch(type) - { - //case ARMOR_STAND: //Rotation : Right arm rotation - //case HORSE: //VarInt : Variant (Color & Style) - //case CHESTED_HORSE: //Boolean : Has Chest - //case OCELOT: //VarInt Type (0 = untamed, 1 = tuxedo, 2 = tabby, 3 = siamese). Used to render regardless as to whether it is tamed or not. - //case WOLF: //Float : Damage taken (used for tail rotation) - //case PARROT: //VarInt Variant (0: red/blue, 1: blue, 2: green, 3: yellow/blue, 4: silver) - //case SHULKER: //Byte : Color (dye color) - //case WITHER: //VarInt : Invulnerable time - //case ZOMBIE_VILLAGER: //Boolean : Is converting - case PLAYER: //NBT Tag : Left shoulder entity data (for occupying parrot) - // Not supported yet - break; - } - break; - case 16: - switch(type) - { - //case ARMOR_STAND: //Rotation : Left leg rotation - //case HORSE: //VarInt : Armor (0: none, 1: iron, 2: gold, 3: diamond) - //case WOLF: //Boolean : Is begging - //case ZOMBIE_VILLAGER: //VarInt : Profession - case PLAYER: //NBT Tag : Right shoulder entity data (for occupying parrot) - // Not supported yet - break; - } - case 17: - switch(type) - { - //case ARMOR_STAND: //Rotation : Right leg rotation - //case WOLF: //VarInt : Collar color (values are those used with dyes) - //break; - } - break; - } - } - return peMeta; - } - - // private + break; + } + break; + case 8: + switch (type) { + case MINECART: //Float : Shaking multiplier + case AREA_EFFECT_CLOUD: //Boolean : Ignore radius and show effect as single point, not area + case BOAT: //Float : Damage taken + break; + default: // (all LIVING) VarInt : Potion effect color (or 0 if there is no effect) + peMeta.set(EntityMetaData.Constants.DATA_POTION_COLOR, new ByteMeta((byte) ((int) m.getValue() & 0xFF))); + break; + } + break; + case 9: + switch (type) { + case MINECART: //VarInt : Custom block ID and damage + peMeta.set(EntityMetaData.Constants.DATA_MINECART_DISPLAY_BLOCK, new IntegerMeta((int) m.getValue())); + break; + case AREA_EFFECT_CLOUD: //VarInt : Particle ID + 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()))); + 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))); + break; + } + break; + case 10: + switch (type) { + case MINECART: //VarInt : Custom block Y position (in 16ths of a block) + peMeta.set(EntityMetaData.Constants.DATA_MINECART_DISPLAY_OFFSET, new IntegerMeta((int) m.getValue())); + break; + case AREA_EFFECT_CLOUD: //VarInt : Particle parameter 1 + break; + case BOAT: //Boolean : Right paddle turning + peMeta.set(EntityMetaData.Constants.DATA_PADDLE_TIME_RIGHT, new IntegerMeta(5)); + break; + default: //(all LIVING) VarInt : Number of arrows in entity + // Not supported yet + break; + } + break; + case 11: + switch (type) { + case MINECART: //Boolean : Show custom block + peMeta.set(EntityMetaData.Constants.DATA_MINECART_HAS_DISPLAY, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + case AREA_EFFECT_CLOUD: //VarInt : Particle parameter 2 + break; + case BOAT: //Boolean : Left paddle turning + peMeta.set(EntityMetaData.Constants.DATA_PADDLE_TIME_LEFT, new IntegerMeta(5)); + break; + case ARMOR_STAND: //Byte : see http://wiki.vg/Entity_metadata#ArmorStand + break; + //case INSENTIENT: //Byte : (0x01 = NoAI, 0x02 = Left handed) + case PLAYER: //Float : Additional Hearts + // Not supported yet + break; + } + break; + case 12: + switch (type) { + case MINECART: //Boolean : Is powered + 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 + break; + case BAT: //Byte : Is hanging + case IRONGOLEM: //Byte : Is player-created + case SNOWMAN: //Byte : has no pumpkin hat +// case SHULKER: //Direction : Facing direction + break; + case BLAZE: //Byte : 0x01 = Is on fire + peMeta.set(EntityMetaData.Constants.DATA_FLAG_ONFIRE, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + case CREEPER: //VarInt State (-1 = idle, 1 = fuse) +// case EVOCATOR: //Byte Spell (0: none, 1: summon vex, 2: attack, 3: wololo) + case VEX: //Byte : 0x01 = Is in attack mode +// case VINDICATOR: //Byte : 0x01 = Has target (aggressive state) + case SKELETON: //Boolean : Is swinging arms + break; + case SPIDER: //Byte : 0x01 = Is climbing + peMeta.set(EntityMetaData.Constants.DATA_FLAG_WALLCLIMBING, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; +// case WITCH: //Boolean : Is drinking potion +// case WITHER: //VarInt : Center head's target (entity ID, or 0 if no target) + case ENDERMAN: //Opt BlockID : Carried block +// case ENDER_DRAGON: //VarInt : Dragon phase + case GHAST: //Boolean : Is attacking + case SLIME : //VarInt : Size + break; + case PLAYER: //VarInt : Score + // Not supported yet + break; + default: //ZOMBIE, AGEABLE + peMeta.set(EntityMetaData.Constants.DATA_FLAG_BABY, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + } + break; + case 13: + switch (type) { + //case MINECART_COMMAND_BLOCK: //Chat : Last output + //case ARMOR_STAND: //Rotation : Body rotation + //case HORSE: //Byte : see http://wiki.vg/Entity_metadata#AbstractHorse + case PIG: //Boolean : Has saddle + peMeta.set(EntityMetaData.Constants.DATA_FLAG_SADDLED, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + //case RABBIT: //VarInt : Type + //case POLAR_BEAR: //Boolean : Standing up + //case SHEEP: //Byte : see http://wiki.vg/Entity_metadata#Sheep + //case TAMEABLE_ANIMAL: //Byte : see http://wiki.vg/Entity_metadata#TameableAnimal + //case VILLAGER: //VarInt : Profession (Farmer = 0, Librarian = 1, Priest = 2, Blacksmith = 3, Butcher = 4, Nitwit = 5) + //case SHULKER: //OptPosition : Attachment position + case CREEPER: //Boolean : Is charged + peMeta.set(EntityMetaData.Constants.DATA_FLAG_CHARGED, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + //case WITHER: //VarInt : Left(?) head's target (entity ID, or 0 if no target) + //case ZOMBIE: //VarInt : Unused (previously type) + //case ENDERMAN: //Boolean : Is screaming + case PLAYER: //Byte : The Displayed Skin Parts bit mask that is sent in Client Settings + // Not supported yet + break; + } + break; + case 14: + switch (type) { + //case ARMOR_STAND: //Rotation : Left arm rotation + //case HORSE: //OptUUID : Owner + //case PIG: //VarInt : Total time to "boost" with a carrot on a stick for + //case TAMEABLE_ANIMAL: //OptUUID : Owner + //case SHULKER: //Byte : Shield height + case CREEPER: //Boolean : Is ignited + peMeta.set(EntityMetaData.Constants.DATA_FLAG_IGNITED, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00))); + break; + //case WITHER: //VarInt : Right(?) head's target (entity ID, or 0 if no target) + //case ZOMBIE: //Boolean : Are hands held up + case PLAYER: //Byte : Main hand (0 : Left, 1 : Right) + // Not supported yet + break; + } + break; + case 15: + switch (type) { + //case ARMOR_STAND: //Rotation : Right arm rotation + //case HORSE: //VarInt : Variant (Color & Style) + //case CHESTED_HORSE: //Boolean : Has Chest + //case OCELOT: //VarInt Type (0 = untamed, 1 = tuxedo, 2 = tabby, 3 = siamese). Used to render regardless as to whether it is tamed or not. + //case WOLF: //Float : Damage taken (used for tail rotation) + //case PARROT: //VarInt Variant (0: red/blue, 1: blue, 2: green, 3: yellow/blue, 4: silver) + //case SHULKER: //Byte : Color (dye color) + //case WITHER: //VarInt : Invulnerable time + //case ZOMBIE_VILLAGER: //Boolean : Is converting + case PLAYER: //NBT Tag : Left shoulder entity data (for occupying parrot) + // Not supported yet + break; + } + break; + case 16: + switch (type) { + //case ARMOR_STAND: //Rotation : Left leg rotation + //case HORSE: //VarInt : Armor (0: none, 1: iron, 2: gold, 3: diamond) + //case WOLF: //Boolean : Is begging + //case ZOMBIE_VILLAGER: //VarInt : Profession + case PLAYER: //NBT Tag : Right shoulder entity data (for occupying parrot) + // Not supported yet + break; + } + case 17: + switch (type) { + //case ARMOR_STAND: //Rotation : Right leg rotation + //case WOLF: //VarInt : Collar color (values are those used with dyes) + //break; + } + break; + } + } + return peMeta; + } + public static EntityType translateToPE(ObjectType pcType) { + switch (pcType) { + case SNOWBALL: + return EntityType.SNOW_BALL; + case GHAST_FIREBALL: + return EntityType.LARGE_FIREBALL; + case BLAZE_FIREBALL: + return EntityType.LARGE_FIREBALL; + case WITHER_HEAD_PROJECTILE: + return EntityType.LARGE_FIREBALL; + case ITEM_FRAME: + return EntityType.NONE; //TODO + case EYE_OF_ENDER: + return EntityType.ENDER_EYE; + case EXP_BOTTLE: + return EntityType.ITEM; + case FIREWORK_ROCKET: + return EntityType.FIREWORKS_ROCKET; + case EVOCATION_FANGS: + return EntityType.EVOCATION_FANG; + case FISH_HOOK: + return EntityType.FISHING_HOOK; + case SPECTRAL_ARROW: + return EntityType.ARROW; + case TIPPED_ARROW: + return EntityType.ARROW; + case DRAGON_FIREBALL: + return EntityType.LARGE_FIREBALL; + default: + return EntityType.valueOf(pcType.name()); + } + } } From 4c3ae5e0abfd1dae4dd3870da1874d75316bafe7 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 13:38:47 +0100 Subject: [PATCH 49/60] fix items / armorstands spawning --- .../pc/PCEntityMetadataPacketTranslator.java | 70 ++++++++++++++----- ...layerPositionRotationPacketTranslator.java | 10 ++- .../pc/PCSpawnMobPacketTranslator.java | 63 ++++++++--------- .../pc/PCSpawnObjectPacketTranslator.java | 25 ++----- 4 files changed, 96 insertions(+), 72 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java index 02afe7075..73d07d91c 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java @@ -13,35 +13,69 @@ 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.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.network.translator.EntityMetaTranslator; import org.dragonet.proxy.network.translator.IPCPacketTranslator; import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.AddEntityPacket; +import org.dragonet.proxy.protocol.packets.AddItemEntityPacket; import org.dragonet.proxy.protocol.packets.SetEntityDataPacket; +import org.dragonet.proxy.utilities.Vector3F; public class PCEntityMetadataPacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCEntityMetadataPacketTranslator() { + public PCEntityMetadataPacketTranslator() { - } + } - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) { - CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (entity == null) { - return null; - } - entity.pcMeta = packet.getMetadata(); - SetEntityDataPacket pk = new SetEntityDataPacket(); + public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); +// System.out.println("ServerEntityMetadataPacket entity " + packet.getEntityId() + " update "); + if (entity == null) + { + return null; + } + entity.pcMeta = packet.getMetadata(); + if (entity.spawned) + { + SetEntityDataPacket pk = new SetEntityDataPacket(); + pk.rtid = entity.proxyEid; + pk.meta = EntityMetaTranslator.translateToPE(packet.getMetadata(), entity.peType); + session.sendPacket(pk); + } + else + { + if (entity.peType == EntityType.ITEM) + { + AddItemEntityPacket pk = new AddItemEntityPacket(); pk.rtid = entity.proxyEid; - pk.meta = EntityMetaTranslator.translateToPE(packet.getMetadata(), entity.peType); + pk.eid = entity.proxyEid; + pk.metadata = EntityMetaTranslator.translateToPE(packet.getMetadata(), entity.peType); + pk.item = ((SlotMeta)pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; + pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); + pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); + entity.spawned = true; session.sendPacket(pk); - return null; - } - - // private - + } + else + { + AddEntityPacket pk = new AddEntityPacket(); + pk.rtid = entity.proxyEid; + pk.eid = entity.proxyEid; + pk.type = entity.peType.getPeType(); + pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); + pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); + pk.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); + // TODO: Hack for now. ;P + pk.attributes = new PEEntityAttribute[]{}; + session.sendPacket(pk); + } + } + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java index e875b9c2b..de191611b 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java @@ -38,10 +38,13 @@ 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.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; @@ -229,11 +232,12 @@ else if (entity.peType != null) //ENTITY AddItemEntityPacket pk = new AddItemEntityPacket(); pk.rtid = entity.proxyEid; pk.eid = entity.proxyEid; + pk.metadata = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); + pk.item = ((SlotMeta)pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); - pk.item = ItemBlockTranslator.translateSlotToPE(new ItemStack(1, 1)); - pk.metadata = EntityMetaTranslator.translateToPE(entity.pcMeta, EntityType.ITEM); - session.sendPacket(pk);//not working for now + entity.spawned = true; + session.sendPacket(pk); } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java index 7225d8375..bced7f5e8 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnMobPacketTranslator.java @@ -17,44 +17,41 @@ 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.network.translator.EntityMetaTranslator; import org.dragonet.proxy.protocol.PEPacket; import org.dragonet.proxy.protocol.packets.AddEntityPacket; import org.dragonet.proxy.utilities.Vector3F; public class PCSpawnMobPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCSpawnMobPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerSpawnMobPacket packet) { - try { - CachedEntity e = session.getEntityCache().newEntity(packet); - if (e == null) { - return null; - } - - AddEntityPacket pk = new AddEntityPacket(); - pk.rtid = e.proxyEid; - pk.eid = e.proxyEid; - pk.type = e.peType.getPeType(); - pk.position = new Vector3F((float) e.x, (float) e.y, (float) e.z); - pk.motion = new Vector3F((float) e.motionX, (float) e.motionY, (float) e.motionZ); - // TODO: Hack for now. ;P - pk.meta = EntityMetaData.createDefault(); - pk.attributes = new PEEntityAttribute[]{}; - - return new PEPacket[] { pk }; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - // private + 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")); + if (e == null) { + return null; + } + + AddEntityPacket pk = new AddEntityPacket(); + pk.rtid = e.proxyEid; + pk.eid = e.proxyEid; + pk.type = e.peType.getPeType(); + pk.position = new Vector3F((float) e.x, (float) e.y, (float) e.z); + pk.motion = new Vector3F((float) e.motionX, (float) e.motionY, (float) e.motionZ); + pk.meta = EntityMetaTranslator.translateToPE(e.pcMeta, e.peType); + // TODO: Hack for now. ;P + pk.attributes = new PEEntityAttribute[]{}; + e.spawned = true; + return new PEPacket[]{pk}; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java index 78a74ced6..6bfe1bbd9 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSpawnObjectPacketTranslator.java @@ -12,32 +12,21 @@ */ package org.dragonet.proxy.network.translator.pc; -import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; 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.ServerSpawnObjectPacket; import org.dragonet.proxy.protocol.PEPacket; public class PCSpawnObjectPacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCSpawnObjectPacketTranslator() { + public PCSpawnObjectPacketTranslator() { - } + } - // public - public PEPacket[] translate(UpstreamSession session, ServerSpawnObjectPacket packet) { - if (packet.getType() == ObjectType.ITEM) { - // Currently only handles item data - CachedEntity futureEntity = session.getEntityCache().newObject(packet); - // This crap needs entity meta to be completed so we have to wait. - return null; - } - return null; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerSpawnObjectPacket packet) { + session.getEntityCache().newEntity(packet); +// System.out.println("ServerSpawnObjectPacket register " + packet.getEntityId() + " entity " + packet.getType().name()); + return null; + } } From 832320421b655f80a7c13f328fba1f0c9d2857a6 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 14:12:50 +0100 Subject: [PATCH 50/60] add entity link packet to protocole --- .../org/dragonet/proxy/protocol/Protocol.java | 1 + .../protocol/packets/SetEntityLinkPacket.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java index 4593d49e1..30ba0ffee 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/Protocol.java @@ -68,6 +68,7 @@ public final class Protocol { packets.put(SET_ENTITY_DATA_PACKET, SetEntityDataPacket.class); packets.put(PLAYER_SKIN_PACKET, PlayerSkinPacket.class); packets.put(PLAYER_HOTBAR_PACKET, PlayerHotbarPacket.class); + packets.put(SET_ENTITY_LINK_PACKET, SetEntityLinkPacket.class); packets.put(CONTAINER_OPEN_PACKET, ContainerOpenPacket.class); packets.put(CONTAINER_CLOSE_PACKET, ContainerClosePacket.class); diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java new file mode 100644 index 000000000..3b6cc85aa --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java @@ -0,0 +1,37 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; + +/** + * Created on 15-10-22. + */ +public class SetEntityLinkPacket extends PEPacket { + + public static final byte TYPE_REMOVE = 0; + public static final byte TYPE_RIDE = 1; + public static final byte TYPE_PASSENGER = 2; + + public long rider; + public long riding; + public byte type; + public byte unknownByte; + + @Override + public void decodePayload() { + + } + + @Override + public void encodePayload() { + this.putEntityUniqueId(this.rider); + this.putEntityUniqueId(this.riding); + this.putByte(this.type); + this.putByte(this.unknownByte); + } + + @Override + public int pid() { + return ProtocolInfo.SET_ENTITY_LINK_PACKET; + } +} From 88378f6af925a91083942b06869bf26f3fc0bf77 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 15:11:13 +0100 Subject: [PATCH 51/60] add entity set passenger translator (WIP) --- .../network/PacketTranslatorRegister.java | 1 + .../PCEntitySetPassengerPacketTranslator.java | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java diff --git a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java index 39d00cb92..f66b3f93d 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -79,6 +79,7 @@ public final class PacketTranslatorRegister { 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()); diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java new file mode 100644 index 000000000..0f6a1fda8 --- /dev/null +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java @@ -0,0 +1,82 @@ +/* + * 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.packet.ingame.server.entity.ServerEntitySetPassengersPacket; +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.SetEntityLinkPacket; +import org.dragonet.proxy.utilities.DebugTools; + +public class PCEntitySetPassengerPacketTranslator implements IPCPacketTranslator { + + public PCEntitySetPassengerPacketTranslator() { + + } + + 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)) + entity = session.getEntityCache().getClientEntity(); + else + return null; + } + + SetEntityLinkPacket pk = new SetEntityLinkPacket(); + pk.rider = entity.proxyEid; + + if (packet.getPassengerIds().length == 0) //dismount + { + pk.riding = 0; + pk.type = 0; + pk.unknownByte = 0x00; + session.sendPacket(pk); + } + else //mount + { + boolean piloteSet = false; + for (int id : packet.getPassengerIds()) + { + CachedEntity riding = session.getEntityCache().getByRemoteEID(id); + + if (riding == null) { + continue; + } + + pk.riding = riding.proxyEid; + + if (!piloteSet) + { + pk.type = 1; + piloteSet = true; + } + else + { + pk.type = 2; + } + + pk.unknownByte = 0x00; + session.sendPacket(pk); + + } + + + } + return null; + } +} From e5c3ca1d4f75b00bae92772e0840596634d810af Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 15:15:54 +0100 Subject: [PATCH 52/60] reformate some classes (\t to 4 spaces) --- .../translator/ItemBlockTranslator.java | 51 +-- .../pc/PCAnimationPacketTranslator.java | 32 +- .../pc/PCEntityMetadataPacketTranslator.java | 27 +- .../pc/PCEntityPositionPacketTranslator.java | 52 ++- .../pc/PCEntityRotationPacketTranslator.java | 52 ++- .../pc/PCPlayerListItemPacketTranslator.java | 79 ++-- ...layerPositionRotationPacketTranslator.java | 366 +++++++++--------- .../pc/PCSoundEventPacketTranslator.java | 12 +- .../PEAdventureSettingsPacketTranslator.java | 7 +- .../pe/PEInteractPacketTranslator.java | 5 - .../pe/PEMovePlayerPacketTranslator.java | 32 +- .../proxy/protocol/packets/AnimatePacket.java | 7 +- .../proxy/utilities/LoginChainDecoder.java | 134 +++---- 13 files changed, 397 insertions(+), 459 deletions(-) diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java index af9d91497..2e9b6fd48 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/ItemBlockTranslator.java @@ -163,54 +163,48 @@ 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) - { - if (pcTag != null) - { + public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag pcTag, org.dragonet.proxy.nbt.tag.CompoundTag target) { + if (pcTag != null) { String name = pcTag.getName() != null ? pcTag.getName() : ""; - if (target == null) - { + if (target == null) { target = new org.dragonet.proxy.nbt.tag.CompoundTag(name); } - switch(pcTag.getClass().getSimpleName()) - { + switch (pcTag.getClass().getSimpleName()) { case "ByteArrayTag": - target.putByteArray(name, (byte[])pcTag.getValue()); + target.putByteArray(name, (byte[]) pcTag.getValue()); break; case "ByteTag": - target.putByte(name, (byte)pcTag.getValue()); + target.putByte(name, (byte) pcTag.getValue()); break; case "DoubleTag": - target.putDouble(name, (double)pcTag.getValue()); + target.putDouble(name, (double) pcTag.getValue()); break; case "FloatTag": - target.putFloat(name, (float)pcTag.getValue()); + target.putFloat(name, (float) pcTag.getValue()); break; case "IntArrayTag": - target.putIntArray(name, (int[])pcTag.getValue()); + target.putIntArray(name, (int[]) pcTag.getValue()); break; case "IntTag": - target.putInt(name, (int)pcTag.getValue()); + target.putInt(name, (int) pcTag.getValue()); break; case "LongTag": - target.putLong(name, (long)pcTag.getValue()); + target.putLong(name, (long) pcTag.getValue()); break; case "ShortTag": - target.putShort(name, (short)pcTag.getValue()); + target.putShort(name, (short) pcTag.getValue()); break; case "StringTag": - target.putString(name, (String)pcTag.getValue()); + target.putString(name, (String) pcTag.getValue()); break; case "CompoundTag": - for(String subName : ((CompoundTag)pcTag).getValue().keySet()) - { - translateRawNBT(0, ((CompoundTag)pcTag).getValue().get(subName), target); + for (String subName : ((CompoundTag) pcTag).getValue().keySet()) { + translateRawNBT(0, ((CompoundTag) pcTag).getValue().get(subName), target); } break; case "ListTag": ListTag listTag = new ListTag(); - for(Tag subTag : (List)pcTag.getValue()) - { + for (Tag subTag : (List) pcTag.getValue()) { listTag.add(translateRawNBT(0, subTag, new org.dragonet.proxy.nbt.tag.CompoundTag())); } target.putList(listTag); @@ -222,17 +216,15 @@ public static org.dragonet.proxy.nbt.tag.CompoundTag translateRawNBT(int id, Tag } return target; } - + //WIP public static org.dragonet.proxy.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); - if (output.contains("id")) - { - switch(output.getString("id")) - { + if (output.contains("id")) { + switch (output.getString("id")) { case "minecraft:bed": output.putString("id", "Bed"); output.putByte("color", output.getInt("color")); //TODO check colors @@ -323,9 +315,8 @@ public static ItemStack translateToPC(Slot slot) { return item; } - - public static BlockFace translateToPC(int face) - { + + public static BlockFace translateToPC(int face) { return BlockFace.values()[Math.abs(face % 6)]; } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java index b41363a57..92ab865fb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCAnimationPacketTranslator.java @@ -20,27 +20,21 @@ import org.dragonet.proxy.protocol.packets.AnimatePacket; public class PCAnimationPacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCAnimationPacketTranslator() { + public PCAnimationPacketTranslator() { - } + } - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityAnimationPacket packet) { - - CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (entity == null) { - return null; - } - AnimatePacket pk = new AnimatePacket(); - pk.action = packet.getAnimation().ordinal(); - pk.eid = entity.proxyEid; - System.out.println(packet.getAnimation().name()); - return new PEPacket[] { pk }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerEntityAnimationPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + return null; + } + AnimatePacket pk = new AnimatePacket(); + pk.action = packet.getAnimation().ordinal(); + pk.eid = entity.proxyEid; + System.out.println(packet.getAnimation().name()); + return new PEPacket[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java index 73d07d91c..a0c5a3265 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityMetadataPacketTranslator.java @@ -17,6 +17,7 @@ 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.network.CacheKey; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.network.translator.EntityMetaTranslator; @@ -35,35 +36,33 @@ public PCEntityMetadataPacketTranslator() { public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) { CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); -// System.out.println("ServerEntityMetadataPacket entity " + packet.getEntityId() + " update "); - if (entity == null) - { + 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(); + } else { + return null; + } return null; } entity.pcMeta = packet.getMetadata(); - if (entity.spawned) - { + if (entity.spawned) { SetEntityDataPacket pk = new SetEntityDataPacket(); pk.rtid = entity.proxyEid; pk.meta = EntityMetaTranslator.translateToPE(packet.getMetadata(), entity.peType); session.sendPacket(pk); - } - else - { - if (entity.peType == EntityType.ITEM) - { + } else { + if (entity.peType == EntityType.ITEM) { AddItemEntityPacket pk = new AddItemEntityPacket(); pk.rtid = entity.proxyEid; pk.eid = entity.proxyEid; pk.metadata = EntityMetaTranslator.translateToPE(packet.getMetadata(), entity.peType); - pk.item = ((SlotMeta)pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; + pk.item = ((SlotMeta) pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); entity.spawned = true; session.sendPacket(pk); - } - else - { + } else { AddEntityPacket pk = new AddEntityPacket(); pk.rtid = entity.proxyEid; pk.eid = entity.proxyEid; diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java index 024595d82..6c963bb30 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityPositionPacketTranslator.java @@ -22,34 +22,28 @@ import org.dragonet.proxy.utilities.Vector3F; public class PCEntityPositionPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityPositionPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityPositionPacket packet) { - CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (e == null) { - return null; - } - - e.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()); - - 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 + public PCEntityPositionPacketTranslator() { + + } + + public PEPacket[] translate(UpstreamSession session, ServerEntityPositionPacket packet) { + CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (e == null) { + return null; + } + + e.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()); + + 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/PCEntityRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java index be10a6367..58e96a2cf 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityRotationPacketTranslator.java @@ -22,34 +22,28 @@ import org.dragonet.proxy.utilities.Vector3F; public class PCEntityRotationPacketTranslator implements IPCPacketTranslator { - // vars - - // constructor - public PCEntityRotationPacketTranslator() { - - } - - // public - public PEPacket[] translate(UpstreamSession session, ServerEntityRotationPacket packet) { - CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); - if (e == null) { - return null; - } - - e.relativeMove(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 + public PCEntityRotationPacketTranslator() { + + } + + public PEPacket[] translate(UpstreamSession session, ServerEntityRotationPacket packet) { + CachedEntity e = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (e == null) { + return null; + } + + e.relativeMove(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/PCPlayerListItemPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java index 43f564404..1cedd96c4 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerListItemPacketTranslator.java @@ -24,50 +24,45 @@ import org.dragonet.proxy.protocol.type.Skin; public class PCPlayerListItemPacketTranslator implements IPCPacketTranslator { - // vars - // constructor - public PCPlayerListItemPacketTranslator() { + public PCPlayerListItemPacketTranslator() { - } + } - // public - public PEPacket[] translate(UpstreamSession session, ServerPlayerListEntryPacket packet) { - PlayerListPacket pk = new PlayerListPacket(); - if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) { - PlayerListEntry[] entries = packet.getEntries(); - Set peEntries = new HashSet(); - for (PlayerListEntry entry : entries) { - session.getPlayerInfoCache().put(entry.getProfile().getId(), entry); - org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); - peEntry.uuid = entry.getProfile().getId(); - peEntry.eid = 1; - peEntry.username = entry.getProfile().getName(); - peEntry.skin = Skin.DEFAULT_SKIN; - peEntry.xboxUserId = entry.getProfile().getId().toString(); - peEntries.add(peEntry); - } - pk.type = PlayerListPacket.TYPE_ADD; - pk.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[])peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); - } else if (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER) { - PlayerListEntry[] entries = packet.getEntries(); - Set peEntries = new HashSet(); - for (PlayerListEntry entry : entries) { - session.getPlayerInfoCache().remove(entry.getProfile().getId()); - org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); - peEntry.uuid = entry.getProfile().getId(); - peEntry.eid = 1; - peEntry.username = entry.getProfile().getName(); - peEntry.skin = Skin.DEFAULT_SKIN; - peEntry.xboxUserId = entry.getProfile().getId().toString(); - peEntries.add(peEntry); - } - pk.type = PlayerListPacket.TYPE_REMOVE; - pk.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[])peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); - } - return new PEPacket[] { pk }; - } - - // private + public PEPacket[] translate(UpstreamSession session, ServerPlayerListEntryPacket packet) { + PlayerListPacket pk = new PlayerListPacket(); + if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) { + PlayerListEntry[] entries = packet.getEntries(); + Set peEntries = new HashSet(); + for (PlayerListEntry entry : entries) { + session.getPlayerInfoCache().put(entry.getProfile().getId(), entry); + org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); + peEntry.uuid = entry.getProfile().getId(); + peEntry.eid = 1; + peEntry.username = entry.getProfile().getName(); + peEntry.skin = Skin.DEFAULT_SKIN; + peEntry.xboxUserId = entry.getProfile().getId().toString(); + peEntries.add(peEntry); + } + pk.type = PlayerListPacket.TYPE_ADD; + pk.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); + } else if (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER) { + PlayerListEntry[] entries = packet.getEntries(); + Set peEntries = new HashSet(); + for (PlayerListEntry entry : entries) { + session.getPlayerInfoCache().remove(entry.getProfile().getId()); + org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); + peEntry.uuid = entry.getProfile().getId(); + peEntry.eid = 1; + peEntry.username = entry.getProfile().getName(); + peEntry.skin = Skin.DEFAULT_SKIN; + peEntry.xboxUserId = entry.getProfile().getId().toString(); + peEntries.add(peEntry); + } + pk.type = PlayerListPacket.TYPE_REMOVE; + pk.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); + } + return new PEPacket[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java index de191611b..913c784eb 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCPlayerPositionRotationPacketTranslator.java @@ -50,77 +50,77 @@ import org.dragonet.proxy.utilities.Vector3F; public class PCPlayerPositionRotationPacketTranslator - implements IPCPacketTranslator { - // vars + implements IPCPacketTranslator { + // vars - // constructor - public PCPlayerPositionRotationPacketTranslator() { + // constructor + public PCPlayerPositionRotationPacketTranslator() { - } + } - // public - public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotationPacket packet) { - if (!session.isSpawned()) { - System.out.println("SPAWNED! "); - if (session.getDataCache().get(CacheKey.PACKET_JOIN_GAME_PACKET) == null) { - session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_REMOTE_ERROR)); - return null; - } + // public + public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotationPacket packet) { + if (!session.isSpawned()) { + System.out.println("SPAWNED! "); + if (session.getDataCache().get(CacheKey.PACKET_JOIN_GAME_PACKET) == null) { + session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_REMOTE_ERROR)); + return null; + } - ServerJoinGamePacket restored = (ServerJoinGamePacket) session.getDataCache() - .remove(CacheKey.PACKET_JOIN_GAME_PACKET); - if (!session.getProxy().getAuthMode().equalsIgnoreCase("online")) { - StartGamePacket ret = new StartGamePacket(); - ret.rtid = 1L; - ret.eid = 1L; - ret.dimension = restored.getDimension(); - ret.seed = 0; - ret.generator = 1; - ret.gamemode = restored.getGameMode() == GameMode.CREATIVE ? 1 : 0; - ret.spawnPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ()); - ret.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, - (float) packet.getZ()); - ret.yaw = packet.getYaw(); - ret.pitch = packet.getPitch(); - ret.levelId = ""; - ret.worldName = "World"; - ret.commandsEnabled = true; - ret.defaultPlayerPermission = 2; - ret.premiumWorldTemplateId = ""; - session.sendPacket(ret); - } - - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("DragonProxy"); - ClientPluginMessagePacket ClientPluginMessagePacket = new ClientPluginMessagePacket("MC|Brand" , out.toByteArray()); - ((PCDownstreamSession) session.getDownstream()).send(ClientPluginMessagePacket); + ServerJoinGamePacket restored = (ServerJoinGamePacket) session.getDataCache() + .remove(CacheKey.PACKET_JOIN_GAME_PACKET); + if (!session.getProxy().getAuthMode().equalsIgnoreCase("online")) { + StartGamePacket ret = new StartGamePacket(); + ret.rtid = 1L; + ret.eid = 1L; + ret.dimension = restored.getDimension(); + ret.seed = 0; + ret.generator = 1; + ret.gamemode = restored.getGameMode() == GameMode.CREATIVE ? 1 : 0; + ret.spawnPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ()); + ret.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, + (float) packet.getZ()); + ret.yaw = packet.getYaw(); + ret.pitch = packet.getPitch(); + ret.levelId = ""; + ret.worldName = "World"; + ret.commandsEnabled = true; + ret.defaultPlayerPermission = 2; + ret.premiumWorldTemplateId = ""; + session.sendPacket(ret); + } + + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("DragonProxy"); + ClientPluginMessagePacket ClientPluginMessagePacket = new ClientPluginMessagePacket("MC|Brand", out.toByteArray()); + ((PCDownstreamSession) session.getDownstream()).send(ClientPluginMessagePacket); - LoginPacket loginpacket = (LoginPacket) session.getDataCache().remove(CacheKey.PACKET_LOGIN_PACKET); - ClientSettingsPacket ClientSettingsPacket = new ClientSettingsPacket(loginpacket.decoded.language, 8, ChatVisibility.FULL, false, new SkinPart[]{}, Hand.MAIN_HAND); - ((PCDownstreamSession) session.getDownstream()).send(ClientSettingsPacket); + LoginPacket loginpacket = (LoginPacket) session.getDataCache().remove(CacheKey.PACKET_LOGIN_PACKET); + ClientSettingsPacket ClientSettingsPacket = new ClientSettingsPacket(loginpacket.decoded.language, 8, ChatVisibility.FULL, false, new SkinPart[]{}, Hand.MAIN_HAND); + ((PCDownstreamSession) session.getDownstream()).send(ClientSettingsPacket); - UpdateAttributesPacket attr = new UpdateAttributesPacket(); - attr.rtid = 1L; - attr.entries = new PEEntityAttribute[] { PEEntityAttribute.findAttribute(PEEntityAttribute.ABSORPTION), - PEEntityAttribute.findAttribute(PEEntityAttribute.EXHAUSTION), - PEEntityAttribute.findAttribute(PEEntityAttribute.HUNGER), - PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL), - PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE), - PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL), - PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED), }; - session.sendPacket(attr); + UpdateAttributesPacket attr = new UpdateAttributesPacket(); + attr.rtid = 1L; + attr.entries = new PEEntityAttribute[]{PEEntityAttribute.findAttribute(PEEntityAttribute.ABSORPTION), + PEEntityAttribute.findAttribute(PEEntityAttribute.EXHAUSTION), + PEEntityAttribute.findAttribute(PEEntityAttribute.HUNGER), + PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL), + PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE), + PEEntityAttribute.findAttribute(PEEntityAttribute.EXPERIENCE_LEVEL), + PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED),}; + session.sendPacket(attr); - AdventureSettingsPacket adv = new AdventureSettingsPacket(); - //flags - adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.ADVENTURE)); + AdventureSettingsPacket adv = new AdventureSettingsPacket(); + //flags + adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.ADVENTURE)); // adv.setFlag(AdventureSettingsPacket.NO_PVP, true); // adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true); - adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, restored.getGameMode().equals(GameMode.CREATIVE) || restored.getGameMode().equals(GameMode.SPECTATOR)); - adv.setFlag(AdventureSettingsPacket.NO_CLIP, restored.getGameMode().equals(GameMode.SPECTATOR)); - adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !restored.getGameMode().equals(GameMode.SPECTATOR) || !restored.getGameMode().equals(GameMode.ADVENTURE)); - adv.setFlag(AdventureSettingsPacket.FLYING, false); - adv.setFlag(AdventureSettingsPacket.MUTED, false); - //custom permission flags (not necessary for now when using LEVEL_PERMISSION setting) + adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, restored.getGameMode().equals(GameMode.CREATIVE) || restored.getGameMode().equals(GameMode.SPECTATOR)); + adv.setFlag(AdventureSettingsPacket.NO_CLIP, restored.getGameMode().equals(GameMode.SPECTATOR)); + adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !restored.getGameMode().equals(GameMode.SPECTATOR) || !restored.getGameMode().equals(GameMode.ADVENTURE)); + adv.setFlag(AdventureSettingsPacket.FLYING, false); + adv.setFlag(AdventureSettingsPacket.MUTED, false); + //custom permission flags (not necessary for now when using LEVEL_PERMISSION setting) // adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true); // adv.setFlag(AdventureSettingsPacket.DOORS_AND_SWITCHES, true); // adv.setFlag(AdventureSettingsPacket.OPEN_CONTAINERS, true); @@ -128,150 +128,146 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotatio // adv.setFlag(AdventureSettingsPacket.ATTACK_MOBS, true); // adv.setFlag(AdventureSettingsPacket.OPERATOR, true); // adv.setFlag(AdventureSettingsPacket.TELEPORT, true); - adv.eid = 1L; - adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL; //TODO update this with server configiration - adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER; //TODO update this with server configiration - session.sendPacket(adv); + adv.eid = 1L; + adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL; //TODO update this with server configiration + adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER; //TODO update this with server configiration + session.sendPacket(adv); - SetEntityDataPacket entityData = new SetEntityDataPacket(); - entityData.rtid = 1L; - entityData.meta = EntityMetaData.createDefault(); - session.sendPacket(entityData); + SetEntityDataPacket entityData = new SetEntityDataPacket(); + entityData.rtid = 1L; + entityData.meta = EntityMetaData.createDefault(); + session.sendPacket(entityData); - if (session.getProxy().getAuthMode().equalsIgnoreCase("online")) { - MovePlayerPacket pk = new MovePlayerPacket(); - pk.rtid = 1L; - pk.mode = MovePlayerPacket.MODE_TELEPORT; - pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, - (float) packet.getZ()); - pk.yaw = packet.getYaw(); - pk.pitch = packet.getPitch(); - pk.headYaw = packet.getYaw(); - session.sendPacket(pk); + if (session.getProxy().getAuthMode().equalsIgnoreCase("online")) { + MovePlayerPacket pk = new MovePlayerPacket(); + pk.rtid = 1L; + pk.mode = MovePlayerPacket.MODE_TELEPORT; + pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, + (float) packet.getZ()); + pk.yaw = packet.getYaw(); + pk.pitch = packet.getPitch(); + pk.headYaw = packet.getYaw(); + session.sendPacket(pk); - CachedEntity cliEntity = session.getEntityCache().getClientEntity(); - cliEntity.x = packet.getX(); - cliEntity.y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; - cliEntity.z = packet.getZ(); - cliEntity.yaw = packet.getYaw(); - cliEntity.pitch = packet.getPitch(); + CachedEntity cliEntity = session.getEntityCache().getClientEntity(); + cliEntity.x = packet.getX(); + cliEntity.y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; + cliEntity.z = packet.getZ(); + cliEntity.yaw = packet.getYaw(); + cliEntity.pitch = packet.getPitch(); - /*ChangeDimensionPacket d = new ChangeDimensionPacket(); + /*ChangeDimensionPacket d = new ChangeDimensionPacket(); d.dimension = 0; d.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, (float) packet.getZ()); session.sendPacket(d); session.sendPacket(new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN));*/ + System.out.println("spawning at " + pk.position.toString()); + } + + session.setSpawned(); - System.out.println("spawning at " + pk.position.toString()); - } + session.getEntityCache().getClientEntity().x = packet.getX(); + session.getEntityCache().getClientEntity().y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; + session.getEntityCache().getClientEntity().z = packet.getZ(); - session.setSpawned(); + // send the confirmation + ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId()); + ((PCDownstreamSession) session.getDownstream()).send(confirm); - session.getEntityCache().getClientEntity().x = packet.getX(); - session.getEntityCache().getClientEntity().y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; - session.getEntityCache().getClientEntity().z = packet.getZ(); + PlayerListPacket playerListPacket = new PlayerListPacket(); + Set peEntries = new HashSet(); - // send the confirmation - ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId()); - ((PCDownstreamSession) session.getDownstream()).send(confirm); - - PlayerListPacket playerListPacket = new PlayerListPacket(); - Set peEntries = new HashSet(); - - for(CachedEntity entity : session.getEntityCache().getEntities().values()) - { - if (entity.eid == 1L) //never send ME (entry 1L) - continue; - if (entity.player && entity.playerUniqueId != null) //PLAYER - { - PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId); - AddPlayerPacket pkAddPlayer = new AddPlayerPacket(); - pkAddPlayer.eid = entity.proxyEid; - pkAddPlayer.rtid = entity.proxyEid; + for (CachedEntity entity : session.getEntityCache().getEntities().values()) { + if (entity.eid == 1L) //never send ME (entry 1L) + { + continue; + } + if (entity.player && entity.playerUniqueId != null) //PLAYER + { + PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId); + AddPlayerPacket pkAddPlayer = new AddPlayerPacket(); + pkAddPlayer.eid = entity.proxyEid; + pkAddPlayer.rtid = entity.proxyEid; - pkAddPlayer.uuid = entity.playerUniqueId; + pkAddPlayer.uuid = entity.playerUniqueId; - pkAddPlayer.position = new Vector3F((float) entity.x, (float) entity.y + Constants.PLAYER_HEAD_OFFSET, (float) entity.z); - pkAddPlayer.motion = Vector3F.ZERO; - pkAddPlayer.yaw = entity.yaw; - pkAddPlayer.pitch = entity.pitch; - pkAddPlayer.username = playerListEntry.getProfile().getName(); - - pkAddPlayer.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, EntityType.PLAYER); - pkAddPlayer.meta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta(playerListEntry.getProfile().getName())); //hacky for now + pkAddPlayer.position = new Vector3F((float) entity.x, (float) entity.y + Constants.PLAYER_HEAD_OFFSET, (float) entity.z); + pkAddPlayer.motion = Vector3F.ZERO; + pkAddPlayer.yaw = entity.yaw; + pkAddPlayer.pitch = entity.pitch; + pkAddPlayer.username = playerListEntry.getProfile().getName(); - PlayerSkinPacket skin = new PlayerSkinPacket(entity.playerUniqueId); - - org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); - peEntry.uuid = entity.playerUniqueId; - peEntry.eid = entity.eid; - peEntry.username = playerListEntry.getProfile().getName(); - peEntry.skin = Skin.DEFAULT_SKIN; - peEntry.xboxUserId = "null"; - peEntries.add(peEntry); + pkAddPlayer.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, EntityType.PLAYER); + pkAddPlayer.meta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta(playerListEntry.getProfile().getName())); //hacky for now - session.sendPacket(pkAddPlayer); - session.sendPacket(skin); - } - else if (entity.peType != null) //ENTITY - { - AddEntityPacket pk = new AddEntityPacket(); - pk.rtid = entity.proxyEid; - pk.eid = entity.proxyEid; - pk.type = entity.peType.getPeType(); - pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); - pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); - pk.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); - // TODO: Hack for now. ;P - pk.attributes = new PEEntityAttribute[]{}; - session.sendPacket(pk); - } - else // ITEM - { - AddItemEntityPacket pk = new AddItemEntityPacket(); - pk.rtid = entity.proxyEid; - pk.eid = entity.proxyEid; - pk.metadata = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); - pk.item = ((SlotMeta)pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; - pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); - pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); - entity.spawned = true; - session.sendPacket(pk); - } - } - - playerListPacket.type = PlayerListPacket.TYPE_ADD; - playerListPacket.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[])peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); - session.sendPacket(playerListPacket); - return null; - } + PlayerSkinPacket skin = new PlayerSkinPacket(entity.playerUniqueId); - MovePlayerPacket pk = new MovePlayerPacket(); - pk.rtid = 1L; - pk.mode = MovePlayerPacket.MODE_TELEPORT; - pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, - (float) packet.getZ()); - pk.yaw = packet.getYaw(); - pk.pitch = packet.getPitch(); - pk.headYaw = packet.getYaw(); - CachedEntity cliEntity = session.getEntityCache().getClientEntity(); - cliEntity.x = packet.getX(); - cliEntity.y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; - cliEntity.z = packet.getZ(); - cliEntity.yaw = packet.getYaw(); - cliEntity.pitch = packet.getPitch(); + org.dragonet.proxy.protocol.type.PlayerListEntry peEntry = new org.dragonet.proxy.protocol.type.PlayerListEntry(); + peEntry.uuid = entity.playerUniqueId; + peEntry.eid = entity.eid; + peEntry.username = playerListEntry.getProfile().getName(); + peEntry.skin = Skin.DEFAULT_SKIN; + peEntry.xboxUserId = "null"; + peEntries.add(peEntry); + + session.sendPacket(pkAddPlayer); + session.sendPacket(skin); + } else if (entity.peType != null) //ENTITY + { + AddEntityPacket pk = new AddEntityPacket(); + pk.rtid = entity.proxyEid; + pk.eid = entity.proxyEid; + pk.type = entity.peType.getPeType(); + pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); + pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); + pk.meta = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); + // TODO: Hack for now. ;P + pk.attributes = new PEEntityAttribute[]{}; + session.sendPacket(pk); + } else // ITEM + { + AddItemEntityPacket pk = new AddItemEntityPacket(); + pk.rtid = entity.proxyEid; + pk.eid = entity.proxyEid; + pk.metadata = EntityMetaTranslator.translateToPE(entity.pcMeta, entity.peType); + pk.item = ((SlotMeta) pk.metadata.map.get(EntityMetaData.Constants.DATA_TYPE_SLOT)).slot; + pk.position = new Vector3F((float) entity.x, (float) entity.y, (float) entity.z); + pk.motion = new Vector3F((float) entity.motionX, (float) entity.motionY, (float) entity.motionZ); + entity.spawned = true; + session.sendPacket(pk); + } + } - // session.sendChat(String.format("FORCING TO (%.2f, %.2f, %.2f", packet.getX(), - // packet.getY(), packet.getZ())); + playerListPacket.type = PlayerListPacket.TYPE_ADD; + playerListPacket.entries = (org.dragonet.proxy.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.proxy.protocol.type.PlayerListEntry[peEntries.size()]); + session.sendPacket(playerListPacket); + return null; + } - // send the confirmation - ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId()); - ((PCDownstreamSession) session.getDownstream()).send(confirm); + MovePlayerPacket pk = new MovePlayerPacket(); + pk.rtid = 1L; + pk.mode = MovePlayerPacket.MODE_TELEPORT; + pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + Constants.PLAYER_HEAD_OFFSET, + (float) packet.getZ()); + pk.yaw = packet.getYaw(); + pk.pitch = packet.getPitch(); + pk.headYaw = packet.getYaw(); + CachedEntity cliEntity = session.getEntityCache().getClientEntity(); + cliEntity.x = packet.getX(); + cliEntity.y = packet.getY() + Constants.PLAYER_HEAD_OFFSET; + cliEntity.z = packet.getZ(); + cliEntity.yaw = packet.getYaw(); + cliEntity.pitch = packet.getPitch(); - return new PEPacket[] { pk }; - } + // 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); - // private + return new PEPacket[]{pk}; + } + // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java index 2444503d0..7f027bdfe 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pc/PCSoundEventPacketTranslator.java @@ -20,20 +20,16 @@ import org.dragonet.proxy.utilities.Vector3F; public class PCSoundEventPacketTranslator implements IPCPacketTranslator { - // vars - // constructor public PCSoundEventPacketTranslator() { } - // public public PEPacket[] translate(UpstreamSession session, ServerPlayBuiltinSoundPacket packet) { LevelSoundEventPacket pk = new LevelSoundEventPacket(); - pk.position = new Vector3F((float)packet.getX(), (float)packet.getY(), (float)packet.getZ()); - pk.pitch = (int)packet.getPitch(); - switch(packet.getSound()) - { + pk.position = new Vector3F((float) packet.getX(), (float) packet.getY(), (float) packet.getZ()); + pk.pitch = (int) packet.getPitch(); + switch (packet.getSound()) { case BLOCK_GRASS_BREAK: pk.sound = LevelSoundEventPacket.SOUND_BREAK; break; @@ -59,6 +55,4 @@ public PEPacket[] translate(UpstreamSession session, ServerPlayBuiltinSoundPacke pk.offset = 0; return new PEPacket[]{pk}; } - - // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java index 41c1d1d0c..668f6a170 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEAdventureSettingsPacketTranslator.java @@ -19,19 +19,14 @@ import org.dragonet.proxy.utilities.DebugTools; public class PEAdventureSettingsPacketTranslator implements IPEPacketTranslator { - // vars - // constructor public PEAdventureSettingsPacketTranslator() { } - // public public Packet[] translate(UpstreamSession session, AdventureSettingsPacket packet) { System.out.println(DebugTools.getAllFields(packet)); - + return null; } - - // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java index 742913c99..bdc01402f 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java @@ -21,14 +21,11 @@ import org.dragonet.proxy.protocol.packets.InteractPacket; public class PEInteractPacketTranslator implements IPEPacketTranslator { - // vars - // constructor public PEInteractPacketTranslator() { } - // public public Packet[] translate(UpstreamSession session, InteractPacket packet) { CachedEntity e = session.getEntityCache().getByLocalEID(packet.targetRtid); if (e == null) { @@ -46,6 +43,4 @@ public Packet[] translate(UpstreamSession session, InteractPacket packet) { return null; } - - // private } diff --git a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java index e02c58fca..ae0ef78ff 100644 --- a/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java +++ b/proxy/src/main/java/org/dragonet/proxy/network/translator/pe/PEMovePlayerPacketTranslator.java @@ -21,27 +21,19 @@ import org.dragonet.proxy.utilities.Constants; public class PEMovePlayerPacketTranslator implements IPEPacketTranslator { - // vars - // constructor - public PEMovePlayerPacketTranslator() { + public PEMovePlayerPacketTranslator() { - } - - // public - 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, - packet.pitch); - CachedEntity cliEntity = session.getEntityCache().getClientEntity(); - // session.sendChat(String.format("moving to (%.2f, %.2f, %.2f)", packet.position.x, - // packet.position.y - Constants.PLAYER_HEAD_OFFSET, packet.position.z)); - cliEntity.x = packet.position.x; - cliEntity.y = packet.position.y - Constants.PLAYER_HEAD_OFFSET; - cliEntity.z = packet.position.z; - return new Packet[] { pk }; - } - - // private + } + 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, + packet.pitch); + CachedEntity cliEntity = session.getEntityCache().getClientEntity(); + cliEntity.x = packet.position.x; + cliEntity.y = packet.position.y - Constants.PLAYER_HEAD_OFFSET; + cliEntity.z = packet.position.z; + return new Packet[]{pk}; + } } diff --git a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java index 530fd8fb5..d046adffe 100644 --- a/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java +++ b/proxy/src/main/java/org/dragonet/proxy/protocol/packets/AnimatePacket.java @@ -4,8 +4,7 @@ import org.dragonet.proxy.protocol.ProtocolInfo; public class AnimatePacket extends PEPacket { - //vars - + public static int ANIMATION_SWING_ARM = 1; public static int ACTION_LEFT_CLICK = 2; public static int ANIMATION_LEAVE_BED = 3; @@ -15,12 +14,10 @@ public class AnimatePacket extends PEPacket { public long eid; public float unknown; - //constructor public AnimatePacket() { } - //public public int pid() { return ProtocolInfo.ANIMATE_PACKET; } @@ -42,6 +39,4 @@ public void encodePayload() { this.putLFloat(this.unknown); } } - - //private } diff --git a/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java b/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java index 7d27fee7a..e7ee3e7ea 100644 --- a/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java +++ b/proxy/src/main/java/org/dragonet/proxy/utilities/LoginChainDecoder.java @@ -15,76 +15,80 @@ * Created on 2017/9/12. */ public class LoginChainDecoder { - // vars - private final byte[] chainJWT; - private final byte[] clientDataJWT; - public String username; - public UUID clientUniqueId; - public JsonObject clientData; - public String language; - public Skin skin; + // vars - // constructor - public LoginChainDecoder(byte[] chainJWT, byte[] clientDataJWT) { - this.chainJWT = chainJWT; - this.clientDataJWT = clientDataJWT; - } + private final byte[] chainJWT; + private final byte[] clientDataJWT; + public String username; + public UUID clientUniqueId; + public JsonObject clientData; + public String language; + public Skin skin; - // public - /** - * decode the chain data in Login packet for MCPE Note: the credit of this - * function goes to Nukkit development team - */ - public void decode() { - // chain - Map> map = new Gson().fromJson(new String(chainJWT), - new TypeToken>>() { - }.getType()); - if (map.isEmpty() || !map.containsKey("chain") || map.get("chain").isEmpty()) - return; - List chains = map.get("chain"); - for (String c : chains) { - JsonObject chainMap = decodeToken(c); - if (chainMap == null) - continue; - if (chainMap.has("extraData")) { - JsonObject extra = chainMap.get("extraData").getAsJsonObject(); - if (extra.has("displayName")) - this.username = extra.get("displayName").getAsString(); - if (extra.has("identity")) - this.clientUniqueId = UUID.fromString(extra.get("identity").getAsString()); - } - } + // constructor + public LoginChainDecoder(byte[] chainJWT, byte[] clientDataJWT) { + this.chainJWT = chainJWT; + this.clientDataJWT = clientDataJWT; + } - // client data - clientData = decodeToken(new String(clientDataJWT, StandardCharsets.UTF_8)); - - language = clientData.has("LanguageCode") ? clientData.get("LanguageCode").getAsString() : "en_US"; + // public + /** + * decode the chain data in Login packet for MCPE Note: the credit of this + * function goes to Nukkit development team + */ + public void decode() { + // chain + Map> map = new Gson().fromJson(new String(chainJWT), + new TypeToken>>() { + }.getType()); + if (map.isEmpty() || !map.containsKey("chain") || map.get("chain").isEmpty()) { + return; + } + List chains = map.get("chain"); + for (String c : chains) { + JsonObject chainMap = decodeToken(c); + if (chainMap == null) { + continue; + } + if (chainMap.has("extraData")) { + JsonObject extra = chainMap.get("extraData").getAsJsonObject(); + if (extra.has("displayName")) { + this.username = extra.get("displayName").getAsString(); + } + if (extra.has("identity")) { + this.clientUniqueId = UUID.fromString(extra.get("identity").getAsString()); + } + } + } - skin = new Skin( - clientData.get("SkinId").getAsString(), - clientData.has("SkinData") ? Base64.getDecoder().decode(clientData.get("SkinData").getAsString().replace("-_", "+/")) : new byte[0], - clientData.has("CapeData") ? Base64.getDecoder().decode(clientData.get("CapeData").getAsString().replace("-_", "+/")) : new byte[0], - clientData.get("SkinGeometryName").getAsString(), - clientData.has("SkinGeometry") ? Base64.getDecoder().decode(clientData.get("SkinGeometry").getAsString().replace("-_", "+/")) : new byte[0] + // client data + clientData = decodeToken(new String(clientDataJWT, StandardCharsets.UTF_8)); + language = clientData.has("LanguageCode") ? clientData.get("LanguageCode").getAsString() : "en_US"; - ); - } + skin = new Skin( + clientData.get("SkinId").getAsString(), + clientData.has("SkinData") ? Base64.getDecoder().decode(clientData.get("SkinData").getAsString().replace("-_", "+/")) : new byte[0], + clientData.has("CapeData") ? Base64.getDecoder().decode(clientData.get("CapeData").getAsString().replace("-_", "+/")) : new byte[0], + clientData.get("SkinGeometryName").getAsString(), + clientData.has("SkinGeometry") ? Base64.getDecoder().decode(clientData.get("SkinGeometry").getAsString().replace("-_", "+/")) : new byte[0] + ); + } - // private - /** - * Note: the credit of this function goes to Nukkit development team - * - * @param token - * @return - */ - private JsonObject decodeToken(String token) { - String[] base = token.split("\\."); - if (base.length < 2) - return null; - return new Gson().fromJson( - new String(Base64.getDecoder().decode(base[1].replace("-_", "+/")), StandardCharsets.UTF_8), - JsonObject.class); - } + // private + /** + * Note: the credit of this function goes to Nukkit development team + * + * @param token + * @return + */ + private JsonObject decodeToken(String token) { + String[] base = token.split("\\."); + if (base.length < 2) { + return null; + } + return new Gson().fromJson( + new String(Base64.getDecoder().decode(base[1].replace("-_", "+/")), StandardCharsets.UTF_8), + JsonObject.class); + } } From 0c74358c913d5ba910bf86a09aa95eb3ceb16259 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 17:25:13 +0100 Subject: [PATCH 53/60] 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 From 384e744810287b3e7888f195c55360f622d5b350 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 21:54:23 +0100 Subject: [PATCH 54/60] Add ridering cache to CachedEntity --- .../proxy/network/cache/CachedEntity.java | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java index f0488ea5f..e1e6acd36 100644 --- a/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java +++ b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java @@ -23,65 +23,65 @@ import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; public class CachedEntity { - // vars - public final long eid; - public final long proxyEid; - public final int pcType; - public final EntityType peType; - public final ObjectType objType; - public final boolean player; - public final UUID playerUniqueId; + public final long eid; + public final long proxyEid; + public final int pcType; + public final EntityType peType; + public final ObjectType objType; - public double x; - public double y; - public double z; - public double motionX; - public double motionY; - public double motionZ; - public float yaw; - public float pitch; + public final boolean player; + public final UUID playerUniqueId; - public EntityMetadata[] pcMeta; - public boolean spawned; - public final Set effects = Collections.synchronizedSet(new HashSet()); + public double x; + public double y; + public double z; + public double motionX; + public double motionY; + public double motionZ; + public float yaw; + public float pitch; - // constructor - public CachedEntity(long eid, long proxyEid, int pcType, EntityType peType, ObjectType objType, boolean player, - UUID playerUniqueId) { - super(); + // cache riding datas for dismount + public long riding; + public Set passengers = new HashSet(); - this.eid = eid; - this.proxyEid = proxyEid; - this.pcType = pcType; - this.peType = peType; - this.objType = objType; - this.player = player; - this.playerUniqueId = playerUniqueId; - } + public EntityMetadata[] pcMeta; + public boolean spawned; + public final Set effects = Collections.synchronizedSet(new HashSet()); - // public - public CachedEntity relativeMove(double rx, double ry, double rz, float yaw, float pitch) { - x += rx; - y += ry; - z += rz; - this.yaw = yaw; - this.pitch = pitch; - return this; - } + public CachedEntity(long eid, long proxyEid, int pcType, EntityType peType, ObjectType objType, boolean player, + UUID playerUniqueId) { + super(); - public CachedEntity relativeMove(double rx, double ry, double rz) { - x += rx; - y += ry; - z += rz; - return this; - } - public CachedEntity relativeMove(float yaw, float pitch) { - this.yaw = yaw; - this.pitch = pitch; - return this; - } + this.eid = eid; + this.proxyEid = proxyEid; + this.pcType = pcType; + this.peType = peType; + this.objType = objType; + this.player = player; + this.playerUniqueId = playerUniqueId; + } - // private + public CachedEntity relativeMove(double rx, double ry, double rz, float yaw, float pitch) { + x += rx; + y += ry; + z += rz; + this.yaw = yaw; + this.pitch = pitch; + return this; + } + public CachedEntity relativeMove(double rx, double ry, double rz) { + x += rx; + y += ry; + z += rz; + return this; + } + + public CachedEntity relativeMove(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; + return this; + } } From b917e78089f91a389ae64206779190db83dc5a88 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:01:58 +0100 Subject: [PATCH 55/60] Add player input packet & translator --- .../pc/PCVehicleMovePacketTranslator.java | 31 ++++++++++++++++++ .../pe/PEPlayerInputPacketTranslator.java | 29 +++++++++++++++++ .../org/dragonet/proxy/protocol/Protocol.java | 1 + .../protocol/packets/PlayerInputPacket.java | 32 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pc/PCVehicleMovePacketTranslator.java create mode 100644 src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java create mode 100644 src/main/java/org/dragonet/proxy/protocol/packets/PlayerInputPacket.java diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCVehicleMovePacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCVehicleMovePacketTranslator.java new file mode 100644 index 000000000..39851726a --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCVehicleMovePacketTranslator.java @@ -0,0 +1,31 @@ +/* + * 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.ServerVehicleMovePacket; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.MoveEntityPacket; +import org.dragonet.proxy.utilities.Constants; +import org.dragonet.proxy.utilities.DebugTools; +import org.dragonet.proxy.utilities.Vector3F; + +public class PCVehicleMovePacketTranslator implements IPCPacketTranslator { + + public PEPacket[] translate(UpstreamSession session, ServerVehicleMovePacket packet) { + System.out.println(DebugTools.getAllFields(packet)); + return new PEPacket[]{}; + } +} diff --git a/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java new file mode 100644 index 000000000..c72983dcc --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java @@ -0,0 +1,29 @@ +/* + * 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.packetlib.packet.Packet; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.translator.IPEPacketTranslator; +import org.dragonet.proxy.protocol.packets.PlayerInputPacket; +import org.dragonet.proxy.utilities.DebugTools; + +public class PEPlayerInputPacketTranslator implements IPEPacketTranslator { + + public Packet[] translate(UpstreamSession session, PlayerInputPacket packet) { +// System.out.println("PlayerInputPacket" + DebugTools.getAllFields(packet)); + + return null; + } + +} diff --git a/src/main/java/org/dragonet/proxy/protocol/Protocol.java b/src/main/java/org/dragonet/proxy/protocol/Protocol.java index 30ba0ffee..ca9ad761e 100644 --- a/src/main/java/org/dragonet/proxy/protocol/Protocol.java +++ b/src/main/java/org/dragonet/proxy/protocol/Protocol.java @@ -69,6 +69,7 @@ public final class Protocol { packets.put(PLAYER_SKIN_PACKET, PlayerSkinPacket.class); packets.put(PLAYER_HOTBAR_PACKET, PlayerHotbarPacket.class); packets.put(SET_ENTITY_LINK_PACKET, SetEntityLinkPacket.class); + packets.put(PLAYER_INPUT_PACKET, PlayerInputPacket.class); packets.put(CONTAINER_OPEN_PACKET, ContainerOpenPacket.class); packets.put(CONTAINER_CLOSE_PACKET, ContainerClosePacket.class); diff --git a/src/main/java/org/dragonet/proxy/protocol/packets/PlayerInputPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerInputPacket.java new file mode 100644 index 000000000..b8512e3a3 --- /dev/null +++ b/src/main/java/org/dragonet/proxy/protocol/packets/PlayerInputPacket.java @@ -0,0 +1,32 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; + +public class PlayerInputPacket extends PEPacket { + + public float motionX; + public float motionY; + + public boolean unknownBool1; + public boolean unknownBool2; + + @Override + public void decodePayload() { + this.motionX = this.getLFloat(); + this.motionY = this.getLFloat(); + this.unknownBool1 = this.getBoolean(); + this.unknownBool2 = this.getBoolean(); + } + + @Override + public void encodePayload() { + + } + + @Override + public int pid() { + return ProtocolInfo.PLAYER_INPUT_PACKET; + } + +} From cbae3853c80a2f85fc2d42ef507308ed74b8abcc Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:16:15 +0100 Subject: [PATCH 56/60] Fix Entity link packet (bad order & dava values) --- .../proxy/protocol/packets/SetEntityLinkPacket.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java index 3b6cc85aa..6faf740e9 100644 --- a/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java +++ b/src/main/java/org/dragonet/proxy/protocol/packets/SetEntityLinkPacket.java @@ -8,12 +8,12 @@ */ public class SetEntityLinkPacket extends PEPacket { - public static final byte TYPE_REMOVE = 0; - public static final byte TYPE_RIDE = 1; - public static final byte TYPE_PASSENGER = 2; + public static final byte TYPE_REMOVE = 3; + public static final byte TYPE_RIDE = 2; + public static final byte TYPE_PASSENGER = 0; - public long rider; public long riding; + public long rider; public byte type; public byte unknownByte; @@ -24,8 +24,8 @@ public void decodePayload() { @Override public void encodePayload() { - this.putEntityUniqueId(this.rider); this.putEntityUniqueId(this.riding); + this.putEntityUniqueId(this.rider); this.putByte(this.type); this.putByte(this.unknownByte); } From 464f89f02c7c544bfeac623faee2b800328912a3 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:20:44 +0100 Subject: [PATCH 57/60] Fix dismout vehicle --- .../network/translator/pe/PEInteractPacketTranslator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java index af5b180cf..423a7c0a3 100644 --- a/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEInteractPacketTranslator.java @@ -13,10 +13,13 @@ package org.dragonet.proxy.network.translator.pe; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; +import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState; import com.github.steveice10.packetlib.packet.Packet; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.translator.IPEPacketTranslator; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket; +import org.dragonet.proxy.network.CacheKey; import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.protocol.packets.InteractPacket; @@ -33,9 +36,12 @@ public Packet[] translate(UpstreamSession session, InteractPacket packet) { return new Packet[]{new ClientPlayerInteractEntityPacket((int) (e.eid), InteractAction.ATTACK)}; case InteractPacket.ACTION_LEFT_CLICK: return new Packet[]{new ClientPlayerInteractEntityPacket((int) (e.eid), InteractAction.INTERACT)}; + case InteractPacket.ACTION_LEAVE_VEHICLE: + return new Packet[]{new ClientPlayerStatePacket( + (int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING)}; } -// System.out.println("InteractPacket type : " + packet.type + " on " + packet.targetRtid); + System.out.println("InteractPacket type : " + packet.type + " on " + packet.targetRtid); return null; } From f3f8f15d3d25b8976842fbd9c3c3582487dc8d6a Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:21:07 +0100 Subject: [PATCH 58/60] Register player input packet translator --- .../org/dragonet/proxy/network/PacketTranslatorRegister.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java index 5f98db89c..1aa43c139 100644 --- a/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -105,6 +105,7 @@ public final class PacketTranslatorRegister { 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()); + PE_TO_PC_TRANSLATOR.put(PlayerInputPacket.class, new PEPlayerInputPacketTranslator()); // Inventory PE_TO_PC_TRANSLATOR.put(ContainerClosePacket.class, new PEWindowClosePacketTranslator()); From d54688013dd5b21ec803aca52a6a96f3da9c165d Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:21:37 +0100 Subject: [PATCH 59/60] Fix mount and dismount --- .../PCEntitySetPassengerPacketTranslator.java | 89 ++++++++++++------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java index 0c87d77e1..d4160279f 100644 --- a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java @@ -13,6 +13,7 @@ package org.dragonet.proxy.network.translator.pc; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntitySetPassengersPacket; +import java.util.Arrays; import org.dragonet.proxy.network.CacheKey; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; @@ -24,46 +25,70 @@ public class PCEntitySetPassengerPacketTranslator implements IPCPacketTranslator { 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)) { - entity = session.getEntityCache().getClientEntity(); - } else { - return null; - } +// for (int id : packet.getPassengerIds()) { +// System.out.println("ServerEntitySetPassengersPacket entity " + packet.getEntityId() + " rider " + id); +// } + + CachedEntity vehicle = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (vehicle == null) { + return null; } - SetEntityLinkPacket pk = new SetEntityLinkPacket(); - pk.rider = entity.proxyEid; + // process not passenger (dismount) + for (long id : vehicle.passengers) { + CachedEntity rider = session.getEntityCache().getByLocalEID(id); - if (packet.getPassengerIds().length == 0) //dismount - { - pk.riding = 0; - pk.type = 0; - pk.unknownByte = 0x00; - session.sendPacket(pk); - } else //mount - { - boolean piloteSet = false; - for (int id : packet.getPassengerIds()) { - CachedEntity riding = session.getEntityCache().getByRemoteEID(id); + if (rider == null) { + continue; + } + if (!Arrays.asList(packet.getPassengerIds()).contains(rider.eid)) { - if (riding == null) { - continue; - } + SetEntityLinkPacket pk = new SetEntityLinkPacket(); + pk.riding = vehicle.proxyEid; + pk.rider = rider.proxyEid; + pk.type = SetEntityLinkPacket.TYPE_REMOVE; + pk.unknownByte = 0x00; + session.sendPacket(pk); + + rider.riding = 0; + System.out.println("DISMOUNT\n" + DebugTools.getAllFields(pk)); + } + } - pk.riding = riding.proxyEid; + //clean cache + vehicle.passengers.clear(); - if (!piloteSet) { - pk.type = 1; - piloteSet = true; - } else { - pk.type = 2; - } + //process mount action + boolean piloteSet = false; + for (int id : packet.getPassengerIds()) { - pk.unknownByte = 0x00; - session.sendPacket(pk); + CachedEntity rider = session.getEntityCache().getByRemoteEID(id); + if (id == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) { + rider = session.getEntityCache().getClientEntity(); + } + + if (rider == null) { + continue; + } + + SetEntityLinkPacket pk = new SetEntityLinkPacket(); + pk.riding = vehicle.proxyEid; + pk.rider = rider.proxyEid; + + if (!piloteSet) { + pk.type = SetEntityLinkPacket.TYPE_RIDE; + piloteSet = true; + } else { + pk.type = SetEntityLinkPacket.TYPE_PASSENGER; } + + pk.unknownByte = 0x00; + session.sendPacket(pk); + + vehicle.passengers.add(rider.proxyEid); + rider.riding = vehicle.proxyEid; + System.out.println("MOUNT\n" + DebugTools.getAllFields(pk)); + } return null; } From 2b117224548cb14d49b94eec8555af3f551b2567 Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:43:06 +0100 Subject: [PATCH 60/60] WIP player input --- .../translator/pe/PEPlayerInputPacketTranslator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java index c72983dcc..804d84cd5 100644 --- a/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pe/PEPlayerInputPacketTranslator.java @@ -12,8 +12,10 @@ */ package org.dragonet.proxy.network.translator.pe; +import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket; import com.github.steveice10.packetlib.packet.Packet; import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedEntity; import org.dragonet.proxy.network.translator.IPEPacketTranslator; import org.dragonet.proxy.protocol.packets.PlayerInputPacket; import org.dragonet.proxy.utilities.DebugTools; @@ -23,6 +25,16 @@ public class PEPlayerInputPacketTranslator implements IPEPacketTranslator