Made webserver binding logging less confusing (#474)

People often think "0.0.0.0" is the IP they should connect to when BlueMap logs `WebServer bound to: /0.0.0.0:8100`
Or they see the IPv6 address being logged, and think BlueMap is only running on IPv6.
This commit is contained in:
TechnicJelle 2023-09-07 08:41:50 +02:00 committed by GitHub
parent c407ba6bd5
commit 7047df73d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,10 +28,12 @@
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.channels.*; import java.nio.channels.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
public abstract class Server extends Thread implements Closeable, Runnable { public abstract class Server extends Thread implements Closeable, Runnable {
@ -52,8 +54,21 @@ public void bind(SocketAddress address) throws IOException {
server.bind(address); server.bind(address);
this.server.add(server); this.server.add(server);
if (checkIfBoundToAllInterfaces(address)) {
Logger.global.logInfo("WebServer bound to all network interfaces on port " + ((InetSocketAddress) address).getPort());
} else {
Logger.global.logInfo("WebServer bound to: " + server.getLocalAddress()); Logger.global.logInfo("WebServer bound to: " + server.getLocalAddress());
} }
}
private boolean checkIfBoundToAllInterfaces(SocketAddress address) {
if (address instanceof InetSocketAddress) {
InetSocketAddress inetAddress = (InetSocketAddress) address;
return Objects.equals(inetAddress.getAddress(), new InetSocketAddress(0).getAddress());
}
return false;
}
@Override @Override
public void run() { public void run() {