From a71bf422327130a47aefcd347daeb95e8c28e773 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 2 Feb 2015 19:50:27 -0800 Subject: [PATCH] Bugfixes and custom port support --- minecraft/config.info | 1 + minecraft/download.cgi | 2 +- minecraft/lang/en | 2 +- minecraft/minecraft-lib.pl | 9 ++++++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/minecraft/config.info b/minecraft/config.info index 8919e5942..b3e7f4ab6 100644 --- a/minecraft/config.info +++ b/minecraft/config.info @@ -4,3 +4,4 @@ java_cmd=Full path to java command,0 unix_user=Run Minecraft server as user,5 init_name=Name of init script,0 history_size=Command history size,0 +port=Minecraft server port number,3,Default (25565) diff --git a/minecraft/download.cgi b/minecraft/download.cgi index 5e420fcc1..e759f206e 100755 --- a/minecraft/download.cgi +++ b/minecraft/download.cgi @@ -11,7 +11,7 @@ our $progress_callback_url; # Validate inputs if ($in{'new'}) { $in{'dir'} =~ /^\/\S+$/ || &error($text{'download_edir'}); - getpwnam($in{'user'}) || &error($text{'download_euser'}); + defined(getpwnam($in{'user'})) || &error($text{'download_euser'}); } &ui_print_unbuffered_header(undef, $text{'download_title'}, ""); diff --git a/minecraft/lang/en b/minecraft/lang/en index 8be9db33a..add3bf155 100644 --- a/minecraft/lang/en +++ b/minecraft/lang/en @@ -1,5 +1,5 @@ index_title=Minecraft Server -index_cerr=An error was detected with your Minecraft server : $1. You may need to adjust the module configuration. +index_cerr=An error was detected with your Minecraft server : $1. You may need to adjust the module configuration. Automatic installation is not possible as the server appears to be already running. index_cerr2=The Minecraft server does not appear to be installed on your system. If it is already running, you will need to adjust the module configuration to use the correct paths. index_rooterr=The Minecraft root directory is set on the module configuration page to $2, but this is the same as the Webmin module directory! index_nojava=Also, the Java command $1 needed to run Minecraft was not found. diff --git a/minecraft/minecraft-lib.pl b/minecraft/minecraft-lib.pl index 92325ba76..bc95b7089 100644 --- a/minecraft/minecraft-lib.pl +++ b/minecraft/minecraft-lib.pl @@ -38,11 +38,14 @@ return undef; sub is_minecraft_port_in_use { &foreign_require("proc"); -my ($pid) = &proc::find_socket_processes("tcp:25565"); +my $port = $config{'port'} || 25565; +my ($pid) = &proc::find_socket_processes("tcp:".$port); return $pid if ($pid); my @procs = &proc::list_processes(); +my $jar = $config{'minecraft_jar'} || + $config{'minecraft_dir'}."/"."minecraft_server.jar"; foreach my $p (@procs) { - if ($p->{'args'} =~ /^java.*minecraft_server.jar/) { + if ($p->{'args'} =~ /^java.*\Q$jar\E/) { return $p->{'pid'}; } } @@ -60,7 +63,7 @@ my $jar = $config{'minecraft_jar'} || my $shortjar = $jar; $shortjar =~ s/^.*\///; foreach my $p (@procs) { - if ($p->{'args'} =~ /^\S*\Q$config{'java_cmd'}\E.*(\Q$jar\E|\Q$shortjar\E)/) { + if ($p->{'args'} =~ /^\S*\Q$config{'java_cmd'}\E.*\Q$jar\E/) { return $p->{'pid'}; } }