Only allow a single program instance to be run.
Creates a ServerSocket instance on a port (default: 49250). Credits to marcostudios for the suggestion. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -131,6 +131,7 @@ public class MainMenuExit extends BasicGameState {
|
||||
|
||||
if (yesButton.contains(x, y)) {
|
||||
Options.saveOptions();
|
||||
Opsu.closeSocket();
|
||||
container.exit();
|
||||
} else if (noButton.contains(x, y))
|
||||
game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition(Color.black));
|
||||
@@ -141,6 +142,7 @@ public class MainMenuExit extends BasicGameState {
|
||||
switch (key) {
|
||||
case Input.KEY_1:
|
||||
Options.saveOptions();
|
||||
Opsu.closeSocket();
|
||||
container.exit();
|
||||
break;
|
||||
case Input.KEY_2:
|
||||
|
||||
@@ -225,6 +225,11 @@ public class Options extends BasicGameState {
|
||||
*/
|
||||
private static int screenshotFormatIndex = 0;
|
||||
|
||||
/**
|
||||
* Port binding.
|
||||
*/
|
||||
private static int port = 0;
|
||||
|
||||
/**
|
||||
* Back button (shared by other states).
|
||||
*/
|
||||
@@ -673,6 +678,19 @@ public class Options extends BasicGameState {
|
||||
*/
|
||||
public static boolean isComboBurstEnabled() { return showComboBursts; }
|
||||
|
||||
/**
|
||||
* Returns the port number to bind to.
|
||||
* @return the port
|
||||
*/
|
||||
public static int getPort() {
|
||||
if (port == 0) {
|
||||
// choose a random port
|
||||
port = 49250;
|
||||
optionsChanged = true; // force file creation
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current beatmap directory.
|
||||
* If invalid, this will attempt to search for the directory,
|
||||
@@ -761,6 +779,11 @@ public class Options extends BasicGameState {
|
||||
case "ComboBurst":
|
||||
showComboBursts = Boolean.parseBoolean(value);
|
||||
break;
|
||||
case "Port":
|
||||
i = Integer.parseInt(value);
|
||||
if (i > 0 && i <= 65535)
|
||||
port = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -814,6 +837,8 @@ public class Options extends BasicGameState {
|
||||
writer.newLine();
|
||||
writer.write(String.format("ComboBurst = %b", showComboBursts));
|
||||
writer.newLine();
|
||||
writer.write(String.format("Port = %d", port));
|
||||
writer.newLine();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
Log.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE), e);
|
||||
|
||||
Reference in New Issue
Block a user