2020-02-08 19:43:25 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-02-08 19:43:25 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.platform.velocity;
|
|
|
|
|
|
|
|
import com.google.inject.Inject;
|
2020-03-17 16:43:09 +00:00
|
|
|
import com.velocitypowered.api.command.CommandManager;
|
2020-02-08 19:43:25 +00:00
|
|
|
import com.velocitypowered.api.event.Subscribe;
|
|
|
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|
|
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
|
|
|
import com.velocitypowered.api.plugin.Plugin;
|
2020-04-27 20:45:14 +00:00
|
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
2020-06-20 17:54:40 +00:00
|
|
|
import lombok.Getter;
|
2020-11-14 23:49:56 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2020-02-08 19:43:25 +00:00
|
|
|
import org.geysermc.connector.GeyserConnector;
|
2020-04-29 20:01:53 +00:00
|
|
|
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
2020-08-19 17:14:17 +00:00
|
|
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
2020-06-27 15:36:48 +00:00
|
|
|
import org.geysermc.connector.dump.BootstrapDumpInfo;
|
2020-05-23 21:50:04 +00:00
|
|
|
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
|
|
|
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
2020-02-08 19:43:25 +00:00
|
|
|
import org.geysermc.connector.utils.FileUtils;
|
2020-07-05 23:35:51 +00:00
|
|
|
import org.geysermc.connector.utils.LanguageUtils;
|
2020-03-17 16:43:09 +00:00
|
|
|
import org.geysermc.platform.velocity.command.GeyserVelocityCommandExecutor;
|
2020-04-19 23:08:14 +00:00
|
|
|
import org.geysermc.platform.velocity.command.GeyserVelocityCommandManager;
|
2020-02-08 19:43:25 +00:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-04-27 20:45:14 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2020-06-20 17:54:40 +00:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2020-02-08 19:43:25 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
2020-04-29 20:01:53 +00:00
|
|
|
public class GeyserVelocityPlugin implements GeyserBootstrap {
|
2020-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
@Inject
|
|
|
|
private Logger logger;
|
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
@Inject
|
2020-05-03 20:30:20 +00:00
|
|
|
private ProxyServer proxyServer;
|
2020-04-27 20:45:14 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
@Inject
|
|
|
|
private CommandManager commandManager;
|
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
private GeyserVelocityCommandManager geyserCommandManager;
|
2020-02-08 19:43:25 +00:00
|
|
|
private GeyserVelocityConfiguration geyserConfig;
|
|
|
|
private GeyserVelocityLogger geyserLogger;
|
2020-05-23 21:50:04 +00:00
|
|
|
private IGeyserPingPassthrough geyserPingPassthrough;
|
2020-02-08 19:43:25 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
private GeyserConnector connector;
|
2020-02-08 19:43:25 +00:00
|
|
|
|
2020-06-20 17:54:40 +00:00
|
|
|
@Getter
|
|
|
|
private final Path configFolder = Paths.get("plugins/" + GeyserConnector.NAME + "-Velocity/");
|
|
|
|
|
2020-02-08 19:43:25 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
try {
|
2020-06-20 17:54:40 +00:00
|
|
|
if (!configFolder.toFile().exists())
|
|
|
|
//noinspection ResultOfMethodCallIgnored
|
|
|
|
configFolder.toFile().mkdirs();
|
|
|
|
File configFile = FileUtils.fileOrCopiedFromResource(configFolder.resolve("config.yml").toFile(), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
2020-03-17 16:43:09 +00:00
|
|
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class);
|
2020-02-08 19:43:25 +00:00
|
|
|
} catch (IOException ex) {
|
2020-07-05 23:35:51 +00:00
|
|
|
logger.warn(LanguageUtils.getLocaleStringLog("geyser.config.failed"), ex);
|
2020-02-08 19:43:25 +00:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:30:20 +00:00
|
|
|
InetSocketAddress javaAddr = proxyServer.getBoundAddress();
|
2020-04-27 20:45:14 +00:00
|
|
|
|
2020-08-16 17:45:52 +00:00
|
|
|
// By default this should be localhost but may need to be changed in some circumstances
|
|
|
|
if (this.geyserConfig.getRemote().getAddress().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
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2020-02-08 19:43:25 +00:00
|
|
|
this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode());
|
2020-05-21 03:43:22 +00:00
|
|
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2020-06-10 22:58:29 +00:00
|
|
|
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && !proxyServer.getPluginManager().getPlugin("floodgate").isPresent()) {
|
2020-07-05 23:35:51 +00:00
|
|
|
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
|
2020-06-10 22:58:29 +00:00
|
|
|
return;
|
2020-08-19 17:14:17 +00:00
|
|
|
} else if (geyserConfig.isAutoconfiguredRemote() && proxyServer.getPluginManager().getPlugin("floodgate").isPresent()) {
|
|
|
|
// Floodgate installed means that the user wants Floodgate authentication
|
|
|
|
geyserLogger.debug("Auto-setting to Floodgate authentication.");
|
|
|
|
geyserConfig.getRemote().setAuthType("floodgate");
|
2020-06-10 22:58:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 17:54:40 +00:00
|
|
|
geyserConfig.loadFloodgate(this, proxyServer, configFolder.toFile());
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.connector = GeyserConnector.start(PlatformType.VELOCITY, this);
|
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
this.geyserCommandManager = new GeyserVelocityCommandManager(connector);
|
2020-11-02 19:28:31 +00:00
|
|
|
this.commandManager.register("geyser", new GeyserVelocityCommandExecutor(connector));
|
2020-05-23 21:50:04 +00:00
|
|
|
if (geyserConfig.isLegacyPingPassthrough()) {
|
|
|
|
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
|
|
|
} else {
|
|
|
|
this.geyserPingPassthrough = new GeyserVelocityPingPassthrough(proxyServer);
|
|
|
|
}
|
2020-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2020-03-17 16:43:09 +00:00
|
|
|
connector.shutdown();
|
2020-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserVelocityConfiguration getGeyserConfig() {
|
|
|
|
return geyserConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserVelocityLogger getGeyserLogger() {
|
|
|
|
return geyserLogger;
|
|
|
|
}
|
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
@Override
|
|
|
|
public org.geysermc.connector.command.CommandManager getGeyserCommandManager() {
|
|
|
|
return this.geyserCommandManager;
|
|
|
|
}
|
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
@Override
|
|
|
|
public IGeyserPingPassthrough getGeyserPingPassthrough() {
|
|
|
|
return geyserPingPassthrough;
|
|
|
|
}
|
|
|
|
|
2020-02-08 19:43:25 +00:00
|
|
|
@Subscribe
|
|
|
|
public void onInit(ProxyInitializeEvent event) {
|
|
|
|
onEnable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
public void onShutdown(ProxyShutdownEvent event) {
|
|
|
|
onDisable();
|
|
|
|
}
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BootstrapDumpInfo getDumpInfo() {
|
|
|
|
return new GeyserVelocityDumpInfo(proxyServer);
|
|
|
|
}
|
2020-02-08 19:43:25 +00:00
|
|
|
}
|