diff --git a/src/itdelatrisu/opsu/Opsu.java b/src/itdelatrisu/opsu/Opsu.java index 82e9f553..379bde4c 100644 --- a/src/itdelatrisu/opsu/Opsu.java +++ b/src/itdelatrisu/opsu/Opsu.java @@ -118,18 +118,20 @@ public class Opsu extends StateBasedGame { Options.parseOptions(); // only allow a single instance - try { - SERVER_SOCKET = new ServerSocket(Options.getPort(), 1, InetAddress.getLocalHost()); - } catch (UnknownHostException e) { - // shouldn't happen - } catch (IOException e) { - ErrorHandler.error(String.format( + if (!Options.noSingleInstance()) { + try { + 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 bound to port %d. " + - "You can change the port opsu! uses by editing the \"Port\" field in the configuration file.", + "- An instance of opsu! is already running.\n" + + "- 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); + System.exit(1); + } } File nativeDir; diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index 88fa1e67..82b12894 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -134,6 +134,8 @@ public class Options { /** Port binding. */ private static int port = 49250; + private static boolean noSingleInstance; + /** * Returns whether the XDG flag in the manifest (if any) is set to "true". * @return true if XDG directories are enabled, false otherwise @@ -279,6 +281,15 @@ public class Options { port = i; } }, + NOSINGLEINSTANCE ("NoSingleInstance") { + @Override + public String write() { return noSingleInstance + ""; } + + @Override + public void read(String s) { + noSingleInstance = !"false".equals(s); + } + }, // in-game options SCREEN_RESOLUTION ("Screen Resolution", "ScreenResolution", "Restart (Ctrl+Shift+F5) to apply resolution changes.") { @@ -1492,6 +1503,8 @@ public class Options { */ public static int getPort() { return port; } + public static boolean noSingleInstance() { return noSingleInstance; } + /** * Returns the cursor scale. * @return the scale [0.5, 2]