MinecraftServerControl / mscs

Powerful command-line control for UNIX and Linux powered Minecraft servers

Home Page:https://minecraftservercontrol.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version Manifest Parsing is Broken

cbabione opened this issue · comments

The latest version manifest file from Mojang breaks the msctl script when running snapshots vs stable. (Stable releases seem to still work) Mojang changed the naming convention for the id with the release of 1.14 Pre-Release 1 today ("1.14 Pre-Release 1" vs. "1.14-pre1"). When I use a custom manifest url using the older naming convention, it works. It does not work using the manifest file from Mojang. To work around this, I have a custom url for the manifest which I control, but this may be affecting others that are not able to do this.

commented

Additionally I see that this ID is used as part of the server.jar filename so it should be sanitized.

Would simply replacing spaces with a dash be enough?

I don't have time to test this right now, but if you swap out this function does it fix the problem?

getCurrentMinecraftVersion() {
  local VERSION TYPE
  # Determine the version type for the current world.
  TYPE=$(getMSCSValue "$1" "mscs-version-type" "$DEFAULT_VERSION_TYPE")
  # Extract the current version information.
  VERSION=$($PERL -0777ne '
    use JSON;
    $json = decode_json ($_);
    $version = $json->{latest}{'$TYPE'};
    $version =~ s/\s/-/g;
    print $version;
  ' $VERSIONS_JSON)
  # Print an error and exit if the version string is empty.
  if [ -z "$VERSION" ]; then
    printf "Error detecting the current Minecraft version.\n"
    exit 1
  fi
  echo "$VERSION"
}

No, it is going to be a more complicated patch. The following functions also need to be changed to expect a dash instead of a space (and there might be more): getMinecraftVersionDownloadSHA1, getMinecraftVersionDownloadURL, getMinecraftVersionReleaseTime.

Maybe something like this when included with the above function:

getMinecraftVersionDownloadSHA1() {
  $PERL -0777ne '
    use JSON;
    use LWP::Simple;
    my $json = decode_json ($_);
    my $version;
    foreach $ver (@{$json->{versions}}) {
      $id = $ver->{id};
      $id =~ s/\s/-/g;
      $version = $ver if ($id eq "'$1'");
    }
    $json = decode_json (get ($version->{url}));
    print $json->{downloads}{'$2'}{sha1};
  ' $VERSIONS_JSON
}
getMinecraftVersionDownloadURL() {
  $PERL -0777ne '
    use JSON;
    use LWP::Simple;
    my $json = decode_json ($_);
    my $version;
    foreach $ver (@{$json->{versions}}) {
      $id = $ver->{id};
      $id =~ s/\s/-/g;
      $version = $ver if ($id eq "'$1'");
    }
    $json = decode_json (get ($version->{url}));
    print $json->{downloads}{'$2'}{url};
  ' $VERSIONS_JSON
}
getMinecraftVersionReleaseTime() {
  $PERL -0777ne '
    use JSON;
    $json = decode_json ($_);
    foreach $ver (@{$json->{versions}}) {
      $id = $ver->{id};
      $id =~ s/\s/-/g;
      print $ver->{releaseTime} if ($id eq "'$1'");
    }
  ' $VERSIONS_JSON
}

I can turn this into PR if that would make it easier to test.

I had a chance to give this a test this evening, and it seems to work. I submitted pull request #210 if you want to give it a test. Let me know how it works for you.

If you feel that there are other characters that should be sanitized from this string, let me know.

Hi there and thanks for looking at this. I am traveling today for work, but will give it a try tomorrow when I am home and let you know my results.

commented

I think it would be best to replace all of these: [\s.*+?^${}()|[\]\\].

I was able to download and test the pull request you mentioned and the msctl script seems to be working with the latest pre-releases now. I am not sure if this is the end-all solution, but it did get it to a working state. Thank you so much for your prompt attention to the issue as well as for supporting such an awesome script. You are appreciated my friend.

Good, I'm glad that it worked for you @cbabione!

@Yax, that is a good idea. I'll go ahead and replace those characters as well. Did you test that regex? It seems like more of those brackets would need to be escaped (maybe not).

commented

@sandain with small update, but it's ok: [\s#%*+?^${}()|[\]\\]. Check it at https://regex101.com/r/Q0JvTP/2
I confirm that PR #210 works too.

@Yax right on. I did not know about that site, that is handy. I would have just written a small Perl script to test, but this is easier by far. I guess I assumed that the left square bracket, [, would need to be escaped in that sequence like the right bracket, and I wasn't sure about the need to escape the parens.

I'll try to update the PR with your suggested change when I get a free moment. Also, thanks for confirming that the PR works for you.

I just merged PR #210 with commit 07498f2. Closing this issue as fixed.