Completed server configuration page

This commit is contained in:
Jamie Cameron
2012-12-26 00:00:23 -08:00
parent 64b5870004
commit 318ee56076
6 changed files with 260 additions and 10 deletions

View File

@@ -9,15 +9,17 @@ my $conf = &get_minecraft_config();
&ui_print_header(undef, $text{'conf_title'}, "");
print $text{'conf_desc'},"<p>\n";
print &ui_form_start("save_conf.cgi", "post");
print &ui_table_start($text{'conf_header'}, undef, 2);
print &ui_table_start($text{'conf_header'}, undef, 4);
#### World-related options
# Seed for new worlds
my $seed = &find_value("level-seed", $conf);
print &ui_table_row($text{'conf_seed'},
&ui_opt_textbox("seed", $seed, 20, $text{'conf_random'}));
&ui_opt_textbox("seed", $seed, 20, $text{'conf_random'}), 3);
# Type for new worlds
my $type = &find_value("level-type", $conf) || "DEFAULT";
@@ -30,17 +32,122 @@ print &ui_table_row($text{'conf_type'},
# Generate structures in new worlds
my $structs = &find_value("generate-structures", $conf) || "true";
print &ui_table_row($text{'conf_structs'},
&ui_yesno_radio("structs", lc($structs) eq "true");
&ui_yesno_radio("structs", lc($structs) eq "true"));
# Allow nether
my $nether = &find_value("allow-nether", $conf) || "true";
print &ui_table_row($text{'conf_nether'},
&ui_yesno_radio("nether", lc($nether) eq "true");
&ui_yesno_radio("nether", lc($nether) eq "true"));
# Allow command block
my $command = &find_value("enable-command-block", $conf) || "false";
print &ui_table_row($text{'conf_command'},
&ui_yesno_radio("command", lc($command) eq "true"));
print &ui_table_hr();
#### Game-related options
# Startup difficulty
my $diff = &find_value("difficulty", $conf);
$diff = 1 if (!defined($diff));
print &ui_table_row($text{'conf_difficulty'},
&ui_select("diff", $diff,
[ [ 0, $text{'cmds_peaceful'} ],
[ 1, $text{'cmds_easy'} ],
[ 2, $text{'cmds_normal'} ],
[ 3, $text{'cmds_hard'} ] ]));
# Default game mode
my $gamemode = &find_value("gamemode", $conf);
$gamemode = 0 if (!defined($gamemode));
print &ui_table_row($text{'conf_gamemode'},
&ui_select("gamemode", $gamemode,
[ [ 0, $text{'cmds_survival'} ],
[ 1, $text{'cmds_creative'} ],
[ 2, $text{'cmds_adventure'} ] ]));
# Allow flight
my $flight = &find_value("allow-flight", $conf) || "false";
print &ui_table_row($text{'conf_flight'},
&ui_yesno_radio("flight", lc($flight) eq "true"));
# Hardcore mode
my $hardcore = &find_value("hardcore", $conf) || "false";
print &ui_table_row($text{'conf_hardcore'},
&ui_yesno_radio("hardcore", lc($hardcore) eq "true"));
# Online mode
my $online = &find_value("online-mode", $conf) || "true";
print &ui_table_row($text{'conf_online'},
&ui_yesno_radio("online", lc($online) eq "true"));
# Allow player vs player
my $pvp = &find_value("pvp", $conf) || "true";
print &ui_table_row($text{'conf_pvp'},
&ui_yesno_radio("pvp", lc($pvp) eq "true"));
print &ui_table_hr();
#### Server options
# Max players
my $players = &find_value("max-players", $conf) || 20;
print &ui_table_row($text{'conf_players'},
&ui_textbox("players", $players, 5));
# Message of the day
my $motd = &find_value("motd", $conf);
print &ui_table_row($text{'conf_motd'},
&ui_opt_textbox("motd", $motd, 60,
$text{'default'}." (A Minecraft Server)<br>",
$text{'conf_motdmsg'}), 3);
# Max build height
my $build = &find_value("max-build-height", $conf) || 256;
print &ui_table_row($text{'conf_build'},
&ui_textbox("build", $build, 5));
print &ui_table_hr();
#### Spawn options
# Spawn various creatures
foreach my $s ("animals", "monsters", "npcs") {
my $spawn = &find_value("spawn-$s", $conf) || "true";
print &ui_table_row($text{'conf_'.$s},
&ui_yesno_radio($s, lc($spawn) eq "true"));
}
# Spawn protection range
my $protect = &find_value("spawn-protection", $conf) || 16;
print &ui_table_row($text{'conf_protect'},
&ui_textbox("protect", $protect, 5));
print &ui_table_hr();
#### Network options
# Listen on IP
my $ip = &find_value("server-ip", $conf);
print &ui_table_row($text{'conf_ip'},
&ui_opt_textbox("ip", $ip, 15, $text{'conf_allip'}));
# Listen on port
my $port = &find_value("server-port", $conf);
print &ui_table_row($text{'conf_port'},
&ui_opt_textbox("port", $port, 5, $text{'default'}." (25565)"));
# Allow query port
my $query = &find_value("enable-query", $conf) || "false";
print &ui_table_row($text{'conf_query'},
&ui_yesno_radio("query", lc($query) eq "true"));
# Allow remote console port
my $rcon = &find_value("enable-rcon", $conf) || "false";
print &ui_table_row($text{'conf_rcon'},
&ui_yesno_radio("rcon", lc($rcon) eq "true"));
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'save'} ] ]);

