From 59e0aff2891836ae51f1224d7de0b670b09f16ec Mon Sep 17 00:00:00 2001 From: EOT3000 <43685885+EOT3000@users.noreply.github.com> Date: Wed, 11 Sep 2019 16:28:48 -0400 Subject: [PATCH] Hybrid mode start + try fixing chunks (hashcodes, etc.) --- .idea/encodings.xml | 15 ++++ .idea/modules.xml | 12 ++++ connector/connector.iml | 69 +++++++++++++++++++ .../geysermc/connector/GeyserConnector.java | 1 + .../configuration/RemoteConfiguration.java | 4 +- .../network/session/GeyserSession.java | 2 +- .../network/translators/item/BedrockItem.java | 10 +++ .../translators/item/ItemTranslator.java | 2 +- .../network/translators/item/JavaItem.java | 2 +- .../geysermc/connector/utils/Remapper.java | 13 ++++ connector/src/main/resources/config.yml | 4 +- plugin/plugin.iml | 35 ++++++++++ plugin/pom.xml | 21 ++++++ .../org/geysermc/plugin/GeyserPlugin.java | 56 +++++++++++++++ 14 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/modules.xml create mode 100644 connector/connector.iml create mode 100644 plugin/plugin.iml create mode 100644 plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..7d62d0bcf --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..60a7754d3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/connector/connector.iml b/connector/connector.iml new file mode 100644 index 000000000..3525f9e25 --- /dev/null +++ b/connector/connector.iml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index cbd444d81..63bdc8bf7 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -91,6 +91,7 @@ public class GeyserConnector implements Connector { } private GeyserConnector() { + System.out.println(UUID.randomUUID().toString()); //Metric if(!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) { AnsiConsole.systemInstall(); diff --git a/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java index 82f4ec096..7fcf8a2bb 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java @@ -37,6 +37,6 @@ public class RemoteConfiguration { private String motd1; private String motd2; - @JsonProperty("online-mode") - private boolean onlineMode; + @JsonProperty("auth-type") + private String authType; } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 4eff93447..1a21edea7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -119,7 +119,7 @@ public class GeyserSession implements PlayerSession, Player { startGame(); this.remoteServer = remoteServer; - if (!connector.getConfig().getRemote().isOnlineMode()) { + if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); authenticate(authenticationData.getName()); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/BedrockItem.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/BedrockItem.java index dbfa86720..69afbff92 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/BedrockItem.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/BedrockItem.java @@ -37,4 +37,14 @@ public class BedrockItem { private String identifier; private int id; private int data; + + @Override + public int hashCode() { + return id << 4 | data; + } + + @Override + public boolean equals(Object obj) { + return obj == this || (obj instanceof BedrockItem && ((BedrockItem) obj).id == this.id && ((BedrockItem) obj).identifier.equals(this.identifier) && ((BedrockItem) obj).data == this.data); + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index e9cf95046..5d223ba03 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -97,7 +97,7 @@ public class ItemTranslator { } public BedrockItem getBedrockBlock(BlockState state) { - BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrock(new ItemStack(state.getId())); + BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrockB(new ItemStack(state.getId())); if (bedrockItem == null) { // GeyserLogger.DEFAULT.debug("Missing mapping for java block " + state.getId()); return BedrockItem.AIR; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/JavaItem.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/JavaItem.java index 288420b40..06798b274 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/JavaItem.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/JavaItem.java @@ -39,7 +39,7 @@ public class JavaItem { @Override public int hashCode() { - return id & identifier.hashCode(); + return id; } @Override diff --git a/connector/src/main/java/org/geysermc/connector/utils/Remapper.java b/connector/src/main/java/org/geysermc/connector/utils/Remapper.java index 4676dec24..ab733321f 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Remapper.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Remapper.java @@ -107,6 +107,19 @@ public class Remapper { return null; } + public BedrockItem convertToBedrockB(ItemStack block) { + for (Map.Entry javaItem : Toolbox.JAVA_BLOCKS.entrySet()) { + if (javaItem.getValue().getId() != block.getId()) + continue; + + return javaToBedrock.get(javaItem.getValue()); + } + + return null; + } + + + private static String getBedrockIdentifier(String javaIdentifier) { javaIdentifier = javaIdentifier.toLowerCase(); javaIdentifier = javaIdentifier.replace("terracotta", "stained_hardened_clay"); diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index 5b14707c2..ff0214889 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -19,7 +19,9 @@ remote: address: 127.0.0.1 # The port of the remote (Java Edition) server port: 25565 - online-mode: false + + # Authentication type. Can be offline, online, or hybrid (see the wiki). + auth-type: offline ## the Xbox/MCPE username is the key for the Java server auth-info ## this allows automatic configuration/login to the remote Java server diff --git a/plugin/plugin.iml b/plugin/plugin.iml new file mode 100644 index 000000000..742de9a0f --- /dev/null +++ b/plugin/plugin.iml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin/pom.xml b/plugin/pom.xml index bb5febc48..df9bd1f5f 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -9,4 +9,25 @@ 1.0-SNAPSHOT plugin + + + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + + + + + + net.md-5 + bungeecord-api + 1.14-SNAPSHOT + provided + + + com.whirvis + jraknet + 2.11.8 + + \ No newline at end of file diff --git a/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java b/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java new file mode 100644 index 000000000..cd1f5f471 --- /dev/null +++ b/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java @@ -0,0 +1,56 @@ +package org.geysermc.plugin; + +import com.whirvis.jraknet.RakNetPacket; +import com.whirvis.jraknet.peer.RakNetClientPeer; +import com.whirvis.jraknet.server.RakNetServer; +import com.whirvis.jraknet.server.RakNetServerListener; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ConnectedPlayer; +import net.md_5.bungee.api.plugin.Plugin; + +import java.lang.reflect.Field; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class GeyserPlugin extends Plugin { + private List players; + + @SuppressWarnings("unchecked") + @Override + public void onEnable() { + try { + Class clazz = getProxy().getClass(); + + Field field = clazz.getDeclaredField("connections"); + + field.setAccessible(true); + + players = (List) field.get(getProxy()); + } catch (Exception e) { + throw new RuntimeException(e); + } + RakNetServer server = new RakNetServer(new InetSocketAddress("0.0.0.0", 65500), 1000000); + + server.addListener(new RakNetServerListener() { + @Override + public void handleMessage(RakNetServer server, RakNetClientPeer peer, RakNetPacket packet, int channel) { + if(packet.getId() == 0) { + + } + } + }); + } + + private UUID fromXUID(String XUID) { + String one = XUID.substring(0, XUID.length()/2); + String two = XUID.substring(XUID.length()/2, XUID.length()); + + long L1 = Long.parseLong(one); + long L2 = Long.parseLong(two); + + return new UUID(L1, L2); + } +}