Skip to content

Commit

Permalink
Made webserver binding logging less confusing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TechnicJelle authored Sep 6, 2023
1 parent c407ba6 commit 4a8f5c6
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

public abstract class Server extends Thread implements Closeable, Runnable {

Expand All @@ -52,7 +54,20 @@ public void bind(SocketAddress address) throws IOException {
server.bind(address);
this.server.add(server);

Logger.global.logInfo("WebServer bound to: " + server.getLocalAddress());
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());
}
}

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
Expand Down

0 comments on commit 4a8f5c6

Please sign in to comment.