View File

@@ -61,6 +61,14 @@ else {
print &ui_table_row($text{'worlds_size'},
&nice_size($world->{'size'}));
# Seed, if active
if (&is_minecraft_server_running() && $def eq $world->{'name'}) {
my $out = &execute_minecraft_command("/seed");
if ($out =~ /Seed:\s+(\S+)/) {
print &ui_table_row($text{'worlds_seed'}, $1);
}
}
# All players
if (@{$world->{'players'}}) {
my @grid = map { "<a href='view_conn.cgi?name=".&urlize($_).

View File

@@ -15,6 +15,43 @@ check_ejar=The server JAR file $1 does not exist
check_ejava=The Java executable $1 was not found
conf_title=Server Configuration
conf_desc=These settings will not be activated until the Minecraft server is restarted.
conf_header=Global server configuration settings
conf_seed=Seed for new worlds
conf_random=Choose randomly
conf_type=Type for new worlds
conf_type_default=Default
conf_type_flat=Flat land
conf_type_largebiomes=Large biomes
conf_structs=Generate NPC villages?
conf_nether=Allow access to Nether?
conf_err=Failed to save server configuration
conf_eseen=Missing or invalid-looking seed
conf_flight=Allow flying in survival mode?
conf_difficulty=Default difficulty
conf_gamemode=Default game mode
conf_hardcore=Hardcore (permanent death) mode?
conf_players=Maximum concurrent players
conf_motd=Server message
conf_motdmsg=Custom message
conf_online=Validate Minecraft accounts?
conf_pvp=Allow players to kill each other?
conf_build=Maximum build height
conf_eplayers=Maximum concurrent players must be a positive number
conf_ebuild=Maximum build height must be a positive number
conf_animals=Spawn animals?
conf_monsters=Spawn monsters?
conf_npcs=Spawn NPCs?
conf_protect=Spawn protection radius
conf_command=Allow command block?
conf_ip=Listen on IP address
conf_port=Listen on port
conf_allip=Any address
conf_query=Enable query protocol?
conf_rcon=Enable remote console?
conf_eprotect=Spawn protection radius must be a number
conf_eip=Missing or invalid IP address
conf_eport=Missing on non-numeric port number
users_title=Users and Operators
users_tabwhite=Allowed users
@@ -105,6 +142,7 @@ worlds_title=Manage Worlds
worlds_def=Active?
worlds_name=World name
worlds_size=Data size
worlds_seed=World seed
worlds_players=All players
worlds_change=Change Active World
worlds_change2=Change World And Restart Server
@@ -183,3 +221,7 @@ cmds_gamemodedone=Changed default game mode to $1
cmds_difficultydone=Changed game difficulty
manual_title=Edit Configuration File
log_conf=Changed server configuration
log_stop=Stopped Minecraft server
log_start=Started Minecraft server

View File

@@ -3,6 +3,7 @@
# XXX java param options
# XXX plugins?
# XXX configuration page, with seed field
# XXX IP ban-list
BEGIN { push(@INC, ".."); };
use strict;

92
minecraft/save_conf.cgi Normal file
View File

@@ -0,0 +1,92 @@
#!/usr/local/bin/perl
# Save server properties
use strict;
use warnings;
require './minecraft-lib.pl';
our (%in, %text, %config);
&ReadParse();
&lock_file(&get_minecraft_config_file());
my $conf = &get_minecraft_config();
&error_setup($text{'conf_err'});
# Validate and store inputs, starting with seed
if ($in{'seed_def'}) {
&save_directive("level-seed", "", $conf);
}
else {
$in{'seed'} =~ /^\S+$/ || &error($text{'conf_seed'});
&save_directive("level-seed", $in{'seed'}, $conf);
}
# New world type
&save_directive("level-type", $in{'type'}, $conf);
# Generate structures?
&save_directive("generate-structures", $in{'structs'} ? 'true' : 'false', $conf);
# Allow nether?
&save_directive("allow-nether", $in{'nether'} ? 'true' : 'false', $conf);
# Startup difficulty
&save_directive("difficulty", $in{'diff'}, $conf);
# Default game mode
&save_directive("gamemode", $in{'gamemode'}, $conf);
# Allow flight
&save_directive("allow-flight", $in{'flight'} ? 'true' : 'false', $conf);
# Hardcore mode
&save_directive("hardcore", $in{'hardcore'} ? 'true' : 'false', $conf);
# Online mode
&save_directive("online-mode", $in{'online'} ? 'true' : 'false', $conf);
# Allow player vs player
&save_directive("pvp", $in{'pvp'} ? 'true' : 'false', $conf);
# Max players
$in{'players'} =~ /^[1-9]\d*$/ || &error($text{'conf_eplayers'});
&save_directive("max-players", $in{'players'}, $conf);
# Message of the day
$in{'motd_def'} || $in{'motd'} =~ /\S/ || &error($text{'conf_emotd'});
&save_directive("motd", $in{'motd_def'} ? undef : $in{'motd'}, $conf);
# Max build height
$in{'build'} =~ /^[1-9]\d*$/ || &error($text{'conf_ebuild'});
&save_directive("max-build-height", $in{'build'}, $conf);
# Spawn various creatures
foreach my $s ("animals", "monsters", "npcs") {
&save_directive("spawn-$s", $in{$s} ? "true" : "false", $conf);
}
# Spawn protection range
$in{'protect_def'} || $in{'protect'} =~ /^\d+$/ ||
&error($text{'conf_eprotect'});
&save_directive("spawn-protection", $in{'protect_def'} ? undef : $in{'protect'},
$conf);
# IP address
$in{'ip_def'} || &check_ipaddress($in{'ip'}) ||
&error($text{'conf_eip'});
&save_directive("server-ip", $in{'ip_def'} ? undef : $in{'ip'}, $conf);
# TCP port
$in{'port_def'} || $in{'port'} =~ /^\d+$/ ||
&error($text{'conf_eport'});
&save_directive("server-port", $in{'port_def'} ? undef : $in{'port'}, $conf);
# Query port
&save_directive("enable-query", $in{'query'} ? 'true' : 'false', $conf);
# Remote console port
&save_directive("enable-rcon", $in{'rcon'} ? 'true' : 'false', $conf);
# Write out the file
&flush_file_lines(&get_minecraft_config_file());
&unlock_file(&get_minecraft_config_file());
&webmin_log("conf");
&redirect("");

View File

@@ -74,16 +74,16 @@ if ($c || 1) {
# Change spawn point
print &ui_table_row($text{'conn_spawn'},
"X:".&ui_textbox("spawnx", int($x), 20)." ".
"Y:".&ui_textbox("spawny", int($y), 20)." ".
"Z:".&ui_textbox("spawnz", int($z), 20)." ".
"X:".&ui_textbox("spawnx", int($x), 10)." ".
"Y:".&ui_textbox("spawny", int($y), 10)." ".
"Z:".&ui_textbox("spawnz", int($z), 10)." ".
&ui_submit($text{'conn_spawnb'}, 'spawn'));
# Teleport to location
print &ui_table_row($text{'conn_tp'},
"X:".&ui_textbox("tpx", int($x), 20)." ".
"Y:".&ui_textbox("tpy", int($y), 20)." ".
"Z:".&ui_textbox("tpz", int($z), 20)." ".
"X:".&ui_textbox("tpx", int($x), 10)." ".
"Y:".&ui_textbox("tpy", int($y), 10)." ".
"Z:".&ui_textbox("tpz", int($z), 10)." ".
&ui_submit($text{'conn_tpb'}, 'tp'));
# Teleport to player