13
0
geforkt von Mirrors/Velocity

Merge pull request #141 from VelocityPowered/options

Allow specifying bind port via command line
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-11-23 03:19:03 -05:00 committet von GitHub
Commit 38f460d56c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 64 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ dependencies {
compile "org.apache.logging.log4j:log4j-core:${log4jVersion}"
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
compile 'net.sf.jopt-simple:jopt-simple:5.0.4' // command-line options
compile 'net.minecrell:terminalconsoleappender:1.1.1'
runtime 'net.java.dev.jna:jna:4.5.2' // Needed for JLine
runtime 'com.lmax:disruptor:3.4.2' // Async loggers

Datei anzeigen

@ -0,0 +1,44 @@
package com.velocitypowered.proxy;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.util.Arrays;
public final class ProxyOptions {
private static final Logger logger = LogManager.getLogger(ProxyOptions.class);
private final boolean help;
private final @Nullable Integer port;
ProxyOptions(final String[] args) {
final OptionParser parser = new OptionParser();
final OptionSpec<Void> help = parser.acceptsAll(Arrays.asList("h", "help"), "Print help").forHelp();
final OptionSpec<Integer> port = parser.acceptsAll(Arrays.asList("p", "port"), "Specify the bind port to be used. The configuration bind port will be ignored.").withRequiredArg().ofType(Integer.class);
final OptionSet set = parser.parse(args);
this.help = set.has(help);
this.port = port.value(set);
if (this.help) {
try {
parser.printHelpOn(System.out);
} catch (final IOException e) {
logger.error("Could not print help", e);
}
}
}
boolean isHelp() {
return this.help;
}
public @Nullable Integer getPort() {
return this.port;
}
}

Datei anzeigen

@ -17,7 +17,13 @@ public class Velocity {
public static void main(String... args) {
long startTime = System.currentTimeMillis();
VelocityServer server = new VelocityServer();
final ProxyOptions options = new ProxyOptions(args);
if (options.isHelp()) {
return;
}
VelocityServer server = new VelocityServer(options);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false), "Shutdown thread"));

Datei anzeigen

@ -70,6 +70,7 @@ public class VelocityServer implements ProxyServer {
.registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer())
.create();
private final ProxyOptions options;
private @MonotonicNonNull ConnectionManager cm;
private @MonotonicNonNull VelocityConfiguration configuration;
private @MonotonicNonNull NettyHttpClient httpClient;
@ -88,6 +89,10 @@ public class VelocityServer implements ProxyServer {
private @MonotonicNonNull VelocityScheduler scheduler;
private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar();
public VelocityServer(final ProxyOptions options) {
this.options = options;
}
public KeyPair getServerKeyPair() {
if (serverKeyPair == null) {
throw new AssertionError();
@ -181,7 +186,13 @@ public class VelocityServer implements ProxyServer {
// init console permissions after plugins are loaded
console.setupPermissions();
final Integer port = this.options.getPort();
if (port != null) {
logger.debug("Overriding bind port to {} from command line option", port);
this.cm.bind(new InetSocketAddress(configuration.getBind().getHostString(), port));
} else {
this.cm.bind(configuration.getBind());
}
if (configuration.isQueryEnabled()) {
this.cm.queryBind(configuration.getBind().getHostString(), configuration.getQueryPort());