fix: initialize the tick manager
This commit is contained in:
parent
dcec07be8a
commit
4772e7cdc4
3 changed files with 4 additions and 93 deletions
|
@ -9,6 +9,7 @@ RUN <<EOF
|
|||
curl -sSLo /tmp/debsuryorg-archive-keyring.deb \
|
||||
https://packages.sury.org/debsuryorg-archive-keyring.deb
|
||||
dpkg -i /tmp/debsuryorg-archive-keyring.deb
|
||||
rm -f /tmp/debsuryorg-archive-keyring.deb
|
||||
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" \
|
||||
> /etc/apt/sources.list.d/php.list
|
||||
apt-get update
|
||||
|
@ -17,7 +18,7 @@ RUN <<EOF
|
|||
php8.3-xml socat
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
adduser --system --group \
|
||||
adduser --system --in-group www-data \
|
||||
--shell '/usr/bin/php /opt/lwb5/scripts/ticks.php' \
|
||||
--comment 'LWB5 Ticks' \
|
||||
--home /opt/lwb5 --no-create-home \
|
||||
|
|
|
@ -5,8 +5,7 @@ socat -u \
|
|||
SYSTEM:"(sed -z 's/$/\\\\n/'; /bin/echo)" \
|
||||
&
|
||||
|
||||
#perl /opt/lwb5/scripts/control.pl --start
|
||||
#perl /opt/lwb5/scripts/control.pl TMINIT
|
||||
perl /opt/lwb5/scripts/control.pl --start
|
||||
|
||||
: "${APACHE_CONFDIR:=/etc/apache2}"
|
||||
: "${APACHE_RUN_DIR:=/run/apache2}"
|
||||
|
|
|
@ -110,11 +110,6 @@ chmod 0770, $ctrlPath;
|
|||
NOEND => \&gameCancelEnd,
|
||||
"END" => \&gameChangeEnd,
|
||||
SETDEF => \&setDefaultGame,
|
||||
BOTON => \&startBot,
|
||||
BOTOFF => \&killBot,
|
||||
PCPID => \&proxyDetectorID,
|
||||
PCON => \&startProxyDetector,
|
||||
PCOFF => \&stopProxyDetector
|
||||
);
|
||||
|
||||
# Reader loop
|
||||
|
@ -164,14 +159,8 @@ sub start {
|
|||
print "LegacyWorlds - Initialising game\n";
|
||||
print " -> Controller\n";
|
||||
sleep(1);
|
||||
print " -> Proxy detector\n";
|
||||
&sendMessage("PCON");
|
||||
sleep(1);
|
||||
print " -> Ticks manager\n";
|
||||
&sendMessage("TMINIT");
|
||||
sleep(1);
|
||||
print " -> IRC bot\n";
|
||||
&sendMessage("BOTON");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -179,15 +168,9 @@ sub start {
|
|||
|
||||
sub stop {
|
||||
print "LegacyWolrds - Shutting down\n";
|
||||
print " -> IRC bot\n";
|
||||
&sendMessage("BOTOFF");
|
||||
sleep(1);
|
||||
print " -> Ticks manager\n";
|
||||
&sendMessage("TMSTOP");
|
||||
sleep(1);
|
||||
print " -> Proxy detector\n";
|
||||
&sendMessage("PCOFF");
|
||||
sleep(1);
|
||||
print " -> Controller\n";
|
||||
&sendMessage("DIE");
|
||||
exit(0);
|
||||
|
@ -261,7 +244,7 @@ sub tickManagerStart {
|
|||
return if &tickManagerStatus();
|
||||
return unless -f "$Bin/ticks.php";
|
||||
if ($> == 0) {
|
||||
system("su - lwticks");
|
||||
system("runuser -u lwticks -- bash -c 'cd $Bin; php ticks.php'");
|
||||
} else {
|
||||
system("cd $Bin; php ticks.php");
|
||||
}
|
||||
|
@ -277,28 +260,6 @@ sub tickManagerStop {
|
|||
unlink("$ctrlPath/tickManager.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Start IRC bot
|
||||
#
|
||||
sub startBot {
|
||||
&killBot();
|
||||
if ($> == 0) {
|
||||
system("su - lwbot");
|
||||
} else {
|
||||
system("cd $Bin/../ircbot; (php bot.php &) </dev/null >/dev/null 2>&1");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Stop IRC bot
|
||||
#
|
||||
sub killBot {
|
||||
return unless -f "$ctrlPath/ircbot.pid";
|
||||
my $pid = `cat $ctrlPath/ircbot.pid`;
|
||||
kill 15, $pid;
|
||||
unlink("$ctrlPath/ircbot.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Check tick manager status
|
||||
#
|
||||
|
@ -522,53 +483,3 @@ sub setDefaultGame {
|
|||
print NEWCONF @newConf;
|
||||
close(NEWCONF);
|
||||
}
|
||||
|
||||
#
|
||||
# Proxy detector PID update
|
||||
#
|
||||
sub proxyDetectorID {
|
||||
my $pid = shift;
|
||||
return unless $pid;
|
||||
|
||||
open(PIDFILE, "> $ctrlPath/proxyDetector.pid");
|
||||
print PIDFILE "$pid " . time() . "\n";
|
||||
close(PIDFILE);
|
||||
}
|
||||
|
||||
#
|
||||
# Start proxy detector
|
||||
#
|
||||
sub startProxyDetector {
|
||||
return if &proxyDetectorStatus();
|
||||
return unless -f "$Bin/proxycheck.php";
|
||||
if ($> == 0) {
|
||||
system("su - lwproxy");
|
||||
} else {
|
||||
system("cd $Bin; php proxycheck.php");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Stop proxy detector
|
||||
#
|
||||
sub stopProxyDetector {
|
||||
my $pid;
|
||||
return unless ($pid = &proxyDetectorStatus());
|
||||
kill 15, $pid;
|
||||
unlink("$ctrlPath/proxyDetector.pid");
|
||||
}
|
||||
|
||||
#
|
||||
# Check proxy detector status
|
||||
#
|
||||
sub proxyDetectorStatus {
|
||||
return 0 unless -f "$ctrlPath/proxyDetector.pid";
|
||||
|
||||
open(PIDFILE, "< $ctrlPath/proxyDetector.pid");
|
||||
my $data = <PIDFILE>;
|
||||
close(PIDFILE);
|
||||
|
||||
chomp($data);
|
||||
my ($pid, $time) = split / /, $data;
|
||||
return (time() - $time < 22 ? $pid : 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue