3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Allow specifying bind port via command line

adds #140
Dieser Commit ist enthalten in:
kashike 2018-11-20 21:48:11 -08:00
Ursprung 74ee716480
Commit 7da847bfac
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-core:${log4jVersion}"
compile "org.apache.logging.log4j:log4j-slf4j-impl:${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' compile 'net.minecrell:terminalconsoleappender:1.1.1'
runtime 'net.java.dev.jna:jna:4.5.2' // Needed for JLine runtime 'net.java.dev.jna:jna:4.5.2' // Needed for JLine
runtime 'com.lmax:disruptor:3.4.2' // Async loggers 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) { public static void main(String... args) {
long startTime = System.currentTimeMillis(); 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(); server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false), "Shutdown thread")); 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()) .registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer())
.create(); .create();
private final ProxyOptions options;
private @MonotonicNonNull ConnectionManager cm; private @MonotonicNonNull ConnectionManager cm;
private @MonotonicNonNull VelocityConfiguration configuration; private @MonotonicNonNull VelocityConfiguration configuration;
private @MonotonicNonNull NettyHttpClient httpClient; private @MonotonicNonNull NettyHttpClient httpClient;
@ -88,6 +89,10 @@ public class VelocityServer implements ProxyServer {
private @MonotonicNonNull VelocityScheduler scheduler; private @MonotonicNonNull VelocityScheduler scheduler;
private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar(); private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar();
public VelocityServer(final ProxyOptions options) {
this.options = options;
}
public KeyPair getServerKeyPair() { public KeyPair getServerKeyPair() {
if (serverKeyPair == null) { if (serverKeyPair == null) {
throw new AssertionError(); throw new AssertionError();
@ -181,7 +186,13 @@ public class VelocityServer implements ProxyServer {
// init console permissions after plugins are loaded // init console permissions after plugins are loaded
console.setupPermissions(); console.setupPermissions();
this.cm.bind(configuration.getBind()); 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()) { if (configuration.isQueryEnabled()) {
this.cm.queryBind(configuration.getBind().getHostString(), configuration.getQueryPort()); this.cm.queryBind(configuration.getBind().getHostString(), configuration.getQueryPort());