diff --git a/api/src/main/java/org/geysermc/geyser/api/util/PlatformType.java b/api/src/main/java/org/geysermc/geyser/api/util/PlatformType.java index 815381d6b..1abdc0230 100644 --- a/api/src/main/java/org/geysermc/geyser/api/util/PlatformType.java +++ b/api/src/main/java/org/geysermc/geyser/api/util/PlatformType.java @@ -40,4 +40,5 @@ public record PlatformType(String platformName) { public static final PlatformType SPONGE = new PlatformType("Sponge"); public static final PlatformType STANDALONE = new PlatformType("Standalone"); public static final PlatformType VELOCITY = new PlatformType("Velocity"); + public static final PlatformType VIAPROXY = new PlatformType("ViaProxy"); } diff --git a/bootstrap/viaproxy/build.gradle.kts b/bootstrap/viaproxy/build.gradle.kts new file mode 100644 index 000000000..06fcbac54 --- /dev/null +++ b/bootstrap/viaproxy/build.gradle.kts @@ -0,0 +1,27 @@ +dependencies { + api(projects.core) +} + +platformRelocate("net.kyori") +platformRelocate("org.yaml") +platformRelocate("it.unimi.dsi.fastutil") +platformRelocate("com.mojang") +platformRelocate("org.cloudburstmc.netty") + +// These dependencies are already present on the platform +provided(libs.viaproxy) + +application { + mainClass.set("org.geysermc.geyser.platform.viaproxy.GeyserViaProxyMain") +} + +tasks.withType { + archiveBaseName.set("Geyser-ViaProxy") + + dependencies { + exclude(dependency("com.google.*:.*")) + exclude(dependency("io.netty:.*")) + exclude(dependency("org.slf4j:.*")) + exclude(dependency("org.ow2.asm:.*")) + } +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java new file mode 100644 index 000000000..a3a504c4c --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ +package org.geysermc.geyser.platform.viaproxy; + +import net.raphimc.viaproxy.cli.options.Options; +import org.geysermc.geyser.GeyserBootstrap; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.GeyserLogger; +import org.geysermc.geyser.api.network.AuthType; +import org.geysermc.geyser.api.util.PlatformType; +import org.geysermc.geyser.command.GeyserCommandManager; +import org.geysermc.geyser.configuration.GeyserConfiguration; +import org.geysermc.geyser.dump.BootstrapDumpInfo; +import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; +import org.geysermc.geyser.ping.IGeyserPingPassthrough; +import org.geysermc.geyser.text.GeyserLocale; +import org.geysermc.geyser.util.FileUtils; +import org.geysermc.geyser.util.LoopbackUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.UUID; + +public class GeyserViaProxyBootstrap implements GeyserBootstrap { + + private final GeyserViaProxyLogger logger = new GeyserViaProxyLogger(); + private GeyserViaProxyConfiguration config; + + private GeyserImpl geyser; + private GeyserCommandManager commandManager; + private IGeyserPingPassthrough pingPassthrough; + + @Override + public void onEnable() { + LoopbackUtil.checkAndApplyLoopback(this.logger); + + try { + final File configFile = FileUtils.fileOrCopiedFromResource(new File(GeyserViaProxyPlugin.ROOT_FOLDER, "config.yml"), "config.yml", s -> s.replaceAll("generateduuid", UUID.randomUUID().toString()), this); + this.config = FileUtils.loadConfig(configFile, GeyserViaProxyConfiguration.class); + } catch (IOException e) { + this.logger.severe(GeyserLocale.getLocaleStringLog("geyser.config.failed"), e); + System.exit(-1); + } + + config.getRemote().setAuthType(Options.ONLINE_MODE ? AuthType.ONLINE : AuthType.OFFLINE); + GeyserConfiguration.checkGeyserConfiguration(this.config, this.logger); + + this.geyser = GeyserImpl.load(PlatformType.VIAPROXY, this); + GeyserImpl.start(); + + this.commandManager = new GeyserCommandManager(this.geyser); + this.commandManager.init(); + + this.pingPassthrough = GeyserLegacyPingPassthrough.init(this.geyser); + } + + @Override + public void onDisable() { + this.geyser.shutdown(); + } + + @Override + public GeyserConfiguration getGeyserConfig() { + return this.config; + } + + @Override + public GeyserLogger getGeyserLogger() { + return this.logger; + } + + @Override + public GeyserCommandManager getGeyserCommandManager() { + return this.commandManager; + } + + @Override + public IGeyserPingPassthrough getGeyserPingPassthrough() { + return this.pingPassthrough; + } + + @Override + public Path getConfigFolder() { + return GeyserViaProxyPlugin.ROOT_FOLDER.toPath(); + } + + @Override + public BootstrapDumpInfo getDumpInfo() { + return new GeyserViaProxyDumpInfo(); + } + + @NotNull + @Override + public String getServerBindAddress() { + return Options.BIND_ADDRESS; + } + + @Override + public int getServerPort() { + return Options.BIND_PORT; + } + + @Override + public boolean testFloodgatePluginPresent() { + return false; + } + +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyConfiguration.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyConfiguration.java new file mode 100644 index 000000000..f5757a385 --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyConfiguration.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ +package org.geysermc.geyser.platform.viaproxy; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.geysermc.geyser.configuration.GeyserJacksonConfiguration; + +import java.io.File; +import java.nio.file.Path; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class GeyserViaProxyConfiguration extends GeyserJacksonConfiguration { + + @Override + public Path getFloodgateKeyPath() { + return new File(GeyserViaProxyPlugin.ROOT_FOLDER, this.getFloodgateKeyFile()).toPath(); + } + +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java new file mode 100644 index 000000000..c44006344 --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ +package org.geysermc.geyser.platform.viaproxy; + +import net.raphimc.viaproxy.ViaProxy; +import org.geysermc.geyser.dump.BootstrapDumpInfo; + +public class GeyserViaProxyDumpInfo extends BootstrapDumpInfo { + + private final String viaProxyVersion = ViaProxy.VERSION; + +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyLogger.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyLogger.java new file mode 100644 index 000000000..f8ddac14f --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyLogger.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ +package org.geysermc.geyser.platform.viaproxy; + +import net.raphimc.viaproxy.cli.ConsoleFormatter; +import org.geysermc.geyser.GeyserLogger; +import org.geysermc.geyser.command.GeyserCommandSource; + +public class GeyserViaProxyLogger implements GeyserLogger, GeyserCommandSource { + + @Override + public void severe(String message) { + GeyserViaProxyPlugin.LOGGER.fatal(ConsoleFormatter.convert(message)); + } + + @Override + public void severe(String message, Throwable error) { + GeyserViaProxyPlugin.LOGGER.fatal(ConsoleFormatter.convert(message), error); + } + + @Override + public void error(String message) { + GeyserViaProxyPlugin.LOGGER.error(ConsoleFormatter.convert(message)); + } + + @Override + public void error(String message, Throwable error) { + GeyserViaProxyPlugin.LOGGER.error(ConsoleFormatter.convert(message), error); + } + + @Override + public void warning(String message) { + GeyserViaProxyPlugin.LOGGER.warn(ConsoleFormatter.convert(message)); + } + + @Override + public void info(String message) { + GeyserViaProxyPlugin.LOGGER.info(ConsoleFormatter.convert(message)); + } + + @Override + public void debug(String message) { + GeyserViaProxyPlugin.LOGGER.debug(ConsoleFormatter.convert(message)); + } + + @Override + public void setDebug(boolean debug) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isDebug() { + return false; + } + +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyMain.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyMain.java new file mode 100644 index 000000000..675c92534 --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyMain.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.platform.viaproxy; + +import net.raphimc.viaproxy.plugins.PluginManager; +import org.geysermc.geyser.GeyserMain; + +public class GeyserViaProxyMain extends GeyserMain { + + public static void main(String[] args) { + new GeyserViaProxyMain().displayMessage(); + } + + public String getPluginType() { + return "ViaProxy"; + } + + public String getPluginFolder() { + return PluginManager.PLUGINS_DIR.getName(); + } + +} diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java new file mode 100644 index 000000000..15b756df4 --- /dev/null +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.platform.viaproxy; + +import net.lenni0451.lambdaevents.EventHandler; +import net.raphimc.viaproxy.plugins.PluginManager; +import net.raphimc.viaproxy.plugins.ViaProxyPlugin; +import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent; +import net.raphimc.viaproxy.plugins.events.ProxyStartEvent; +import net.raphimc.viaproxy.plugins.events.ProxyStopEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.text.GeyserLocale; + +import java.io.File; + +public class GeyserViaProxyPlugin extends ViaProxyPlugin { + + public static final Logger LOGGER = LogManager.getLogger("Geyser"); + public static final File ROOT_FOLDER = new File(PluginManager.PLUGINS_DIR, "Geyser"); + + private GeyserViaProxyBootstrap bootstrap; + + @Override + public void onEnable() { + ROOT_FOLDER.mkdirs(); + + this.bootstrap = new GeyserViaProxyBootstrap(); + GeyserLocale.init(this.bootstrap); + this.bootstrap.onEnable(); + GeyserImpl.getInstance().shutdown(); + + PluginManager.EVENT_MANAGER.register(this); + } + + @EventHandler + public void onConsoleCommand(final ConsoleCommandEvent event) { + if (event.getCommand().equals("geyser") || event.getCommand().equals("/geyser")) { + event.setCancelled(true); + + this.bootstrap.getGeyserCommandManager().runCommand(this.bootstrap.getGeyserLogger(), "geyser " + String.join(" ", event.getArgs())); + } + } + + // Code below split apart from GeyserImpl.getInstance().reload(); + + @EventHandler + public void onProxyStart(final ProxyStartEvent event) { + GeyserImpl.getInstance().extensionManager().enableExtensions(); + this.bootstrap.onEnable(); + } + + @EventHandler + public void onProxyStop(final ProxyStopEvent event) { + GeyserImpl.getInstance().shutdown(); + } + +} diff --git a/bootstrap/viaproxy/src/main/resources/viaproxy.yml b/bootstrap/viaproxy/src/main/resources/viaproxy.yml new file mode 100644 index 000000000..06a1c3e6b --- /dev/null +++ b/bootstrap/viaproxy/src/main/resources/viaproxy.yml @@ -0,0 +1,5 @@ +name: "${name}-ViaProxy" +version: "${version}" +author: "${author}" +main: "org.geysermc.geyser.platform.viaproxy.GeyserViaProxyPlugin" +min-version: "3.0.21" diff --git a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts index 95d4d5409..c9f984596 100644 --- a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts @@ -16,14 +16,14 @@ indra { mitLicense() javaVersions { - target(16) + target(17) } } tasks { processResources { - // Spigot, BungeeCord, Velocity, Fabric - filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json", "fabric.mod.json")) { + // Spigot, BungeeCord, Velocity, Fabric, ViaProxy + filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json", "fabric.mod.json", "viaproxy.yml")) { expand( "id" to "geyser", "name" to "Geyser", @@ -34,4 +34,4 @@ tasks { ) } } -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index 9eb8a6ed0..6f32ec0cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ allprojects { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(16)) + languageVersion.set(JavaLanguageVersion.of(17)) } } @@ -21,7 +21,8 @@ val platforms = setOf( projects.bungeecord, projects.spigot, projects.standalone, - projects.velocity + projects.velocity, + projects.viaproxy ).map { it.dependencyProject } subprojects { @@ -35,4 +36,4 @@ subprojects { in platforms -> plugins.apply("geyser.platform-conventions") else -> plugins.apply("geyser.base-conventions") } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java index 56309c058..e5a9931a2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java @@ -51,7 +51,7 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator