2019-12-01 22:52:07 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2019-12-01 22:52:07 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.platform.bungeecord;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
import net.md_5.bungee.api.config.ListenerInfo;
|
2019-12-01 22:52:07 +00:00
|
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
2022-08-01 15:01:24 +00:00
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
2022-02-27 22:38:55 +00:00
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2020-11-14 23:49:56 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.GeyserBootstrap;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2022-03-20 02:55:29 +00:00
|
|
|
import org.geysermc.geyser.api.network.AuthType;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.command.GeyserCommandManager;
|
2021-11-20 21:34:30 +00:00
|
|
|
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.platform.bungeecord.command.GeyserBungeeCommandExecutor;
|
|
|
|
import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandManager;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.text.GeyserLocale;
|
|
|
|
import org.geysermc.geyser.util.FileUtils;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-04-27 20:45:14 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2021-07-31 16:52:49 +00:00
|
|
|
import java.net.SocketAddress;
|
2020-06-20 17:54:40 +00:00
|
|
|
import java.nio.file.Path;
|
2021-08-24 19:11:38 +00:00
|
|
|
import java.nio.file.Paths;
|
2019-12-01 22:52:07 +00:00
|
|
|
import java.util.UUID;
|
2019-12-02 14:45:51 +00:00
|
|
|
import java.util.logging.Level;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
private GeyserBungeeCommandManager geyserCommandManager;
|
2019-12-01 22:52:07 +00:00
|
|
|
private GeyserBungeeConfiguration geyserConfig;
|
2021-07-31 16:52:49 +00:00
|
|
|
private GeyserBungeeInjector geyserInjector;
|
2019-12-01 22:52:07 +00:00
|
|
|
private GeyserBungeeLogger geyserLogger;
|
2020-05-23 21:50:04 +00:00
|
|
|
private IGeyserPingPassthrough geyserBungeePingPassthrough;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
private GeyserImpl geyser;
|
2020-03-17 16:43:09 +00:00
|
|
|
|
2019-12-01 22:52:07 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2021-12-03 16:01:06 +00:00
|
|
|
GeyserLocale.init(this);
|
|
|
|
|
2022-08-01 15:01:24 +00:00
|
|
|
// Copied from ViaVersion.
|
|
|
|
// https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43
|
|
|
|
try {
|
|
|
|
ProtocolConstants.class.getField("MINECRAFT_1_19_1");
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
getLogger().warning(" / \\");
|
|
|
|
getLogger().warning(" / \\");
|
|
|
|
getLogger().warning(" / | \\");
|
|
|
|
getLogger().warning(" / | \\ " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy", getProxy().getName()));
|
|
|
|
getLogger().warning(" / \\ " + GeyserLocale.getLocaleStringLog("geyser.may_not_work_as_intended_all_caps"));
|
|
|
|
getLogger().warning(" / o \\");
|
|
|
|
getLogger().warning("/_____________\\");
|
|
|
|
}
|
|
|
|
|
2019-12-01 22:52:07 +00:00
|
|
|
if (!getDataFolder().exists())
|
|
|
|
getDataFolder().mkdir();
|
|
|
|
|
2019-12-02 16:54:07 +00:00
|
|
|
try {
|
2020-06-10 22:58:29 +00:00
|
|
|
if (!getDataFolder().exists())
|
|
|
|
getDataFolder().mkdir();
|
2021-12-03 16:01:06 +00:00
|
|
|
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"),
|
|
|
|
"config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()), this);
|
2020-06-10 22:58:29 +00:00
|
|
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserBungeeConfiguration.class);
|
|
|
|
} catch (IOException ex) {
|
2021-12-03 16:01:06 +00:00
|
|
|
getLogger().log(Level.SEVERE, GeyserLocale.getLocaleStringLog("geyser.config.failed"), ex);
|
2020-06-10 22:58:29 +00:00
|
|
|
ex.printStackTrace();
|
2021-12-03 16:01:06 +00:00
|
|
|
return;
|
2019-12-02 16:54:07 +00:00
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
if (getProxy().getConfig().getListeners().size() == 1) {
|
|
|
|
ListenerInfo listener = getProxy().getConfig().getListeners().toArray(new ListenerInfo[0])[0];
|
|
|
|
|
|
|
|
InetSocketAddress javaAddr = listener.getHost();
|
|
|
|
|
2020-08-16 17:45:52 +00:00
|
|
|
// By default this should be localhost but may need to be changed in some circumstances
|
2022-07-11 00:58:48 +00:00
|
|
|
if (this.geyserConfig.getRemote().address().equalsIgnoreCase("auto")) {
|
2020-08-19 17:14:17 +00:00
|
|
|
this.geyserConfig.setAutoconfiguredRemote(true);
|
|
|
|
// Don't use localhost if not listening on all interfaces
|
|
|
|
if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) {
|
|
|
|
this.geyserConfig.getRemote().setAddress(javaAddr.getHostString());
|
|
|
|
}
|
2020-08-16 17:45:52 +00:00
|
|
|
this.geyserConfig.getRemote().setPort(javaAddr.getPort());
|
2020-04-27 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 20:09:40 +00:00
|
|
|
if (geyserConfig.getBedrock().isCloneRemotePort()) {
|
|
|
|
geyserConfig.getBedrock().setPort(javaAddr.getPort());
|
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode());
|
2020-05-21 03:43:22 +00:00
|
|
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2021-06-06 23:01:16 +00:00
|
|
|
// Remove this in like a year
|
|
|
|
if (getProxy().getPluginManager().getPlugin("floodgate-bungee") != null) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.outdated", "https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/"));
|
2021-06-06 23:01:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-11 00:58:48 +00:00
|
|
|
if (geyserConfig.getRemote().authType() == AuthType.FLOODGATE && getProxy().getPluginManager().getPlugin("floodgate") == null) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
|
2020-06-10 22:58:29 +00:00
|
|
|
return;
|
2020-09-28 01:08:31 +00:00
|
|
|
} else if (geyserConfig.isAutoconfiguredRemote() && getProxy().getPluginManager().getPlugin("floodgate") != null) {
|
2020-08-19 17:14:17 +00:00
|
|
|
// Floodgate installed means that the user wants Floodgate authentication
|
|
|
|
geyserLogger.debug("Auto-setting to Floodgate authentication.");
|
2022-04-24 16:42:17 +00:00
|
|
|
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
|
2020-06-10 22:58:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 15:47:52 +00:00
|
|
|
geyserConfig.loadFloodgate(this);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyser = GeyserImpl.start(PlatformType.BUNGEECORD, this);
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2021-11-09 16:44:28 +00:00
|
|
|
this.geyserInjector = new GeyserBungeeInjector(this);
|
2021-07-31 16:52:49 +00:00
|
|
|
this.geyserInjector.initializeLocalChannel(this);
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyserCommandManager = new GeyserBungeeCommandManager(geyser);
|
2022-01-16 21:09:53 +00:00
|
|
|
this.geyserCommandManager.init();
|
2020-04-19 23:08:14 +00:00
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
if (geyserConfig.isLegacyPingPassthrough()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
2020-05-23 21:50:04 +00:00
|
|
|
} else {
|
|
|
|
this.geyserBungeePingPassthrough = new GeyserBungeePingPassthrough(getProxy());
|
|
|
|
}
|
|
|
|
|
2022-07-11 00:58:48 +00:00
|
|
|
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor("geyser", geyser, geyserCommandManager.getCommands()));
|
|
|
|
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor("geyserext", geyser, geyserCommandManager.commands()));
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2021-11-20 21:34:30 +00:00
|
|
|
if (geyser != null) {
|
|
|
|
geyser.shutdown();
|
2021-07-31 16:52:49 +00:00
|
|
|
}
|
|
|
|
if (geyserInjector != null) {
|
|
|
|
geyserInjector.shutdown();
|
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserBungeeConfiguration getGeyserConfig() {
|
|
|
|
return geyserConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserBungeeLogger getGeyserLogger() {
|
|
|
|
return geyserLogger;
|
|
|
|
}
|
2020-04-19 23:08:14 +00:00
|
|
|
|
|
|
|
@Override
|
2022-01-16 21:09:53 +00:00
|
|
|
public GeyserCommandManager getGeyserCommandManager() {
|
2020-04-19 23:08:14 +00:00
|
|
|
return this.geyserCommandManager;
|
|
|
|
}
|
2020-05-23 21:50:04 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGeyserPingPassthrough getGeyserPingPassthrough() {
|
|
|
|
return geyserBungeePingPassthrough;
|
|
|
|
}
|
2020-06-20 17:54:40 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Path getConfigFolder() {
|
|
|
|
return getDataFolder().toPath();
|
|
|
|
}
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BootstrapDumpInfo getDumpInfo() {
|
|
|
|
return new GeyserBungeeDumpInfo(getProxy());
|
|
|
|
}
|
2021-07-31 16:52:49 +00:00
|
|
|
|
2021-08-24 19:11:38 +00:00
|
|
|
@Override
|
|
|
|
public Path getLogsPath() {
|
2021-08-25 10:31:12 +00:00
|
|
|
return Paths.get(getProxy().getName().equals("BungeeCord") ? "proxy.log.0" : "logs/latest.log");
|
2021-08-24 19:11:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:52:49 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public SocketAddress getSocketAddress() {
|
|
|
|
return this.geyserInjector.getServerSocketAddress();
|
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|