Skip to content

Add -server launcher argument #10914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SachaTending
Copy link
Contributor

@SachaTending SachaTending commented Jun 10, 2025

This patch adds -server argument for auto connecting to server on startup
Example usage: java -jar desktop.jar -server localhost
This can be useful in game launchers(example: some server with mods that has launcher to automatically downloads new version of mindustry(if avaible) and mods, and starts desktop.jar with -server arg).

(i used vscodium btw)

If your pull request is not translation or serverlist-related, read the list of requirements below and check each box:

  • I have ensured that my code compiles, if applicable.
  • I have read the contribution guidelines.
  • I have ensured that any new features in this PR function correctly in-game, if applicable.

This patch adds -server argument for auto connecting to server on startup
Example usage: java -jar desktop.jar -server localhost
This can be useful in game launchers
Copy link
Contributor

@1ue999 1ue999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this would be a good feature, i just see a lot of flaws in this implementation...
I doubt Anuke would merge this PR in the state it is in right now.

@@ -44,7 +45,7 @@ public static void main(String[] arg){
width = 900;
height = 700;
gl30Minor = 2;
gl30 = true;
gl30 = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put a trailing whitespace there?

@@ -72,14 +73,24 @@ public static void main(String[] arg){
handleCrash(e);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point in removing that whitespace...?


Events.on(ClientLoadEvent.class, event -> {
// Now (if -server option is present) we inject server to serverlist and automaticly connect to it.
if (Seq.with(args).contains("-server")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use serverAddr (init it to null) instead of that?

Log.info("Autoconnecting to server " + serverAddr);
int port = Vars.port; // TODO: Use port specified in Vars.
if (serverAddr.contains(":")) {
port = Strings.parseInt(serverAddr.substring(serverAddr.indexOf(":")+1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this WILL break with ipv6 addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants