From 93615736af3b829e81b43b913ec63a6a3254b48e Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Wed, 12 Aug 2015 22:00:58 -0500 Subject: [PATCH] Minor port-related fixes. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/Opsu.java | 8 ++++++-- src/itdelatrisu/opsu/Options.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/itdelatrisu/opsu/Opsu.java b/src/itdelatrisu/opsu/Opsu.java index 1b36b34a..3b548389 100644 --- a/src/itdelatrisu/opsu/Opsu.java +++ b/src/itdelatrisu/opsu/Opsu.java @@ -38,7 +38,9 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.net.InetAddress; import java.net.ServerSocket; +import java.net.UnknownHostException; import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; @@ -116,12 +118,14 @@ public class Opsu extends StateBasedGame { // only allow a single instance try { - SERVER_SOCKET = new ServerSocket(Options.getPort()); + SERVER_SOCKET = new ServerSocket(Options.getPort(), 1, InetAddress.getLocalHost()); + } catch (UnknownHostException e) { + // shouldn't happen } catch (IOException e) { ErrorHandler.error(String.format( "opsu! could not be launched for one of these reasons:\n" + "- An instance of opsu! is already running.\n" + - "- Another program is running on port %d. " + + "- Another program is bound to port %d. " + "You can change the port opsu! uses by editing the \"Port\" field in the configuration file.", Options.getPort()), null, false); System.exit(1); diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index a4b84447..39d2a775 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -212,7 +212,7 @@ public class Options { @Override public void read(String s) { int i = Integer.parseInt(s); - if (i > 0 && i < 65535) + if (i > 0 && i <= 65535) port = i; } },