From fffac8a552370179c9ba75b23f0f1f4e47b4dde9 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sat, 25 Jul 2020 22:38:00 +0800 Subject: [PATCH 01/10] Fix Spawn position not using offset. (#1015) --- .../entity/player/JavaPlayerPositionRotationTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 491779121..d5bdabc5f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -62,7 +62,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator Date: Sat, 25 Jul 2020 17:53:44 +0100 Subject: [PATCH 02/10] Fix Wolf anger display (#1021) --- .../entity/living/animal/tameable/WolfEntity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index aa578acb2..ab631ebe5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -59,7 +59,12 @@ public class WolfEntity extends TameableEntity { if (entityMetadata.getId() == 19 && !metadata.getFlags().getFlag(EntityFlag.ANGRY)) { metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } - //TODO: Anger time int? + + // Wolf anger (1.16+) + if (entityMetadata.getId() == 20) { + metadata.getFlags().setFlag(EntityFlag.ANGRY, (int) entityMetadata.getValue() != 0); + } + super.updateBedrockMetadata(entityMetadata, session); } } From af484a425b4eccb125c3e3bf9a965712310b5644 Mon Sep 17 00:00:00 2001 From: Phillipp W <44843453+ChickenPat@users.noreply.github.com> Date: Sat, 25 Jul 2020 19:42:43 +0200 Subject: [PATCH 03/10] SRV resolving / Small Handshake rework (#968) Handshake now uses the server address directly from the config and no longer the IP from a domain (Some servers use the address that is given during the handshake) --- .../sponge/GeyserSpongeConfiguration.java | 10 ++++++ .../geysermc/connector/GeyserConnector.java | 34 ++++++++++++++++--- .../configuration/GeyserConfiguration.java | 4 +++ .../ping/GeyserLegacyPingPassthrough.java | 10 +++--- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 79e7621cc..d56abe090 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -195,11 +195,21 @@ public class GeyserSpongeConfiguration implements GeyserConfiguration { return node.getNode("address").getString("127.0.0.1"); } + @Override + public void setAddress(String address) { + node.getNode("address").setValue(address); + } + @Override public int getPort() { return node.getNode("port").getInt(25565); } + @Override + public void setPort(int port) { + node.getNode("port").setValue(port); + } + @Override public String getAuthType() { return node.getNode("auth-type").getString("online"); diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 89eccda5c..527e1248d 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -32,10 +32,10 @@ import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v407.Bedrock_v407; import lombok.Getter; import lombok.Setter; -import org.geysermc.connector.common.AuthType; -import org.geysermc.connector.common.PlatformType; import org.geysermc.connector.bootstrap.GeyserBootstrap; import org.geysermc.connector.command.CommandManager; +import org.geysermc.connector.common.AuthType; +import org.geysermc.connector.common.PlatformType; import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.network.ConnectorServerEventHandler; @@ -51,17 +51,19 @@ import org.geysermc.connector.network.translators.item.PotionMixRegistry; import org.geysermc.connector.network.translators.sound.SoundHandlerRegistry; import org.geysermc.connector.network.translators.sound.SoundRegistry; import org.geysermc.connector.network.translators.world.WorldManager; -import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator; import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DockerCheck; +import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.LocaleUtils; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.InitialDirContext; import java.net.InetSocketAddress; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; @@ -78,6 +80,8 @@ public class GeyserConnector { public static final String NAME = "Geyser"; public static final String VERSION = "DEV"; // A fallback for running in IDEs + private static final String IP_REGEX = "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b"; + private final List players = new ArrayList<>(); private static GeyserConnector instance; @@ -136,8 +140,28 @@ public class GeyserConnector { if (platformType != PlatformType.STANDALONE) { DockerCheck.check(bootstrap); } + String remoteAddress = config.getRemote().getAddress(); + int remotePort = config.getRemote().getPort(); + // Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry. + if ((config.isLegacyPingPassthrough() || platformType == PlatformType.STANDALONE) && !remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) { + try { + // Searches for a server address and a port from a SRV record of the specified host name + InitialDirContext ctx = new InitialDirContext(); + Attribute attr = ctx.getAttributes("dns:///_minecraft._tcp." + remoteAddress, new String[]{"SRV"}).get("SRV"); + // size > 0 = SRV entry found + if (attr.size() > 0) { + String[] record = ((String) attr.get(0)).split(" "); + // Overwrites the existing address and port with that from the SRV record. + config.getRemote().setAddress(remoteAddress = record[3]); + config.getRemote().setPort(remotePort = Integer.parseInt(record[2])); + logger.debug("Found SRV record \"" + remoteAddress + ":" + remotePort + "\""); + } + } catch (NamingException ex) { + ex.printStackTrace(); + } + } - remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort()); + remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort); authType = AuthType.getByName(config.getRemote().getAuthType()); if (config.isAboveBedrockNetherBuilding()) diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index 5727a902f..a8bc0a9d9 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -92,6 +92,10 @@ public interface GeyserConfiguration { String getAddress(); int getPort(); + + void setAddress(String address); + + void setPort(int port); String getAuthType(); } diff --git a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java index aa9e0503d..ec4e0d7fa 100644 --- a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java +++ b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java @@ -79,15 +79,17 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn public void run() { try { Socket socket = new Socket(); - socket.connect(new InetSocketAddress(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort()), 5000); + String address = connector.getConfig().getRemote().getAddress(); + int port = connector.getConfig().getRemote().getPort(); + socket.connect(new InetSocketAddress(address, port), 5000); ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); DataOutputStream handshake = new DataOutputStream(byteArrayStream); handshake.write(0x0); VarInts.writeUnsignedInt(handshake, MinecraftConstants.PROTOCOL_VERSION); - VarInts.writeUnsignedInt(handshake, socket.getInetAddress().getHostAddress().length()); - handshake.writeBytes(socket.getInetAddress().getHostAddress()); - handshake.writeShort(socket.getPort()); + VarInts.writeUnsignedInt(handshake, address.length()); + handshake.writeBytes(address); + handshake.writeShort(port); VarInts.writeUnsignedInt(handshake, 1); DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream()); From 5c2a2255336339993be1f44030378e685e94aecb Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Sat, 25 Jul 2020 18:21:13 -0400 Subject: [PATCH 04/10] Check for null when looking for SRV (#1025) --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 527e1248d..669458385 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -149,7 +149,7 @@ public class GeyserConnector { InitialDirContext ctx = new InitialDirContext(); Attribute attr = ctx.getAttributes("dns:///_minecraft._tcp." + remoteAddress, new String[]{"SRV"}).get("SRV"); // size > 0 = SRV entry found - if (attr.size() > 0) { + if (attr != null && attr.size() > 0) { String[] record = ((String) attr.get(0)).split(" "); // Overwrites the existing address and port with that from the SRV record. config.getRemote().setAddress(remoteAddress = record[3]); From d03f56e7e89a6ed679cd0963fddbb4731fa397b5 Mon Sep 17 00:00:00 2001 From: bundabrg Date: Sun, 26 Jul 2020 11:06:06 +0800 Subject: [PATCH 05/10] Fix Merchant Inventory Transaction (#1017) --- .../MerchantInventoryTranslator.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/MerchantInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/MerchantInventoryTranslator.java index 37c84e28a..640617399 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/MerchantInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/MerchantInventoryTranslator.java @@ -60,15 +60,23 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator { @Override public int bedrockSlotToJava(InventoryActionData action) { - if (action.getSource().getContainerId() == ContainerId.UI) { - switch (action.getSlot()) { - case 4: - return 0; - case 5: - return 1; - case 50: - return 2; - } + switch (action.getSource().getContainerId()) { + case ContainerId.UI: + switch (action.getSlot()) { + case 4: + return 0; + case 5: + return 1; + case 50: + return 2; + } + break; + case -28: // Trading 1? + return 0; + case -29: // Trading 2? + return 1; + case -30: // Trading Output? + return 2; } return super.bedrockSlotToJava(action); } @@ -109,10 +117,8 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator { @Override public void translateActions(GeyserSession session, Inventory inventory, List actions) { - for (InventoryActionData action : actions) { - if (action.getSource().getType() == InventorySource.Type.NON_IMPLEMENTED_TODO) { - return; - } + if (actions.stream().anyMatch(a -> a.getSource().getContainerId() == -31)) { + return; } super.translateActions(session, inventory, actions); From d316d3a5a8eb0f8495c7f9a8d7f17e646010c9f9 Mon Sep 17 00:00:00 2001 From: Heath123 Date: Mon, 27 Jul 2020 11:30:24 +0100 Subject: [PATCH 06/10] Add .vscode to .gitignore (#1033) * Add .vscode to .gitignore * Use Toptal gitignore generator rtm516 said this would be cleaner, which makes sense * Use gitignore.io links * Uncomment #.project --- .gitignore | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0af6ecd05..88b8bc730 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -# Created by https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all -# Edit at https://www.gitignore.io/?templates=git,java,maven,eclipse,netbeans,jetbrains+all +# Created by https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all,visualstudiocode +# Edit at https://www.gitignore.io/gitignore?templates=git,java,maven,eclipse,netbeans,jetbrains+all,visualstudiocode ### Eclipse ### .metadata @@ -53,22 +53,19 @@ local.properties # Annotation Processing .apt_generated/ +.apt_generated_test/ # Scala IDE specific (Scala & Java development for Eclipse) .cache-main .scala_dependencies .worksheet -### Eclipse Patch ### -# Eclipse Core +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: .project -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - +### Eclipse Patch ### +# Spring Boot Tooling .sts4-cache/ ### Git ### @@ -112,7 +109,7 @@ local.properties hs_err_pid* ### JetBrains+all ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff @@ -142,6 +139,9 @@ hs_err_pid* # When using Gradle or Maven with auto-import, you should exclude module files, # since they will be recreated, and may cause churn. Uncomment if using # auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml # .idea/modules.xml # .idea/*.iml # .idea/modules @@ -207,6 +207,7 @@ release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar .mvn/wrapper/maven-wrapper.jar ### NetBeans ### @@ -219,7 +220,20 @@ dist/ nbdist/ .nb-gradle/ -# End of https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all +### VisualStudioCode ### +# Note: Manually edited to remove settings files +.vscode/* +# !.vscode/settings.json +# !.vscode/tasks.json +# !.vscode/launch.json +# !.vscode/extensions.json +# *.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/git,java,maven,eclipse,netbeans,jetbrains+all,visualstudiocode ### Geyser ### run/ From b9846fe797098ff871c631498b48ca520bf0cd4d Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Mon, 27 Jul 2020 07:17:55 -0800 Subject: [PATCH 07/10] Small inventory fixes (#1029) * Increase minimum delay between closing and opening a new window * Fix potential crash when opening player inventory --- .../bedrock/BedrockInteractTranslator.java | 15 +++++++++------ .../geysermc/connector/utils/InventoryUtils.java | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index 7d03f9832..856b01eec 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -135,12 +135,15 @@ public class BedrockInteractTranslator extends PacketTranslator } break; case OPEN_INVENTORY: - ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); - containerOpenPacket.setId((byte) 0); - containerOpenPacket.setType(ContainerType.INVENTORY); - containerOpenPacket.setUniqueEntityId(-1); - containerOpenPacket.setBlockPosition(entity.getPosition().toInt()); - session.sendUpstreamPacket(containerOpenPacket); + if (!session.getInventory().isOpen()) { + ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); + containerOpenPacket.setId((byte) 0); + containerOpenPacket.setType(ContainerType.INVENTORY); + containerOpenPacket.setUniqueEntityId(-1); + containerOpenPacket.setBlockPosition(entity.getPosition().toInt()); + session.sendUpstreamPacket(containerOpenPacket); + session.getInventory().setOpen(true); + } break; } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java index c30f4518a..6d83da0ad 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java @@ -56,7 +56,7 @@ public class InventoryUtils { translator.prepareInventory(session, inventory); //Ensure at least half a second passes between closing and opening a new window //The client will not open the new window if it is still closing the old one - long delay = 500 - (System.currentTimeMillis() - session.getLastWindowCloseTime()); + long delay = 700 - (System.currentTimeMillis() - session.getLastWindowCloseTime()); //TODO: find better way to handle double chest delay if (translator instanceof DoubleChestInventoryTranslator) { delay = Math.max(delay, 200); @@ -87,6 +87,7 @@ public class InventoryUtils { } } else { Inventory inventory = session.getInventory(); + inventory.setOpen(false); InventoryTranslator translator = InventoryTranslator.INVENTORY_TRANSLATORS.get(inventory.getWindowType()); translator.updateInventory(session, inventory); } From fe75320d6d0440022f86ffdbfa0920eac9808f97 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Mon, 27 Jul 2020 18:18:22 -0400 Subject: [PATCH 08/10] Add WORLD_IMMUTABLE flag to spectator mode (#1034) Prevents the client from trying to interact with blocks --- .../translators/java/world/JavaNotifyClientTranslator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index 3a958bdae..8b23bb6db 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -85,6 +85,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator Date: Tue, 28 Jul 2020 18:47:08 -0400 Subject: [PATCH 09/10] Hide stack trace if an SRV record is unable to be found. (#1046) --- .../main/java/org/geysermc/connector/GeyserConnector.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 669458385..ee687dbbd 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -58,7 +58,6 @@ import org.geysermc.connector.utils.DockerCheck; import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.LocaleUtils; -import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.InitialDirContext; import java.net.InetSocketAddress; @@ -156,8 +155,10 @@ public class GeyserConnector { config.getRemote().setPort(remotePort = Integer.parseInt(record[2])); logger.debug("Found SRV record \"" + remoteAddress + ":" + remotePort + "\""); } - } catch (NamingException ex) { - ex.printStackTrace(); + } catch (Exception ex) { + logger.debug("Exception while trying to find an SRV record for the remote host."); + if (config.isDebugMode()) + ex.printStackTrace(); // Otherwise we can get a stack trace for any domain that doesn't have an SRV record } } From 964432e4f871024cb3a56473e4fb67b23df329ec Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Tue, 28 Jul 2020 21:01:58 -0400 Subject: [PATCH 10/10] Update submodules (#1047) --- connector/src/main/resources/languages | 2 +- connector/src/main/resources/mappings | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/resources/languages b/connector/src/main/resources/languages index 8a62f3730..cd57d6029 160000 --- a/connector/src/main/resources/languages +++ b/connector/src/main/resources/languages @@ -1 +1 @@ -Subproject commit 8a62f3730bd1ae94262315ad1535b5d5523de189 +Subproject commit cd57d6029186293b3ca282243a90252db434714b diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 6bb50495f..47179bc5e 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 6bb50495ffc9c3ef74c90838ed2f6a4f784c0be4 +Subproject commit 47179bc5ee12cab11370b650ab5f3a641aba1390