From 4772e7cdc4b47b936789e704129d422ebe520543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Tue, 31 Dec 2024 12:13:52 +0100 Subject: [PATCH] fix: initialize the tick manager --- Dockerfile | 3 +- run-lwb5.sh | 3 +- scripts/control.pl | 91 +--------------------------------------------- 3 files changed, 4 insertions(+), 93 deletions(-) diff --git a/Dockerfile b/Dockerfile index 67a93d5..f96224d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN < /etc/apt/sources.list.d/php.list apt-get update @@ -17,7 +18,7 @@ RUN < \&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 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 = ; - close(PIDFILE); - - chomp($data); - my ($pid, $time) = split / /, $data; - return (time() - $time < 22 ? $pid : 0); -}