MinetestManagementConsole/mmc

213 lines
5.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
use strict;
use warnings;
use UI::Dialog;
use Term::ReadKey;
use Term::ANSIScreen qw(cls);
my $FileEditor = "/bin/nano";
my $InitDName = "/etc/init.d/minetest";
my $MINETESTDIR = "/root/minetest";
my $BackupCommand = "/root/MineBackup/minebackup.pl";
2018-08-16 16:34:02 -07:00
my $PagerCommand = "/usr/bin/less";
my $Logfile = "/root/minetest/minetest.log";
my $PlayersDir = "/var/games/minetest-server/.minetest/worlds/world/players";
###################################################
# No changes below here
###################################################
2018-08-17 01:13:29 -07:00
my $MySettings = "$ENV{'HOME'}/.mmcrc";
2018-08-17 00:20:36 -07:00
my $MMC_ver = "1.2.0";
my $Record = "false"; # Are results saved?
my $TempDir = "/tmp";
my $RobotName = "";
my $BotVersion = "";
my $UserName = "";
my $ServerStatus = "foo";
my $d = new UI::Dialog ( backtitle => "Minetest Management Console v$MMC_ver", height => 20, width => 65, listheight => 5,
order => [ 'ascii', 'cdialog', 'xdialog' ]);
my $windowtitle = "Welcome to the Minetest Management Console!";
my $enjoyedtitle = "We hope you enjoyed MMC!";
my $introtext =
"This is the Minetest Management Console, a utility for Minetest operators
to manage their servers from a text GUI rather than the command line.";
$d->msgbox( title => $windowtitle, text => $introtext );
if (($d->state() eq "ESC") || ($d->state() eq "CANCEL"))
{
exit 0;
}
2018-08-17 01:13:29 -07:00
# Check for config file
if (-f $MySettings)
{
# Read in settings
open (my $FH, "<", $MySettings) or die "Could not read default file '$MySettings' $!";
while (<$FH>)
{
2018-08-17 01:24:04 -07:00
chop();
2018-08-17 01:13:29 -07:00
my ($Command, $Setting) = split(/=/, $_);
if ($Command eq "fileeditor")
{
$FileEditor = $Setting;
}
if ($Command eq "initdname")
{
$InitDName = $Setting;
}
if ($Command eq "minetestdir")
{
$MINETESTDIR = $Setting;
}
if ($Command eq "backupcommand")
{
$BackupCommand = $Setting;
}
if ($Command eq "pagercommand")
{
$PagerCommand = $Setting;
}
if ($Command eq "logfile")
{
2018-08-17 01:24:04 -07:00
$Logfile = $Setting;
2018-08-17 01:13:29 -07:00
}
if ($Command eq "playerdir")
{
$PlayersDir = $Setting;
}
}
close($FH);
}
else
{
# Store defaults
open (my $FH, ">", $MySettings) or die "Could not create default file '$MySettings' $!";
print $FH "fileeditor=/bin/nano\n";
print $FH "initdname=/etc/init.d/minetest\n";
print $FH "minetestdir=/root/minetest\n";
print $FH "backupcommand=/root/MineBackup/minebackup.pl\n";
print $FH "pagercommand=/usr/bin/less\n";
print $FH "logfile=/root/minetest/minetest.log\n";
print $FH "playerdir=/var/games/minetest-server/.minetest/worlds/world/players\n";
close($FH);
}
my $menuselection = "";
2018-08-17 01:13:29 -07:00
sub CheckServerStatus
{
my $running=`ps ax|grep minetestserver|grep -v grep`;
if ($running ne "")
{
$ServerStatus = "Running";
}
else
{
$ServerStatus = "Stopped";
}
}
sub MainMenu
{
my $WantRespawn="ON";
CheckServerStatus();
if (-f "$MINETESTDIR/nostart")
{
$WantRespawn="OFF";
}
$menuselection = $d->menu( title => "Main Menu", text => "Server is $ServerStatus and respawn is $WantRespawn - Select one:",
list => [ '1', 'Start Server',
'2', 'Stop Server',
'3', 'Server Console',
'4', 'Turn Off Respawn',
'5', 'Turn Respawn On',
'6', 'Edit World Cfg',
2018-03-19 02:56:51 -07:00
'7', 'Edit minetest.conf',
'8', 'Run Backup',
2018-08-16 16:34:02 -07:00
'9', 'View Log',
'10', 'View Players',
'q', 'Quit MMC' ] );
}
while (-1)
{
MainMenu();
if (($menuselection eq "CANCEL") || ($menuselection eq "ESC") || ($menuselection eq "") || ($menuselection eq "q") || ($menuselection eq "Q"))
{
$d->msgbox( title => $enjoyedtitle, text => "Thanks for using MMC..." );
exit 0;
}
if ($menuselection eq "1")
{
system("$InitDName start");
}
elsif ($menuselection eq "2")
{
if ($d->yesno( text => "Confirm stopping the server", text => "Are you sure you want to shut down the server?" ))
{
system("$InitDName stop");
sleep(5);
}
}
elsif ($menuselection eq "3")
{
$d->msgbox( text => "To exit the minetest console and return to MMC press CTRL-A CTRL-D" );
system("screen -r");
}
elsif ($menuselection eq "4")
{
# Turn off respawn
system("touch $MINETESTDIR/nostart");
}
elsif ($menuselection eq "5")
{
# Turn respawn back on
if (-f "$MINETESTDIR/nostart")
{
unlink("$MINETESTDIR/nostart");
}
}
elsif ($menuselection eq "6")
{
# Edit world.mt file
system("$FileEditor $MINETESTDIR/worlds/world/world.mt");
}
2018-03-19 02:56:51 -07:00
elsif ($menuselection eq "7")
{
# Edit minetest.conf file
system("$FileEditor $MINETESTDIR/minetest.conf");
}
elsif ($menuselection eq "8")
{
# Run a backup
2018-08-16 16:34:02 -07:00
system("clear");
system("$BackupCommand");
2018-08-16 16:34:02 -07:00
print "Press Enter To Continue";
my $entered = <STDIN>;
}
elsif ($menuselection eq "9")
{
# View log file
system("$PagerCommand $Logfile");
}
elsif ($menuselection eq "10")
{
# View users
system("clear");
system("ls $PlayersDir");
print "Press Enter To Continue";
my $entered = <STDIN>;
}
}
exit 0;