A bit more

This commit is contained in:
Andrew Steinborn
2018-07-27 20:24:57 -04:00
parent a9715be771
commit 1d2110f2aa
4 changed files with 37 additions and 5 deletions

View File

@@ -61,7 +61,7 @@ public class VelocityServer {
httpClient = new NettyHttpClient(this); httpClient = new NettyHttpClient(this);
this.cm.bind(new InetSocketAddress(26671)); this.cm.bind(configuration.getBind());
} }
public Bootstrap initializeGenericBootstrap() { public Bootstrap initializeGenericBootstrap() {

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.proxy.config;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.moandjiezana.toml.Toml; import com.moandjiezana.toml.Toml;
import com.velocitypowered.proxy.util.AddressUtil;
import com.velocitypowered.proxy.util.LegacyChatColorUtils; import com.velocitypowered.proxy.util.LegacyChatColorUtils;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers; import net.kyori.text.serializer.ComponentSerializers;
@@ -10,6 +11,7 @@ import org.apache.logging.log4j.Logger;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@@ -50,6 +52,13 @@ public class VelocityConfiguration {
valid = false; valid = false;
} }
try {
AddressUtil.parseAddress(bind);
} catch (IllegalArgumentException e) {
logger.error("'bind' option does not specify a valid IP address.", e);
valid = false;
}
if (!onlineMode) { if (!onlineMode) {
logger.info("Proxy is running in offline mode!"); logger.info("Proxy is running in offline mode!");
} }
@@ -72,6 +81,15 @@ public class VelocityConfiguration {
valid = false; valid = false;
} }
for (Map.Entry<String, String> entry : servers.entrySet()) {
try {
AddressUtil.parseAddress(entry.getValue());
} catch (IllegalArgumentException e) {
logger.error("Server {} does not have a valid IP address.", entry.getKey(), e);
valid = false;
}
}
for (String s : attemptConnectionOrder) { for (String s : attemptConnectionOrder) {
if (!servers.containsKey(s)) { if (!servers.containsKey(s)) {
logger.error("Fallback server " + s + " doesn't exist!"); logger.error("Fallback server " + s + " doesn't exist!");
@@ -90,8 +108,8 @@ public class VelocityConfiguration {
return valid; return valid;
} }
public String getBind() { public InetSocketAddress getBind() {
return bind; return AddressUtil.parseAddress(bind);
} }
public String getMotd() { public String getMotd() {

View File

@@ -92,8 +92,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (ctx.channel().isActive()) { if (ctx.channel().isActive()) {
cause.printStackTrace();
if (sessionHandler != null) { if (sessionHandler != null) {
sessionHandler.exception(cause); sessionHandler.exception(cause);
} }

View File

@@ -0,0 +1,16 @@
package com.velocitypowered.proxy.util;
import com.google.common.base.Preconditions;
import java.net.InetSocketAddress;
import java.net.URI;
public enum AddressUtil {
;
public static InetSocketAddress parseAddress(String ip) {
Preconditions.checkNotNull(ip, "ip");
URI uri = URI.create("tcp://" + ip);
return new InetSocketAddress(uri.getHost(), uri.getPort());
}
}